1ac7ddfbfSEd Maste //===-- ExpressionSourceCode.cpp --------------------------------*- C++ -*-===// 2ac7ddfbfSEd Maste // 3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure 4ac7ddfbfSEd Maste // 5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source 6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details. 7ac7ddfbfSEd Maste // 8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===// 9ac7ddfbfSEd Maste 10ac7ddfbfSEd Maste #include "lldb/Expression/ExpressionSourceCode.h" 11ac7ddfbfSEd Maste 12ac7ddfbfSEd Maste #include "lldb/Core/StreamString.h" 13ac7ddfbfSEd Maste 14ac7ddfbfSEd Maste using namespace lldb_private; 15ac7ddfbfSEd Maste 16ac7ddfbfSEd Maste const char * 17ac7ddfbfSEd Maste ExpressionSourceCode::g_expression_prefix = R"( 18ac7ddfbfSEd Maste #undef NULL 19ac7ddfbfSEd Maste #undef Nil 20ac7ddfbfSEd Maste #undef nil 21ac7ddfbfSEd Maste #undef YES 22ac7ddfbfSEd Maste #undef NO 23ac7ddfbfSEd Maste #define NULL (__null) 24ac7ddfbfSEd Maste #define Nil (__null) 25ac7ddfbfSEd Maste #define nil (__null) 26ac7ddfbfSEd Maste #define YES ((BOOL)1) 27ac7ddfbfSEd Maste #define NO ((BOOL)0) 28ac7ddfbfSEd Maste typedef signed char BOOL; 29ac7ddfbfSEd Maste typedef signed __INT8_TYPE__ int8_t; 30ac7ddfbfSEd Maste typedef unsigned __INT8_TYPE__ uint8_t; 31ac7ddfbfSEd Maste typedef signed __INT16_TYPE__ int16_t; 32ac7ddfbfSEd Maste typedef unsigned __INT16_TYPE__ uint16_t; 33ac7ddfbfSEd Maste typedef signed __INT32_TYPE__ int32_t; 34ac7ddfbfSEd Maste typedef unsigned __INT32_TYPE__ uint32_t; 35ac7ddfbfSEd Maste typedef signed __INT64_TYPE__ int64_t; 36ac7ddfbfSEd Maste typedef unsigned __INT64_TYPE__ uint64_t; 37ac7ddfbfSEd Maste typedef signed __INTPTR_TYPE__ intptr_t; 38ac7ddfbfSEd Maste typedef unsigned __INTPTR_TYPE__ uintptr_t; 39ac7ddfbfSEd Maste typedef __SIZE_TYPE__ size_t; 40ac7ddfbfSEd Maste typedef __PTRDIFF_TYPE__ ptrdiff_t; 41ac7ddfbfSEd Maste typedef unsigned short unichar; 42ac7ddfbfSEd Maste )"; 43ac7ddfbfSEd Maste 44ac7ddfbfSEd Maste 45ac7ddfbfSEd Maste bool ExpressionSourceCode::GetText (std::string &text, lldb::LanguageType wrapping_language, bool const_object, bool static_method) const 46ac7ddfbfSEd Maste { 47ac7ddfbfSEd Maste if (m_wrap) 48ac7ddfbfSEd Maste { 49ac7ddfbfSEd Maste switch (wrapping_language) 50ac7ddfbfSEd Maste { 51ac7ddfbfSEd Maste default: 52ac7ddfbfSEd Maste return false; 53ac7ddfbfSEd Maste case lldb::eLanguageTypeC: 54ac7ddfbfSEd Maste case lldb::eLanguageTypeC_plus_plus: 55ac7ddfbfSEd Maste case lldb::eLanguageTypeObjC: 56ac7ddfbfSEd Maste break; 57ac7ddfbfSEd Maste } 58ac7ddfbfSEd Maste 59ac7ddfbfSEd Maste StreamString wrap_stream; 60ac7ddfbfSEd Maste 61ac7ddfbfSEd Maste switch (wrapping_language) 62ac7ddfbfSEd Maste { 63ac7ddfbfSEd Maste default: 64ac7ddfbfSEd Maste break; 65ac7ddfbfSEd Maste case lldb::eLanguageTypeC: 66ac7ddfbfSEd Maste wrap_stream.Printf("%s \n" 67ac7ddfbfSEd Maste "%s \n" 68ac7ddfbfSEd Maste "void \n" 69ac7ddfbfSEd Maste "%s(void *$__lldb_arg) \n" 70ac7ddfbfSEd Maste "{ \n" 71ac7ddfbfSEd Maste " %s; \n" 72ac7ddfbfSEd Maste "} \n", 73ac7ddfbfSEd Maste g_expression_prefix, 74ac7ddfbfSEd Maste m_prefix.c_str(), 75ac7ddfbfSEd Maste m_name.c_str(), 76ac7ddfbfSEd Maste m_body.c_str()); 77ac7ddfbfSEd Maste break; 78ac7ddfbfSEd Maste case lldb::eLanguageTypeC_plus_plus: 79ac7ddfbfSEd Maste wrap_stream.Printf("%s \n" 80ac7ddfbfSEd Maste "%s \n" 81ac7ddfbfSEd Maste "void \n" 82ac7ddfbfSEd Maste "$__lldb_class::%s(void *$__lldb_arg) %s\n" 83ac7ddfbfSEd Maste "{ \n" 84ac7ddfbfSEd Maste " %s; \n" 85ac7ddfbfSEd Maste "} \n", 86ac7ddfbfSEd Maste g_expression_prefix, 87ac7ddfbfSEd Maste m_prefix.c_str(), 88ac7ddfbfSEd Maste m_name.c_str(), 89ac7ddfbfSEd Maste (const_object ? "const" : ""), 90ac7ddfbfSEd Maste m_body.c_str()); 91ac7ddfbfSEd Maste break; 92ac7ddfbfSEd Maste case lldb::eLanguageTypeObjC: 93ac7ddfbfSEd Maste if (static_method) 94ac7ddfbfSEd Maste { 95ac7ddfbfSEd Maste wrap_stream.Printf("%s \n" 96ac7ddfbfSEd Maste "%s \n" 97ac7ddfbfSEd Maste "@interface $__lldb_objc_class ($__lldb_category) \n" 98ac7ddfbfSEd Maste "+(void)%s:(void *)$__lldb_arg; \n" 99ac7ddfbfSEd Maste "@end \n" 100ac7ddfbfSEd Maste "@implementation $__lldb_objc_class ($__lldb_category) \n" 101ac7ddfbfSEd Maste "+(void)%s:(void *)$__lldb_arg \n" 102ac7ddfbfSEd Maste "{ \n" 103ac7ddfbfSEd Maste " %s; \n" 104ac7ddfbfSEd Maste "} \n" 105ac7ddfbfSEd Maste "@end \n", 106ac7ddfbfSEd Maste g_expression_prefix, 107ac7ddfbfSEd Maste m_prefix.c_str(), 108ac7ddfbfSEd Maste m_name.c_str(), 109ac7ddfbfSEd Maste m_name.c_str(), 110ac7ddfbfSEd Maste m_body.c_str()); 111ac7ddfbfSEd Maste } 112ac7ddfbfSEd Maste else 113ac7ddfbfSEd Maste { 114ac7ddfbfSEd Maste wrap_stream.Printf("%s \n" 115ac7ddfbfSEd Maste "%s \n" 116ac7ddfbfSEd Maste "@interface $__lldb_objc_class ($__lldb_category) \n" 117ac7ddfbfSEd Maste "-(void)%s:(void *)$__lldb_arg; \n" 118ac7ddfbfSEd Maste "@end \n" 119ac7ddfbfSEd Maste "@implementation $__lldb_objc_class ($__lldb_category) \n" 120ac7ddfbfSEd Maste "-(void)%s:(void *)$__lldb_arg \n" 121ac7ddfbfSEd Maste "{ \n" 122ac7ddfbfSEd Maste " %s; \n" 123ac7ddfbfSEd Maste "} \n" 124ac7ddfbfSEd Maste "@end \n", 125ac7ddfbfSEd Maste g_expression_prefix, 126ac7ddfbfSEd Maste m_prefix.c_str(), 127ac7ddfbfSEd Maste m_name.c_str(), 128ac7ddfbfSEd Maste m_name.c_str(), 129ac7ddfbfSEd Maste m_body.c_str()); 130ac7ddfbfSEd Maste } 131ac7ddfbfSEd Maste break; 132ac7ddfbfSEd Maste } 133ac7ddfbfSEd Maste 134ac7ddfbfSEd Maste text = wrap_stream.GetString(); 135ac7ddfbfSEd Maste } 136ac7ddfbfSEd Maste else 137ac7ddfbfSEd Maste { 138ac7ddfbfSEd Maste text.append(m_body); 139ac7ddfbfSEd Maste } 140ac7ddfbfSEd Maste 141ac7ddfbfSEd Maste return true; 142ac7ddfbfSEd Maste } 143