Bugfixes to the expression parser.  Fixes include:

 - If you put a semicolon at the end of an expression,
   this no longer causes the expression parser to
   error out.  This was a two-part fix: first,
   ClangExpressionDeclMap::Materialize now handles
   an empty struct (such as when there is no return
   value); second, ASTResultSynthesizer walks backward
   from the end of the ASTs until it reaches something
   that's not a NullStmt.

 - ClangExpressionVariable now properly byte-swaps when
   printing itself.

 - ClangUtilityFunction now cleans up after itself when
   it's done compiling itself.

 - Utility functions can now use external functions just
   like user expressions.

 - If you end your expression with a statement that does
   not return a value, the expression now runs correctly
   anyway.

Also, added the beginnings of an Objective-C object
validator function, which is neither installed nor used
as yet.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@113789 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ASTResultSynthesizer.cpp b/source/Expression/ASTResultSynthesizer.cpp
index b3790f2..8838fdd 100644
--- a/source/Expression/ASTResultSynthesizer.cpp
+++ b/source/Expression/ASTResultSynthesizer.cpp
@@ -113,6 +113,18 @@
     if (!function_decl)
         return false;
     
+    if (log)
+    {
+        std::string s;
+        raw_string_ostream os(s);
+        
+        function_decl->print(os);
+        
+        os.flush();
+        
+        log->Printf("Function AST before transforming:\n%s", s.c_str());
+    }
+    
     Stmt *function_body = function_decl->getBody();
     CompoundStmt *compound_stmt = dyn_cast<CompoundStmt>(function_body);
     
@@ -125,6 +137,15 @@
     Stmt **last_stmt_ptr = compound_stmt->body_end() - 1;
     Stmt *last_stmt = *last_stmt_ptr;
     
+    while (dyn_cast<NullStmt>(last_stmt))
+    {
+        if (last_stmt_ptr != compound_stmt->body_begin())
+        {
+            last_stmt_ptr--;
+            last_stmt = *last_stmt_ptr;
+        }
+    }
+    
     Expr *last_expr = dyn_cast<Expr>(last_stmt);
     
     if (!last_expr)