Added support for indicating to the expression parser
that the result of an expression should be coerced to
a specific type.  Also made breakpoint conditions pass
in the bool type for this type.

The expression parser ignores this indication for now.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@119779 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Breakpoint/BreakpointOptions.cpp b/source/Breakpoint/BreakpointOptions.cpp
index 713c2e9..975c836 100644
--- a/source/Breakpoint/BreakpointOptions.cpp
+++ b/source/Breakpoint/BreakpointOptions.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Core/Value.h"
 #include "lldb/Breakpoint/StoppointCallbackContext.h"
 #include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
 #include "lldb/Target/ThreadSpec.h"
 #include "lldb/Target/ThreadPlanTestCondition.h"
 
@@ -193,8 +194,12 @@
         
         exe_ctx.process->SetDynamicCheckers(dynamic_checkers);
     }
+    
+    // Get the boolean type from the process's scratch AST context
+    ClangASTContext *ast_context = exe_ctx.target->GetScratchClangASTContext();
+    TypeFromUser bool_type(ast_context->GetBuiltInType_bool(), ast_context->getASTContext());
 
-    if (!m_condition_ap->Parse (error_stream, exe_ctx))
+    if (!m_condition_ap->Parse (error_stream, exe_ctx, bool_type))
     {
         // Errors mean we should stop.
         return NULL;
diff --git a/source/Expression/ASTResultSynthesizer.cpp b/source/Expression/ASTResultSynthesizer.cpp
index 7078756..bcabfe3 100644
--- a/source/Expression/ASTResultSynthesizer.cpp
+++ b/source/Expression/ASTResultSynthesizer.cpp
@@ -24,11 +24,13 @@
 using namespace clang;
 using namespace lldb_private;
 
-ASTResultSynthesizer::ASTResultSynthesizer(ASTConsumer *passthrough) :
+ASTResultSynthesizer::ASTResultSynthesizer(ASTConsumer *passthrough,
+                                           TypeFromUser desired_type) :
     m_ast_context (NULL),
     m_passthrough (passthrough),
     m_passthrough_sema (NULL),
-    m_sema (NULL)
+    m_sema (NULL),
+    m_desired_type (desired_type)
 {
     if (!m_passthrough)
         return;
diff --git a/source/Expression/ClangUserExpression.cpp b/source/Expression/ClangUserExpression.cpp
index f351528..3e4827b 100644
--- a/source/Expression/ClangUserExpression.cpp
+++ b/source/Expression/ClangUserExpression.cpp
@@ -44,7 +44,8 @@
     m_jit_addr(LLDB_INVALID_ADDRESS),
     m_cplusplus(false),
     m_objectivec(false),
-    m_needs_object_ptr(false)
+    m_needs_object_ptr(false),
+    m_desired_type(NULL, NULL)
 {
 }
 
@@ -55,7 +56,8 @@
 clang::ASTConsumer *
 ClangUserExpression::ASTTransformer (clang::ASTConsumer *passthrough)
 {
-    return new ASTResultSynthesizer(passthrough);
+    return new ASTResultSynthesizer(passthrough,
+                                    m_desired_type);
 }
 
 void
@@ -115,7 +117,9 @@
 }
 
 bool
-ClangUserExpression::Parse (Stream &error_stream, ExecutionContext &exe_ctx)
+ClangUserExpression::Parse (Stream &error_stream, 
+                            ExecutionContext &exe_ctx,
+                            TypeFromUser desired_type)
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
@@ -194,6 +198,8 @@
     // Parse the expression
     //
     
+    m_desired_type = desired_type;
+    
     m_expr_decl_map.reset(new ClangExpressionDeclMap(&exe_ctx));
     
     ClangExpressionParser parser(target_triple.GetCString(), *this);
@@ -452,7 +458,7 @@
     
     StreamString error_stream;
     
-    if (!user_expression.Parse (error_stream, exe_ctx))
+    if (!user_expression.Parse (error_stream, exe_ctx, TypeFromUser(NULL, NULL)))
     {
         if (error_stream.GetString().empty())
             error.SetErrorString ("expression failed to parse, unknown error");
diff --git a/source/Symbol/ClangASTContext.cpp b/source/Symbol/ClangASTContext.cpp
index 1ab02b9..1330275 100644
--- a/source/Symbol/ClangASTContext.cpp
+++ b/source/Symbol/ClangASTContext.cpp
@@ -671,6 +671,12 @@
 }
 
 clang_type_t
+ClangASTContext::GetBuiltInType_bool()
+{
+    return getASTContext()->BoolTy.getAsOpaquePtr();
+}
+
+clang_type_t
 ClangASTContext::GetBuiltInType_objc_id()
 {
     return getASTContext()->ObjCBuiltinIdTy.getAsOpaquePtr();