Added support for calling blocks from expressions,
but gated by an #ifdef until we roll LLVM/Clang to
bring in the necessary parser support.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@152149 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangExpressionDeclMap.cpp b/source/Expression/ClangExpressionDeclMap.cpp
index 6b82c7d..c9f08eb 100644
--- a/source/Expression/ClangExpressionDeclMap.cpp
+++ b/source/Expression/ClangExpressionDeclMap.cpp
@@ -2731,6 +2731,44 @@
     }
 }
 
+static clang_type_t
+MaybePromoteToBlockPointerType
+(
+    ASTContext *ast_context,
+    clang_type_t candidate_type
+)
+{
+    if (!candidate_type)
+        return candidate_type;
+    
+    QualType candidate_qual_type = QualType::getFromOpaquePtr(candidate_type);
+    
+    const PointerType *candidate_pointer_type = dyn_cast<PointerType>(candidate_qual_type);
+    
+    if (!candidate_pointer_type)
+        return candidate_type;
+    
+    QualType pointee_qual_type = candidate_pointer_type->getPointeeType();
+    
+    const RecordType *pointee_record_type = dyn_cast<RecordType>(pointee_qual_type);
+    
+    if (!pointee_record_type)
+        return candidate_type;
+    
+    RecordDecl *pointee_record_decl = pointee_record_type->getDecl();
+    
+    if (!pointee_record_decl->isRecord())
+        return candidate_type;
+    
+    if (!pointee_record_decl->getName().startswith(llvm::StringRef("__block_literal_")))
+        return candidate_type;
+    
+    QualType generic_function_type = ast_context->getFunctionNoProtoType(ast_context->UnknownAnyTy);
+    QualType block_pointer_type = ast_context->getBlockPointerType(generic_function_type);
+    
+    return block_pointer_type.getAsOpaquePtr();
+}
+
 Value *
 ClangExpressionDeclMap::GetVariableValue
 (
@@ -2768,6 +2806,10 @@
             log->PutCString("There is no AST context for the current execution context");
         return NULL;
     }
+
+#ifdef EXPRESSION_PARSER_SUPPORTS_BLOCKS
+    var_opaque_type = MaybePromoteToBlockPointerType (ast, var_opaque_type);
+#endif
     
     DWARFExpression &var_location_expr = var->LocationExpression();