[Lldb-commits] [lldb] r140545 - in /lldb/trunk: include/lldb/Expression/ExpressionSourceCode.h lldb.xcodeproj/project.pbxproj source/Expression/ClangUserExpression.cpp source/Expression/ExpressionSourceCode.cpp
Sean Callanan
scallanan at apple.com
Mon Sep 26 11:45:31 PDT 2011
Author: spyffe
Date: Mon Sep 26 13:45:31 2011
New Revision: 140545
URL: http://llvm.org/viewvc/llvm-project?rev=140545&view=rev
Log:
Factored out handling of the source code for an
expression into a separate class. This class
encapsulates wrapping the function as needed. I
am also moving from using booleans to indicate
what the expression's language should be to using
lldb::LanguageType instead.
Added:
lldb/trunk/include/lldb/Expression/ExpressionSourceCode.h
lldb/trunk/source/Expression/ExpressionSourceCode.cpp
Modified:
lldb/trunk/lldb.xcodeproj/project.pbxproj
lldb/trunk/source/Expression/ClangUserExpression.cpp
Added: lldb/trunk/include/lldb/Expression/ExpressionSourceCode.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ExpressionSourceCode.h?rev=140545&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Expression/ExpressionSourceCode.h (added)
+++ lldb/trunk/include/lldb/Expression/ExpressionSourceCode.h Mon Sep 26 13:45:31 2011
@@ -0,0 +1,75 @@
+//===-- ExpressionSourceCode.h ----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ExpressionSourceCode_h
+#define liblldb_ExpressionSourceCode_h
+
+#include "lldb-enumerations.h"
+
+#include <string>
+
+namespace lldb_private
+{
+
+class ExpressionSourceCode
+{
+public:
+ static ExpressionSourceCode *CreateWrapped (const char *prefix,
+ const char *body)
+ {
+ return new ExpressionSourceCode ("$__lldb_expr",
+ prefix,
+ body,
+ true);
+ }
+
+ static ExpressionSourceCode *CreateUnwrapped (const char *name,
+ const char *body)
+ {
+ return new ExpressionSourceCode (name,
+ "",
+ body,
+ false);
+ }
+
+ bool NeedsWrapping () const
+ {
+ return m_wrap;
+ }
+
+ const char *GetName () const
+ {
+ return m_name.c_str();
+ }
+
+ bool GetText (std::string &text,
+ lldb::LanguageType wrapping_language,
+ bool const_object) const;
+
+private:
+ ExpressionSourceCode (const char *name,
+ const char *prefix,
+ const char *body,
+ bool wrap) :
+ m_name(name),
+ m_prefix(prefix),
+ m_body(body),
+ m_wrap(wrap)
+ {
+ }
+
+ std::string m_name;
+ std::string m_prefix;
+ std::string m_body;
+ bool m_wrap;
+};
+
+} // namespace lldb_private
+
+#endif
Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=140545&r1=140544&r2=140545&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Mon Sep 26 13:45:31 2011
@@ -397,6 +397,7 @@
26F5C39110F3FA26009D5894 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C39010F3FA26009D5894 /* CoreFoundation.framework */; };
26F73062139D8FDB00FD51C7 /* History.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F73061139D8FDB00FD51C7 /* History.cpp */; };
496B015B1406DEB100F830D5 /* IRInterpreter.h in Headers */ = {isa = PBXBuildFile; fileRef = 496B015A1406DEB100F830D5 /* IRInterpreter.h */; };
+ 49A1CAC51430E8DE00306AC9 /* ExpressionSourceCode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49A1CAC31430E8BD00306AC9 /* ExpressionSourceCode.cpp */; };
49A71FE7141FFA5C00D59478 /* IRInterpreter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 496B01581406DE8900F830D5 /* IRInterpreter.cpp */; };
49A71FE8141FFACF00D59478 /* DataEncoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268ED0A4140FF54200DE830F /* DataEncoder.cpp */; };
49C8507C1384A786007DB519 /* ProcessDataAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49C850781384A0CA007DB519 /* ProcessDataAllocator.cpp */; };
@@ -1159,6 +1160,8 @@
497E7B9D1188F6690065CCA1 /* ABI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ABI.cpp; path = source/Target/ABI.cpp; sourceTree = "<group>"; };
499F381E11A5B3F300F5CE02 /* CommandObjectArgs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandObjectArgs.h; path = source/Commands/CommandObjectArgs.h; sourceTree = "<group>"; };
499F381F11A5B3F300F5CE02 /* CommandObjectArgs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectArgs.cpp; path = source/Commands/CommandObjectArgs.cpp; sourceTree = "<group>"; };
+ 49A1CAC11430E21D00306AC9 /* ExpressionSourceCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExpressionSourceCode.h; path = include/lldb/Expression/ExpressionSourceCode.h; sourceTree = "<group>"; };
+ 49A1CAC31430E8BD00306AC9 /* ExpressionSourceCode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExpressionSourceCode.cpp; path = source/Expression/ExpressionSourceCode.cpp; sourceTree = "<group>"; };
49A8A39F11D568A300AD3B68 /* ASTResultSynthesizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ASTResultSynthesizer.cpp; path = source/Expression/ASTResultSynthesizer.cpp; sourceTree = "<group>"; };
49A8A3A311D568BF00AD3B68 /* ASTResultSynthesizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTResultSynthesizer.h; path = include/lldb/Expression/ASTResultSynthesizer.h; sourceTree = "<group>"; };
49BB309511F79450001A4197 /* TaggedASTType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TaggedASTType.h; path = include/lldb/Symbol/TaggedASTType.h; sourceTree = "<group>"; };
@@ -2358,6 +2361,8 @@
26BC7DBE10F1B78200F91463 /* Expression */ = {
isa = PBXGroup;
children = (
+ 49A1CAC11430E21D00306AC9 /* ExpressionSourceCode.h */,
+ 49A1CAC31430E8BD00306AC9 /* ExpressionSourceCode.cpp */,
49D7072611B5AD03001AD875 /* ClangASTSource.h */,
49D7072811B5AD11001AD875 /* ClangASTSource.cpp */,
26BC7DC010F1B79500F91463 /* ClangExpression.h */,
@@ -3481,6 +3486,7 @@
49A71FE7141FFA5C00D59478 /* IRInterpreter.cpp in Sources */,
49A71FE8141FFACF00D59478 /* DataEncoder.cpp in Sources */,
B207C4931429607D00F36E4E /* CommandObjectWatchpoint.cpp in Sources */,
+ 49A1CAC51430E8DE00306AC9 /* ExpressionSourceCode.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=140545&r1=140544&r2=140545&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Mon Sep 26 13:45:31 2011
@@ -28,6 +28,7 @@
#include "lldb/Expression/ClangExpressionParser.h"
#include "lldb/Expression/ClangFunction.h"
#include "lldb/Expression/ClangUserExpression.h"
+#include "lldb/Expression/ExpressionSourceCode.h"
#include "lldb/Host/Host.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/ExecutionContext.h"
@@ -106,6 +107,7 @@
if (method_decl->isInstance())
{
m_cplusplus = true;
+ m_needs_object_ptr = true;
do {
clang::QualType this_type = method_decl->getThisType(decl_context->getParentASTContext());
@@ -122,7 +124,10 @@
else if (clang::ObjCMethodDecl *method_decl = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_context))
{
if (method_decl->isInstanceMethod())
+ {
m_objectivec = true;
+ m_needs_object_ptr = true;
+ }
}
}
@@ -185,61 +190,23 @@
ApplyObjcCastHack(m_expr_text);
//ApplyUnicharHack(m_expr_text);
+ std::auto_ptr <ExpressionSourceCode> source_code (ExpressionSourceCode::CreateWrapped(m_expr_prefix.c_str(), m_expr_text.c_str()));
+
+ lldb::LanguageType lang_type;
+
if (m_cplusplus)
- {
- m_transformed_stream.Printf("%s \n"
- "typedef unsigned short unichar; \n"
- "void \n"
- "$__lldb_class::%s(void *$__lldb_arg) %s\n"
- "{ \n"
- " %s; \n"
- "} \n",
- m_expr_prefix.c_str(),
- FunctionName(),
- (m_const_object ? "const" : ""),
- m_expr_text.c_str());
-
- m_needs_object_ptr = true;
- }
- else if (m_objectivec)
- {
- const char *function_name = FunctionName();
-
- m_transformed_stream.Printf("%s \n"
- "typedef unsigned short unichar; \n"
- "@interface $__lldb_objc_class ($__lldb_category) \n"
- "-(void)%s:(void *)$__lldb_arg; \n"
- "@end \n"
- "@implementation $__lldb_objc_class ($__lldb_category) \n"
- "-(void)%s:(void *)$__lldb_arg \n"
- "{ \n"
- " %s; \n"
- "} \n"
- "@end \n",
- m_expr_prefix.c_str(),
- function_name,
- function_name,
- m_expr_text.c_str());
-
- m_needs_object_ptr = true;
- }
+ lang_type = lldb::eLanguageTypeC_plus_plus;
+ else if(m_objectivec)
+ lang_type = lldb::eLanguageTypeObjC;
else
+ lang_type = lldb::eLanguageTypeC;
+
+ if (!source_code->GetText(m_transformed_text, lang_type, m_const_object))
{
- m_transformed_stream.Printf("%s \n"
- "typedef unsigned short unichar;\n"
- "void \n"
- "%s(void *$__lldb_arg) \n"
- "{ \n"
- " %s; \n"
- "} \n",
- m_expr_prefix.c_str(),
- FunctionName(),
- m_expr_text.c_str());
+ error_stream.PutCString ("error: couldn't construct expression body");
+ return false;
}
- m_transformed_text = m_transformed_stream.GetData();
-
-
if (log)
log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str());
Added: lldb/trunk/source/Expression/ExpressionSourceCode.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ExpressionSourceCode.cpp?rev=140545&view=auto
==============================================================================
--- lldb/trunk/source/Expression/ExpressionSourceCode.cpp (added)
+++ lldb/trunk/source/Expression/ExpressionSourceCode.cpp Mon Sep 26 13:45:31 2011
@@ -0,0 +1,88 @@
+//===-- ExpressionSourceCode.cpp --------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Expression/ExpressionSourceCode.h"
+
+#include "lldb/Core/StreamString.h"
+
+using namespace lldb_private;
+
+bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrapping_language, bool const_object) const
+{
+ if (m_wrap)
+ {
+ switch (wrapping_language)
+ {
+ default:
+ return false;
+ case lldb::eLanguageTypeC:
+ case lldb::eLanguageTypeC_plus_plus:
+ case lldb::eLanguageTypeObjC:
+ break;
+ }
+
+ StreamString wrap_stream;
+
+ switch (wrapping_language)
+ {
+ default:
+ break;
+ case lldb::eLanguageTypeC:
+ wrap_stream.Printf("%s \n"
+ "typedef unsigned short unichar;\n"
+ "void \n"
+ "%s(void *$__lldb_arg) \n"
+ "{ \n"
+ " %s; \n"
+ "} \n",
+ m_prefix.c_str(),
+ m_name.c_str(),
+ m_body.c_str());
+ break;
+ case lldb::eLanguageTypeC_plus_plus:
+ wrap_stream.Printf("%s \n"
+ "typedef unsigned short unichar; \n"
+ "void \n"
+ "$__lldb_class::%s(void *$__lldb_arg) %s\n"
+ "{ \n"
+ " %s; \n"
+ "} \n",
+ m_prefix.c_str(),
+ m_name.c_str(),
+ (const_object ? "const" : ""),
+ m_body.c_str());
+ break;
+ case lldb::eLanguageTypeObjC:
+ wrap_stream.Printf("%s \n"
+ "typedef unsigned short unichar; \n"
+ "@interface $__lldb_objc_class ($__lldb_category) \n"
+ "-(void)%s:(void *)$__lldb_arg; \n"
+ "@end \n"
+ "@implementation $__lldb_objc_class ($__lldb_category) \n"
+ "-(void)%s:(void *)$__lldb_arg \n"
+ "{ \n"
+ " %s; \n"
+ "} \n"
+ "@end \n",
+ m_prefix.c_str(),
+ m_name.c_str(),
+ m_name.c_str(),
+ m_body.c_str());
+ break;
+ }
+
+ text = wrap_stream.GetString();
+ }
+ else
+ {
+ text.append(m_body);
+ }
+
+ return true;
+}
More information about the lldb-commits
mailing list