blob: 1d1c2f1a6ab1b676f5f67a38344872d1751e179a [file] [log] [blame]
Sean Callanande3d27e2011-09-26 18:45:31 +00001//===-- ExpressionSourceCode.cpp --------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Expression/ExpressionSourceCode.h"
11
12#include "lldb/Core/StreamString.h"
13
14using namespace lldb_private;
15
Sean Callanane6ea5fe2011-11-15 02:11:17 +000016bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrapping_language, bool const_object, bool static_method) const
Sean Callanande3d27e2011-09-26 18:45:31 +000017{
18 if (m_wrap)
19 {
20 switch (wrapping_language)
21 {
22 default:
23 return false;
24 case lldb::eLanguageTypeC:
25 case lldb::eLanguageTypeC_plus_plus:
26 case lldb::eLanguageTypeObjC:
27 break;
28 }
29
30 StreamString wrap_stream;
31
32 switch (wrapping_language)
33 {
34 default:
35 break;
36 case lldb::eLanguageTypeC:
37 wrap_stream.Printf("%s \n"
Sean Callanan90f78562012-05-09 21:27:03 +000038 "#undef NULL \n"
39 "#define NULL 0 \n"
Sean Callanande3d27e2011-09-26 18:45:31 +000040 "typedef unsigned short unichar;\n"
41 "void \n"
42 "%s(void *$__lldb_arg) \n"
43 "{ \n"
44 " %s; \n"
45 "} \n",
46 m_prefix.c_str(),
47 m_name.c_str(),
48 m_body.c_str());
49 break;
50 case lldb::eLanguageTypeC_plus_plus:
51 wrap_stream.Printf("%s \n"
Sean Callanan90f78562012-05-09 21:27:03 +000052 "#undef NULL \n"
53 "#define NULL 0 \n"
Sean Callanande3d27e2011-09-26 18:45:31 +000054 "typedef unsigned short unichar; \n"
55 "void \n"
56 "$__lldb_class::%s(void *$__lldb_arg) %s\n"
57 "{ \n"
58 " %s; \n"
59 "} \n",
60 m_prefix.c_str(),
61 m_name.c_str(),
62 (const_object ? "const" : ""),
63 m_body.c_str());
64 break;
65 case lldb::eLanguageTypeObjC:
Sean Callanane6ea5fe2011-11-15 02:11:17 +000066 if (static_method)
67 {
68 wrap_stream.Printf("%s \n"
Sean Callanan90f78562012-05-09 21:27:03 +000069 "#undef NULL \n"
70 "#define NULL 0 \n"
Sean Callanane6ea5fe2011-11-15 02:11:17 +000071 "typedef unsigned short unichar; \n"
72 "@interface $__lldb_objc_class ($__lldb_category) \n"
73 "+(void)%s:(void *)$__lldb_arg; \n"
74 "@end \n"
75 "@implementation $__lldb_objc_class ($__lldb_category) \n"
76 "+(void)%s:(void *)$__lldb_arg \n"
77 "{ \n"
78 " %s; \n"
79 "} \n"
80 "@end \n",
81 m_prefix.c_str(),
82 m_name.c_str(),
83 m_name.c_str(),
84 m_body.c_str());
85 }
86 else
87 {
Sean Callanan90f78562012-05-09 21:27:03 +000088 wrap_stream.Printf("%s \n"
89 "#undef NULL \n"
90 "#define NULL 0 \n"
Sean Callanane6ea5fe2011-11-15 02:11:17 +000091 "typedef unsigned short unichar; \n"
92 "@interface $__lldb_objc_class ($__lldb_category) \n"
93 "-(void)%s:(void *)$__lldb_arg; \n"
94 "@end \n"
95 "@implementation $__lldb_objc_class ($__lldb_category) \n"
96 "-(void)%s:(void *)$__lldb_arg \n"
97 "{ \n"
98 " %s; \n"
99 "} \n"
100 "@end \n",
101 m_prefix.c_str(),
102 m_name.c_str(),
103 m_name.c_str(),
104 m_body.c_str());
105 }
Sean Callanande3d27e2011-09-26 18:45:31 +0000106 break;
107 }
108
109 text = wrap_stream.GetString();
110 }
111 else
112 {
113 text.append(m_body);
114 }
115
116 return true;
117}