Index: lldb/trunk/include/lldb/Symbol/GoASTContext.h =================================================================== --- lldb/trunk/include/lldb/Symbol/GoASTContext.h +++ lldb/trunk/include/lldb/Symbol/GoASTContext.h @@ -1,417 +0,0 @@ -//===-- GoASTContext.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_GoASTContext_h_ -#define liblldb_GoASTContext_h_ - -// C Includes -// C++ Includes -#include -#include -#include -#include -#include - -// Other libraries and framework includes -// Project includes -#include "lldb/Symbol/CompilerType.h" -#include "lldb/Symbol/TypeSystem.h" -#include "lldb/Utility/ConstString.h" - -namespace lldb_private { - -class Declaration; -class GoType; - -class GoASTContext : public TypeSystem { -public: - GoASTContext(); - ~GoASTContext() override; - - //------------------------------------------------------------------ - // PluginInterface functions - //------------------------------------------------------------------ - ConstString GetPluginName() override; - - uint32_t GetPluginVersion() override; - - static ConstString GetPluginNameStatic(); - - static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language, - Module *module, Target *target); - - static void EnumerateSupportedLanguages( - std::set &languages_for_types, - std::set &languages_for_expressions); - - static void Initialize(); - - static void Terminate(); - - DWARFASTParser *GetDWARFParser() override; - - void SetAddressByteSize(int byte_size) { m_pointer_byte_size = byte_size; } - - //------------------------------------------------------------------ - // llvm casting support - //------------------------------------------------------------------ - static bool classof(const TypeSystem *ts) { - return ts->getKind() == TypeSystem::eKindGo; - } - - //---------------------------------------------------------------------- - // CompilerDecl functions - //---------------------------------------------------------------------- - ConstString DeclGetName(void *opaque_decl) override { return ConstString(); } - - //---------------------------------------------------------------------- - // CompilerDeclContext functions - //---------------------------------------------------------------------- - - bool DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) override { - return false; - } - - ConstString DeclContextGetName(void *opaque_decl_ctx) override { - return ConstString(); - } - - ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override { - return ConstString(); - } - - bool - DeclContextIsClassMethod(void *opaque_decl_ctx, - lldb::LanguageType *language_ptr, - bool *is_instance_method_ptr, - ConstString *language_object_name_ptr) override { - return false; - } - - //---------------------------------------------------------------------- - // Creating Types - //---------------------------------------------------------------------- - - CompilerType CreateArrayType(const ConstString &name, - const CompilerType &element_type, - uint64_t length); - - CompilerType CreateBaseType(int go_kind, - const ConstString &type_name_const_str, - uint64_t byte_size); - - // For interface, map, chan. - CompilerType CreateTypedefType(int kind, const ConstString &name, - CompilerType impl); - - CompilerType CreateVoidType(const ConstString &name); - CompilerType CreateFunctionType(const lldb_private::ConstString &name, - CompilerType *params, size_t params_count, - bool is_variadic); - - CompilerType CreateStructType(int kind, const ConstString &name, - uint32_t byte_size); - - void CompleteStructType(const CompilerType &type); - - void AddFieldToStruct(const CompilerType &struct_type, - const ConstString &name, const CompilerType &field_type, - uint32_t byte_offset); - - //---------------------------------------------------------------------- - // Tests - //---------------------------------------------------------------------- - - static bool IsGoString(const CompilerType &type); - static bool IsGoSlice(const CompilerType &type); - static bool IsGoInterface(const CompilerType &type); - static bool IsDirectIface(uint8_t kind); - static bool IsPointerKind(uint8_t kind); - - bool IsArrayType(lldb::opaque_compiler_type_t type, - CompilerType *element_type, uint64_t *size, - bool *is_incomplete) override; - - bool IsAggregateType(lldb::opaque_compiler_type_t type) override; - - bool IsCharType(lldb::opaque_compiler_type_t type) override; - - bool IsCompleteType(lldb::opaque_compiler_type_t type) override; - - bool IsDefined(lldb::opaque_compiler_type_t type) override; - - bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, - bool &is_complex) override; - - bool IsFunctionType(lldb::opaque_compiler_type_t type, - bool *is_variadic_ptr = nullptr) override; - - size_t - GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override; - - CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, - const size_t index) override; - - bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override; - - bool IsBlockPointerType(lldb::opaque_compiler_type_t type, - CompilerType *function_pointer_type_ptr) override; - - bool IsIntegerType(lldb::opaque_compiler_type_t type, - bool &is_signed) override; - - bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type, - CompilerType *target_type, // Can pass nullptr - bool check_cplusplus, bool check_objc) override; - - bool IsPointerType(lldb::opaque_compiler_type_t type, - CompilerType *pointee_type = nullptr) override; - - bool IsScalarType(lldb::opaque_compiler_type_t type) override; - - bool IsVoidType(lldb::opaque_compiler_type_t type) override; - - bool SupportsLanguage(lldb::LanguageType language) override; - - //---------------------------------------------------------------------- - // Type Completion - //---------------------------------------------------------------------- - - bool GetCompleteType(lldb::opaque_compiler_type_t type) override; - - //---------------------------------------------------------------------- - // AST related queries - //---------------------------------------------------------------------- - - uint32_t GetPointerByteSize() override; - - //---------------------------------------------------------------------- - // Accessors - //---------------------------------------------------------------------- - - ConstString GetTypeName(lldb::opaque_compiler_type_t type) override; - - uint32_t GetTypeInfo( - lldb::opaque_compiler_type_t type, - CompilerType *pointee_or_element_compiler_type = nullptr) override; - - lldb::LanguageType - GetMinimumLanguage(lldb::opaque_compiler_type_t type) override; - - lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override; - - //---------------------------------------------------------------------- - // Creating related types - //---------------------------------------------------------------------- - - CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, - uint64_t *stride = nullptr) override; - - CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override; - - // Returns -1 if this isn't a function of if the function doesn't have a - // prototype Returns a value >= 0 if there is a prototype. - int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override; - - CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, - size_t idx) override; - - CompilerType - GetFunctionReturnType(lldb::opaque_compiler_type_t type) override; - - size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override; - - TypeMemberFunctionImpl - GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, - size_t idx) override; - - CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override; - - CompilerType GetPointerType(lldb::opaque_compiler_type_t type) override; - - //---------------------------------------------------------------------- - // Exploring the type - //---------------------------------------------------------------------- - - uint64_t GetBitSize(lldb::opaque_compiler_type_t type, - ExecutionContextScope *exe_scope) override; - - lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type, - uint64_t &count) override; - - lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override; - - uint32_t GetNumChildren(lldb::opaque_compiler_type_t type, - bool omit_empty_base_classes) override; - - lldb::BasicType - GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) override; - - CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, - size_t bit_size) override; - - uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override; - - CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx, - std::string &name, uint64_t *bit_offset_ptr, - uint32_t *bitfield_bit_size_ptr, - bool *is_bitfield_ptr) override; - - uint32_t GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) override { - return 0; - } - - uint32_t - GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) override { - return 0; - } - - CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, - size_t idx, - uint32_t *bit_offset_ptr) override { - return CompilerType(); - } - - CompilerType GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type, - size_t idx, - uint32_t *bit_offset_ptr) override { - return CompilerType(); - } - - CompilerType GetChildCompilerTypeAtIndex( - lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, - bool transparent_pointers, bool omit_empty_base_classes, - bool ignore_array_bounds, std::string &child_name, - uint32_t &child_byte_size, int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class, bool &child_is_deref_of_parent, - ValueObject *valobj, uint64_t &language_flags) override; - - // Lookup a child given a name. This function will match base class names and - // member member names in "clang_type" only, not descendants. - uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, - const char *name, - bool omit_empty_base_classes) override; - - // Lookup a child member given a name. This function will match member names - // only and will descend into "clang_type" children in search for the first - // member in this class, or any base class that matches "name". - // TODO: Return all matches for a given name by returning a - // vector> - // so we catch all names that match a given child name, not just the first. - size_t - GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type, - const char *name, bool omit_empty_base_classes, - std::vector &child_indexes) override; - - //---------------------------------------------------------------------- - // Dumping types - //---------------------------------------------------------------------- - void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, - Stream *s, lldb::Format format, const DataExtractor &data, - lldb::offset_t data_offset, size_t data_byte_size, - uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, - bool show_types, bool show_summary, bool verbose, - uint32_t depth) override; - - bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s, - lldb::Format format, const DataExtractor &data, - lldb::offset_t data_offset, size_t data_byte_size, - uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, - ExecutionContextScope *exe_scope) override; - - void DumpTypeDescription( - lldb::opaque_compiler_type_t type) override; // Dump to stdout - - void DumpTypeDescription(lldb::opaque_compiler_type_t type, - Stream *s) override; - - //---------------------------------------------------------------------- - // TODO: These methods appear unused. Should they be removed? - //---------------------------------------------------------------------- - - bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override; - - void DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, - Stream *s, const DataExtractor &data, - lldb::offset_t data_offset, size_t data_byte_size) override; - - // Converts "s" to a floating point value and place resulting floating point - // bytes in the "dst" buffer. - size_t ConvertStringToFloatValue(lldb::opaque_compiler_type_t type, - const char *s, uint8_t *dst, - size_t dst_size) override; - - //---------------------------------------------------------------------- - // TODO: Determine if these methods should move to ClangASTContext. - //---------------------------------------------------------------------- - - bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, - CompilerType *pointee_type = nullptr) override; - - unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override; - - bool IsCStringType(lldb::opaque_compiler_type_t type, - uint32_t &length) override; - - size_t GetTypeBitAlign(lldb::opaque_compiler_type_t type) override; - - CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override; - - bool IsBeingDefined(lldb::opaque_compiler_type_t type) override; - - bool IsConst(lldb::opaque_compiler_type_t type) override; - - uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, - CompilerType *base_type_ptr) override; - - bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override; - - bool IsTypedefType(lldb::opaque_compiler_type_t type) override; - - // If the current object represents a typedef type, get the underlying type - CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) override; - - bool IsVectorType(lldb::opaque_compiler_type_t type, - CompilerType *element_type, uint64_t *size) override; - - CompilerType - GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override; - - CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override; - - bool IsReferenceType(lldb::opaque_compiler_type_t type, - CompilerType *pointee_type = nullptr, - bool *is_rvalue = nullptr) override; - -private: - typedef std::map> TypeMap; - int m_pointer_byte_size; - int m_int_byte_size; - std::unique_ptr m_types; - std::unique_ptr m_dwarf_ast_parser_ap; - - GoASTContext(const GoASTContext &) = delete; - const GoASTContext &operator=(const GoASTContext &) = delete; -}; - -class GoASTContextForExpr : public GoASTContext { -public: - GoASTContextForExpr(lldb::TargetSP target) : m_target_wp(target) {} - UserExpression * - GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix, - lldb::LanguageType language, - Expression::ResultType desired_type, - const EvaluateExpressionOptions &options) override; - -private: - lldb::TargetWP m_target_wp; -}; -} -#endif // liblldb_GoASTContext_h_ Index: lldb/trunk/include/lldb/Symbol/TypeSystem.h =================================================================== --- lldb/trunk/include/lldb/Symbol/TypeSystem.h +++ lldb/trunk/include/lldb/Symbol/TypeSystem.h @@ -72,7 +72,6 @@ enum LLVMCastKind { eKindClang, eKindSwift, - eKindGo, eKindJava, eKindOCaml, kNumKinds Index: lldb/trunk/include/lldb/lldb-forward.h =================================================================== --- lldb/trunk/include/lldb/lldb-forward.h +++ lldb/trunk/include/lldb/lldb-forward.h @@ -107,7 +107,6 @@ class FileSpec; class FileSpecList; class Flags; -class GoASTContext; class TypeCategoryImpl; class FormatManager; class FormattersMatchCandidate; @@ -354,7 +353,6 @@ typedef std::shared_ptr FunctionSP; typedef std::shared_ptr FunctionCallerSP; typedef std::shared_ptr FuncUnwindersSP; -typedef std::unique_ptr GoASTContextUP; typedef std::shared_ptr InlineFunctionInfoSP; typedef std::shared_ptr InstructionSP; typedef std::shared_ptr Index: lldb/trunk/packages/Python/lldbsuite/test/decorators.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/decorators.py +++ lldb/trunk/packages/Python/lldbsuite/test/decorators.py @@ -600,28 +600,6 @@ return skipUnlessPlatform(lldbplatformutil.getDarwinOSTriples())(func) -def skipUnlessGoInstalled(func): - """Decorate the item to skip tests when no Go compiler is available.""" - - def is_go_missing(self): - compiler = self.getGoCompilerVersion() - if not compiler: - return "skipping because go compiler not found" - match_version = re.search(r"(\d+\.\d+(\.\d+)?)", compiler) - if not match_version: - # Couldn't determine version. - return "skipping because go version could not be parsed out of {}".format( - compiler) - else: - min_strict_version = StrictVersion("1.4.0") - compiler_strict_version = StrictVersion(match_version.group(1)) - if compiler_strict_version < min_strict_version: - return "skipping because available version ({}) does not meet minimum required version ({})".format( - compiler_strict_version, min_strict_version) - return None - return skipTestIfFn(is_go_missing)(func) - - def skipIfHostIncompatibleWithRemote(func): """Decorate the item to skip tests if binaries built on this host are incompatible.""" Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/expressions/TestExpressions.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/expressions/TestExpressions.py +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/expressions/TestExpressions.py @@ -1,123 +0,0 @@ -"""Test the go expression parser/interpreter.""" - -import os -import time -import unittest2 -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestGoUserExpression(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @add_test_categories(['pyapi']) - @skipIfRemote # Not remote test suit ready - @skipIfFreeBSD # Test hanging on FreeBSD - llvm.org/pr37194 - @skipUnlessGoInstalled - def test_with_dsym_and_python_api(self): - """Test GoASTUserExpress.""" - self.buildGo() - self.launchProcess() - self.go_expressions() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line numbers to break inside main(). - self.main_source = "main.go" - self.break_line = line_number( - self.main_source, '// Set breakpoint here.') - - def check_builtin(self, name, size=0, typeclass=lldb.eTypeClassBuiltin): - tl = self.target().FindTypes(name) - self.assertEqual(1, len(tl)) - t = list(tl)[0] - self.assertEqual(name, t.name) - self.assertEqual(typeclass, t.type) - if size > 0: - self.assertEqual(size, t.size) - - def launchProcess(self): - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - bpt = target.BreakpointCreateByLocation( - self.main_source, self.break_line) - self.assertTrue(bpt, VALID_BREAKPOINT) - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - - self.assertTrue(process, PROCESS_IS_VALID) - - # The stop reason of the thread should be breakpoint. - thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) - - # Make sure we stopped at the first breakpoint. - self.assertTrue( - len(thread_list) != 0, - "No thread stopped at our breakpoint.") - self.assertTrue(len(thread_list) == 1, - "More than one thread stopped at our breakpoint.") - - frame = thread_list[0].GetFrameAtIndex(0) - self.assertTrue(frame, "Got a valid frame 0 frame.") - - def go_expressions(self): - frame = self.frame() - v = frame.EvaluateExpression("1") - self.assertEqual(1, v.GetValueAsSigned()) - x = frame.EvaluateExpression("x") - self.assertEqual(22, x.GetValueAsSigned()) - - a = frame.EvaluateExpression("a") - self.assertEqual(3, a.GetNumChildren()) - a0 = a.GetChildAtIndex(0) - self.assertEqual(8, a0.GetValueAsSigned()) - - # Array indexing - a0 = frame.EvaluateExpression("a[0]") - self.assertEqual(8, a0.GetValueAsSigned()) - - # Slice indexing - b1 = frame.EvaluateExpression("b[1]") - self.assertEqual(9, b1.GetValueAsSigned()) - - # Test global in this package - g = frame.EvaluateExpression("myGlobal") - self.assertEqual(17, g.GetValueAsSigned(), str(g)) - - # Global with package name - g = frame.EvaluateExpression("main.myGlobal") - self.assertEqual(17, g.GetValueAsSigned(), str(g)) - - # Global with quoted package name - g = frame.EvaluateExpression('"main".myGlobal') - self.assertEqual(17, g.GetValueAsSigned(), str(g)) - - # Casting with package local type - s = frame.EvaluateExpression("*(*myStruct)(i.data)") - sb = s.GetChildMemberWithName("a") - self.assertEqual(2, sb.GetValueAsSigned()) - - # casting with explicit package - s = frame.EvaluateExpression("*(*main.myStruct)(i.data)") - sb = s.GetChildMemberWithName("a") - self.assertEqual(2, sb.GetValueAsSigned()) - - # Casting quoted package - s = frame.EvaluateExpression('*(*"main".myStruct)(i.data)') - sb = s.GetChildMemberWithName("b") - self.assertEqual(-1, sb.GetValueAsSigned()) - -if __name__ == '__main__': - import atexit - lldb.SBDebugger.Initialize() - atexit.register(lambda: lldb.SBDebugger.Terminate()) - unittest2.main() Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/expressions/main.go =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/expressions/main.go +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/expressions/main.go @@ -1,21 +0,0 @@ -package main - -import "fmt" - -type myStruct struct { - a, b int -} - -var myGlobal = 17 - -func myFunc(i interface{}) { - a := [...]int{8, 9, 10} - b := a[:] - x := 22 - fmt.Println(a, b, x, i, myGlobal) // Set breakpoint here. -} - -func main() { - s := myStruct {2, -1} - myFunc(s) -} \ No newline at end of file Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/formatters/TestGoFormatters.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/formatters/TestGoFormatters.py +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/formatters/TestGoFormatters.py @@ -1,76 +0,0 @@ -"""Test the Go Data Formatter Plugin.""" - -import os -import time -import unittest2 -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestGoLanguage(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @skipIfFreeBSD # llvm.org/pr24895 triggers assertion failure - @skipIfRemote # Not remote test suite ready - @no_debug_info_test - @skipUnlessGoInstalled - def test_go_formatter_plugin(self): - """Test go data formatters.""" - self.buildGo() - self.launchProcess() - self.check_formatters() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line numbers to break inside main(). - self.main_source = "main.go" - self.break_line = line_number(self.main_source, '// stop here') - - def launchProcess(self): - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - self.bpt = target.BreakpointCreateByLocation( - self.main_source, self.break_line) - self.assertTrue(self.bpt, VALID_BREAKPOINT) - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - - self.assertTrue(process, PROCESS_IS_VALID) - - # The stop reason of the thread should be breakpoint. - thread_list = lldbutil.get_threads_stopped_at_breakpoint( - process, self.bpt) - - # Make sure we stopped at the first breakpoint. - self.assertTrue( - len(thread_list) != 0, - "No thread stopped at our breakpoint.") - self.assertTrue(len(thread_list) == 1, - "More than one thread stopped at our breakpoint.") - - frame = thread_list[0].GetFrameAtIndex(0) - self.assertTrue(frame, "Got a valid frame 0 frame.") - - def check_formatters(self): - a = self.frame().FindVariable('a') - self.assertEqual('(string) a = "my string"', str(a)) - b = self.frame().FindVariable('b') - self.assertEqual( - "([]int) b = (len 2, cap 7) {\n [0] = 0\n [1] = 0\n}", - str(b)) - - -if __name__ == '__main__': - import atexit - lldb.SBDebugger.Initialize() - atexit.register(lambda: lldb.SBDebugger.Terminate()) - unittest2.main() Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/formatters/main.go =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/formatters/main.go +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/formatters/main.go @@ -1,9 +0,0 @@ -package main - -import "fmt" - -func main() { - a := "my string" - b := make([]int, 2, 7) - fmt.Println(a, b) // stop here -} \ No newline at end of file Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/goroutines/TestGoroutines.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/goroutines/TestGoroutines.py +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/goroutines/TestGoroutines.py @@ -1,104 +0,0 @@ -"""Test the Go OS Plugin.""" - -from __future__ import print_function - - -import os -import time -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestGoASTContext(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @add_test_categories(['pyapi']) - @skipIfFreeBSD # llvm.org/pr24895 triggers assertion failure - @skipIfRemote # Not remote test suite ready - @no_debug_info_test - @skipUnlessGoInstalled - def test_goroutine_plugin(self): - """Test goroutine as threads support.""" - self.buildGo() - self.launchProcess() - self.check_goroutines() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line numbers to break inside main(). - self.main_source = "main.go" - self.break_line1 = line_number(self.main_source, '// stop1') - self.break_line2 = line_number(self.main_source, '// stop2') - self.break_line3 = line_number(self.main_source, '// stop3') - - def launchProcess(self): - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - self.bpt1 = target.BreakpointCreateByLocation( - self.main_source, self.break_line1) - self.assertTrue(self.bpt1, VALID_BREAKPOINT) - self.bpt2 = target.BreakpointCreateByLocation( - self.main_source, self.break_line2) - self.assertTrue(self.bpt2, VALID_BREAKPOINT) - self.bpt3 = target.BreakpointCreateByLocation( - self.main_source, self.break_line3) - self.assertTrue(self.bpt3, VALID_BREAKPOINT) - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - - self.assertTrue(process, PROCESS_IS_VALID) - - # The stop reason of the thread should be breakpoint. - thread_list = lldbutil.get_threads_stopped_at_breakpoint( - process, self.bpt1) - - # Make sure we stopped at the first breakpoint. - self.assertTrue( - len(thread_list) != 0, - "No thread stopped at our breakpoint.") - self.assertTrue(len(thread_list) == 1, - "More than one thread stopped at our breakpoint.") - - frame = thread_list[0].GetFrameAtIndex(0) - self.assertTrue(frame, "Got a valid frame 0 frame.") - - def check_goroutines(self): - self.assertLess(len(self.process().threads), 20) - self.process().Continue() - - # Make sure we stopped at the 2nd breakpoint - thread_list = lldbutil.get_threads_stopped_at_breakpoint( - self.process(), self.bpt2) - self.assertTrue( - len(thread_list) != 0, - "No thread stopped at our breakpoint.") - self.assertTrue(len(thread_list) == 1, - "More than one thread stopped at our breakpoint.") - - # There's (at least) 21 goroutines. - self.assertGreater(len(self.process().threads), 20) - # self.dbg.HandleCommand("log enable lldb os") - - # Now test that stepping works if the memory thread moves to a - # different backing thread. - for i in list(range(11)): - self.thread().StepOver() - self.assertEqual( - lldb.eStopReasonPlanComplete, - self.thread().GetStopReason(), - self.thread().GetStopDescription(100)) - - # Disable the plugin and make sure the goroutines disappear - self.dbg.HandleCommand( - "settings set plugin.os.goroutines.enable false") - self.thread().StepInstruction(False) - self.assertLess(len(self.process().threads), 20) Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/goroutines/main.go =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/goroutines/main.go +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/goroutines/main.go @@ -1,89 +0,0 @@ -package main - -import ( - "fmt" - "runtime" -) - -type philosopher struct { - i int - forks [2]chan bool - eating chan int - done chan struct{} -} - -func (p philosopher) run() { - for { - select { - case <-p.done: - return - case <-p.forks[0]: - p.eat() - } - } -} - -func (p philosopher) eat() { - select { - case <-p.done: - return - case <-p.forks[1]: - p.eating <- p.i - p.forks[0] <- true - p.forks[1] <- true - runtime.Gosched() - } -} - -func startPhilosophers(n int) (chan struct{}, chan int) { - philosophers := make([]*philosopher, n) - chans := make([]chan bool, n) - for i := range chans { - chans[i] = make(chan bool, 1) - chans[i] <- true - } - eating := make(chan int, n) - done := make(chan struct{}) - for i := range philosophers { - var min, max int - if i == n - 1 { - min = 0 - max = i - } else { - min = i - max = i + 1 - } - philosophers[i] = &philosopher{i: i, forks: [2]chan bool{chans[min], chans[max]}, eating: eating, done: done} - go philosophers[i].run() - } - return done, eating -} - -func wait(c chan int) { - fmt.Println(<- c) - runtime.Gosched() -} - -func main() { - // Restrict go to 1 real thread so we can be sure we're seeing goroutines - // and not threads. - runtime.GOMAXPROCS(1) - // Create a bunch of goroutines - done, eating := startPhilosophers(20) // stop1 - // Now turn up the number of threads so this goroutine is likely to get - // scheduled on a different thread. - runtime.GOMAXPROCS(runtime.NumCPU()) // stop2 - // Now let things run. Hopefully we'll bounce around - wait(eating) - wait(eating) - wait(eating) - wait(eating) - wait(eating) - wait(eating) - wait(eating) - wait(eating) - wait(eating) - wait(eating) - close(done) - fmt.Println("done") // stop3 -} Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/runtime/TestGoLanguageRuntime =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/runtime/TestGoLanguageRuntime +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/runtime/TestGoLanguageRuntime @@ -1,80 +0,0 @@ -"""Test the go dynamic type handling.""" - -import os, time -import unittest2 -import lldb -import lldbutil -from lldbtest import * - -class TestGoLanguageRuntime(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @python_api_test - @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr24895') - @skipIfRemote # Not remote test suite ready - @skipUnlessGoInstalled - def test_with_dsym_and_python_api(self): - """Test GoASTContext dwarf parsing.""" - self.buildGo() - self.launchProcess() - self.go_interface_types() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line numbers to break inside main(). - self.main_source = "main.go" - self.break_line1 = line_number(self.main_source, '// Set breakpoint 1') - self.break_line2 = line_number(self.main_source, '// Set breakpoint 2') - - - def launchProcess(self): - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - bpt1 = target.BreakpointCreateByLocation(self.main_source, self.break_line1) - self.assertTrue(bpt1, VALID_BREAKPOINT) - bpt2 = target.BreakpointCreateByLocation(self.main_source, self.break_line2) - self.assertTrue(bpt2, VALID_BREAKPOINT) - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple (None, None, self.get_process_working_directory()) - - self.assertTrue(process, PROCESS_IS_VALID) - - # The stop reason of the thread should be breakpoint. - thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt1) - - # Make sure we stopped at the first breakpoint. - self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.") - self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.") - - frame = thread_list[0].GetFrameAtIndex(0) - self.assertTrue (frame, "Got a valid frame 0 frame.") - - def go_interface_types(self): - f = self.frame() - v = f.FindVariable("a", lldb.eDynamicCanRunTarget) - self.assertEqual("*int", v.GetType().name) - self.assertEqual(1, v.Dereference().GetValueAsSigned()) - v = f.FindVariable("b", lldb.eDynamicCanRunTarget) - self.assertEqual("*float64", v.GetType().name) - err = lldb.SBError() - self.assertEqual(2.0, v.Dereference().GetData().GetDouble(err, 0)) - v = f.FindVariable("c", lldb.eDynamicCanRunTarget) - self.assertEqual("*main.SomeFooer", v.GetType().name) - self.assertEqual(9, v.Dereference().GetChildAtIndex(0).GetValueAsSigned()) - v = f.FindVariable("d", lldb.eDynamicCanRunTarget) - self.assertEqual("*main.AnotherFooer", v.GetType().name) - self.assertEqual(-1, v.Dereference().GetChildAtIndex(0).GetValueAsSigned()) - self.assertEqual(-2, v.Dereference().GetChildAtIndex(1).GetValueAsSigned()) - self.assertEqual(-3, v.Dereference().GetChildAtIndex(2).GetValueAsSigned()) - -if __name__ == '__main__': - import atexit - lldb.SBDebugger.Initialize() - atexit.register(lambda: lldb.SBDebugger.Terminate()) - unittest2.main() Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/runtime/main.go =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/runtime/main.go +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/runtime/main.go @@ -1,38 +0,0 @@ -package main - -import "fmt" - -type Fooer interface { - Foo() int -} - -type SomeFooer struct { - val int -} - -func (s SomeFooer) Foo() int { - return s.val -} - -type AnotherFooer struct { - a, b, c int -} - -func (s AnotherFooer) Foo() int { - return s.a -} - - -func printEface(a, b, c, d interface{}) { - fmt.Println(a, b, c, d) // Set breakpoint 1 -} - -func printIface(a, b Fooer) { - fmt.Println(a, b) // Set breakpoint 2 -} -func main() { - sf := SomeFooer{9} - af := AnotherFooer{-1, -2, -3} - printEface(1,2.0, sf, af) - printIface(sf, af) -} \ No newline at end of file Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/types/TestGoASTContext.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/types/TestGoASTContext.py +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/types/TestGoASTContext.py @@ -1,145 +0,0 @@ -"""Test the go DWARF type parsing.""" - -from __future__ import print_function - - -import os -import time -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestGoASTContext(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - @add_test_categories(['pyapi']) - @skipIfFreeBSD # llvm.org/pr24895 triggers assertion failure - @skipIfRemote # Not remote test suit ready - @no_debug_info_test - @skipUnlessGoInstalled - @expectedFailureAll(bugnumber="llvm.org/pr33643") - def test_with_dsym_and_python_api(self): - """Test GoASTContext dwarf parsing.""" - self.buildGo() - self.launchProcess() - self.go_builtin_types() - self.check_main_vars() - - def setUp(self): - # Call super's setUp(). - TestBase.setUp(self) - # Find the line numbers to break inside main(). - self.main_source = "main.go" - self.break_line = line_number( - self.main_source, '// Set breakpoint here.') - - def check_builtin(self, name, size=0, typeclass=lldb.eTypeClassBuiltin): - tl = self.target().FindTypes(name) - self.assertEqual(1, len(tl)) - t = list(tl)[0] - self.assertEqual(name, t.name) - self.assertEqual(typeclass, t.type) - if size > 0: - self.assertEqual(size, t.size) - - def launchProcess(self): - exe = self.getBuildArtifact("a.out") - - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, VALID_TARGET) - - bpt = target.BreakpointCreateByLocation( - self.main_source, self.break_line) - self.assertTrue(bpt, VALID_BREAKPOINT) - - # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) - - self.assertTrue(process, PROCESS_IS_VALID) - - # The stop reason of the thread should be breakpoint. - thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) - - # Make sure we stopped at the first breakpoint. - self.assertTrue( - len(thread_list) != 0, - "No thread stopped at our breakpoint.") - self.assertTrue(len(thread_list) == 1, - "More than one thread stopped at our breakpoint.") - - frame = thread_list[0].GetFrameAtIndex(0) - self.assertTrue(frame, "Got a valid frame 0 frame.") - - def go_builtin_types(self): - address_size = self.target().GetAddressByteSize() - self.check_builtin('bool') - self.check_builtin('uint8', 1) - self.check_builtin('int8', 1) - self.check_builtin('uint16', 2) - self.check_builtin('int16', 2) - self.check_builtin('uint32', 4) - self.check_builtin('int32', 4) - self.check_builtin('uint64', 8) - self.check_builtin('int64', 8) - self.check_builtin('uintptr', address_size) - self.check_builtin('int', address_size) - self.check_builtin('uint', address_size) - self.check_builtin('float32', 4) - self.check_builtin('float64', 8) - self.check_builtin('complex64', 8, lldb.eTypeClassComplexFloat) - self.check_builtin('complex128', 16, lldb.eTypeClassComplexFloat) - - def var(self, name): - var = self.frame().FindVariable(name) - self.assertTrue(var.IsValid(), "%s %s" % (VALID_VARIABLE, name)) - return var - - def check_main_vars(self): - v = self.var('theBool') - self.assertEqual('true', v.value) - - v = self.var('theInt') - self.assertEqual('-7', v.value) - - v = self.var('theComplex') - self.assertEqual('1 + 2i', v.value) - - v = self.var('thePointer') - self.assertTrue(v.TypeIsPointerType()) - self.assertEqual('-10', v.Dereference().value) - self.assertEqual(1, v.GetNumChildren()) - self.assertEqual('-10', v.GetChildAtIndex(0).value) - - # print() - # print(os.getpid()) - # time.sleep(60) - v = self.var('theStruct') - if v.TypeIsPointerType(): - v = v.Dereference() - self.assertEqual(2, v.GetNumChildren()) - self.assertEqual('7', v.GetChildAtIndex(0).value) - self.assertEqual('7', v.GetChildMemberWithName('myInt').value) - self.assertEqual( - v.load_addr, - v.GetChildAtIndex(1).GetValueAsUnsigned()) - self.assertEqual(v.load_addr, v.GetChildMemberWithName( - 'myPointer').GetValueAsUnsigned()) - - # Test accessing struct fields through pointers. - v = v.GetChildMemberWithName('myPointer') - self.assertTrue(v.TypeIsPointerType()) - self.assertEqual(2, v.GetNumChildren()) - self.assertEqual('7', v.GetChildAtIndex(0).value) - c = v.GetChildMemberWithName('myPointer') - self.assertTrue(c.TypeIsPointerType()) - self.assertEqual(2, c.GetNumChildren()) - self.assertEqual('7', c.GetChildAtIndex(0).value) - - v = self.var('theArray') - self.assertEqual(5, v.GetNumChildren()) - for i in list(range(5)): - self.assertEqual(str(i + 1), v.GetChildAtIndex(i).value) Index: lldb/trunk/packages/Python/lldbsuite/test/lang/go/types/main.go =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/go/types/main.go +++ lldb/trunk/packages/Python/lldbsuite/test/lang/go/types/main.go @@ -1,47 +0,0 @@ -package main - -import "fmt" - -type Fooer interface { - Foo() int -} - -type SomeFooer struct { - val int -} - -func (s SomeFooer) Foo() int { - return s.val -} - -type mystruct struct { - myInt int - myPointer *mystruct -} - -func main() { - theBool := true - theInt := -7 - theComplex := 1 + 2i - pointee := -10 - thePointer := &pointee - theStruct := &mystruct { myInt: 7} - theStruct.myPointer = theStruct - theArray := [5]byte{1, 2, 3, 4, 5} - theSlice := theArray[1:2] - theString := "abc" - - f := SomeFooer {9} - var theEface interface{} = f - var theFooer Fooer = f - - theChan := make(chan int) - theMap := make(map[int]string) - theMap[1] = "1" - - fmt.Println(theBool) // Set breakpoint here. - // Reference all the variables so the compiler is happy. - fmt.Println(theInt, theComplex, thePointer, theStruct.myInt) - fmt.Println(theArray[0], theSlice[0], theString) - fmt.Println(theEface, theFooer, theChan, theMap) -} \ No newline at end of file Index: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py +++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py @@ -1307,18 +1307,6 @@ version = m.group(1) return version - def getGoCompilerVersion(self): - """ Returns a string that represents the go compiler version, or None if go is not found. - """ - compiler = which("go") - if compiler: - version_output = system([[compiler, "version"]])[0] - for line in version_output.split(os.linesep): - m = re.search('go version (devel|go\\S+)', line) - if m: - return m.group(1) - return None - def platformIsDarwin(self): """Returns true if the OS triple for the selected platform is any valid apple OS""" return lldbplatformutil.platformIsDarwin() @@ -1587,12 +1575,6 @@ dictionary, testdir, testname): raise Exception("Don't know how to build binary with gmodules") - def buildGo(self): - """Build the default go binary. - """ - exe = self.getBuildArtifact("a.out") - system([[which('go'), 'build -gcflags "-N -l" -o %s main.go' % exe]]) - def signBinary(self, binary_path): if sys.platform.startswith("darwin"): codesign_cmd = "codesign --force --sign \"%s\" %s" % ( Index: lldb/trunk/packages/Python/lldbsuite/test/settings/TestSettings.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/settings/TestSettings.py +++ lldb/trunk/packages/Python/lldbsuite/test/settings/TestSettings.py @@ -418,11 +418,11 @@ # Set to known value self.runCmd("settings set target.language c89") # Set to new value with trailing whitespace - self.runCmd("settings set target.language go ") + self.runCmd("settings set target.language c11 ") self.expect( "settings show target.language", SETTING_MSG("target.language"), - startstr="target.language (language) = go") + startstr="target.language (language) = c11") self.runCmd("settings clear target.language", check=False) # arguments self.runCmd("settings set target.run-args 1 2 3") # Set to known value Index: lldb/trunk/source/API/SystemInitializerFull.cpp =================================================================== --- lldb/trunk/source/API/SystemInitializerFull.cpp +++ lldb/trunk/source/API/SystemInitializerFull.cpp @@ -24,7 +24,6 @@ #include "lldb/Initialization/SystemInitializerCommon.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Symbol/ClangASTContext.h" -#include "lldb/Symbol/GoASTContext.h" #include "lldb/Symbol/JavaASTContext.h" #include "lldb/Symbol/OCamlASTContext.h" #include "lldb/Utility/Timer.h" @@ -58,13 +57,11 @@ #include "Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.h" #include "Plugins/JITLoader/GDB/JITLoaderGDB.h" #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" -#include "Plugins/Language/Go/GoLanguage.h" #include "Plugins/Language/Java/JavaLanguage.h" #include "Plugins/Language/OCaml/OCamlLanguage.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" #include "Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h" #include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h" -#include "Plugins/LanguageRuntime/Go/GoLanguageRuntime.h" #include "Plugins/LanguageRuntime/Java/JavaLanguageRuntime.h" #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h" #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h" @@ -73,7 +70,6 @@ #include "Plugins/ObjectFile/ELF/ObjectFileELF.h" #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h" -#include "Plugins/OperatingSystem/Go/OperatingSystemGo.h" #include "Plugins/OperatingSystem/Python/OperatingSystemPython.h" #include "Plugins/Platform/Android/PlatformAndroid.h" #include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h" @@ -177,7 +173,7 @@ extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor, const char *method_name, Event *event_sp, bool &got_error); - + extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver( const char *python_class_name, const char *session_dictionary_name, @@ -284,7 +280,6 @@ #ifndef LLDB_DISABLE_PYTHON OperatingSystemPython::Initialize(); #endif - OperatingSystemGo::Initialize(); #if !defined(LLDB_DISABLE_PYTHON) InitializeSWIG(); @@ -316,7 +311,6 @@ llvm::InitializeAllDisassemblers(); ClangASTContext::Initialize(); - GoASTContext::Initialize(); JavaASTContext::Initialize(); OCamlASTContext::Initialize(); @@ -363,11 +357,9 @@ AppleObjCRuntimeV1::Initialize(); SystemRuntimeMacOSX::Initialize(); RenderScriptRuntime::Initialize(); - GoLanguageRuntime::Initialize(); JavaLanguageRuntime::Initialize(); CPlusPlusLanguage::Initialize(); - GoLanguage::Initialize(); JavaLanguage::Initialize(); ObjCLanguage::Initialize(); ObjCPlusPlusLanguage::Initialize(); @@ -451,7 +443,6 @@ PluginManager::Terminate(); ClangASTContext::Terminate(); - GoASTContext::Terminate(); JavaASTContext::Terminate(); OCamlASTContext::Terminate(); @@ -496,7 +487,6 @@ JavaLanguageRuntime::Terminate(); CPlusPlusLanguage::Terminate(); - GoLanguage::Terminate(); JavaLanguage::Terminate(); ObjCLanguage::Terminate(); ObjCPlusPlusLanguage::Terminate(); @@ -531,7 +521,6 @@ #ifndef LLDB_DISABLE_PYTHON OperatingSystemPython::Terminate(); #endif - OperatingSystemGo::Terminate(); platform_freebsd::PlatformFreeBSD::Terminate(); platform_linux::PlatformLinux::Terminate(); Index: lldb/trunk/source/Plugins/ExpressionParser/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/CMakeLists.txt +++ lldb/trunk/source/Plugins/ExpressionParser/CMakeLists.txt @@ -1,2 +1 @@ add_subdirectory(Clang) -add_subdirectory(Go) Index: lldb/trunk/source/Plugins/ExpressionParser/Go/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Go/CMakeLists.txt +++ lldb/trunk/source/Plugins/ExpressionParser/Go/CMakeLists.txt @@ -1,13 +0,0 @@ -add_lldb_library(lldbPluginExpressionParserGo PLUGIN - GoLexer.cpp - GoParser.cpp - GoUserExpression.cpp - - LINK_LIBS - lldbCore - lldbExpression - lldbSymbol - lldbTarget - LINK_COMPONENTS - Support - ) Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoAST.h =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Go/GoAST.h +++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoAST.h @@ -1,1977 +0,0 @@ -//===-- GoAST.h -------------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// DO NOT EDIT. -// Generated by gen_go_ast.py - -#ifndef liblldb_GoAST_h -#define liblldb_GoAST_h - -#include "Plugins/ExpressionParser/Go/GoLexer.h" -#include "lldb/lldb-forward.h" -#include "lldb/lldb-private.h" -#include "llvm/Support/Casting.h" - -namespace lldb_private { - -class GoASTNode { -public: - typedef GoLexer::TokenType TokenType; - typedef GoLexer::Token Token; - enum ChanDir { - eChanBidir, - eChanSend, - eChanRecv, - }; - enum NodeKind { - eBadDecl, - eFuncDecl, - eGenDecl, - eArrayType, - eBadExpr, - eBasicLit, - eBinaryExpr, - eIdent, - eCallExpr, - eChanType, - eCompositeLit, - eEllipsis, - eFuncType, - eFuncLit, - eIndexExpr, - eInterfaceType, - eKeyValueExpr, - eMapType, - eParenExpr, - eSelectorExpr, - eSliceExpr, - eStarExpr, - eStructType, - eTypeAssertExpr, - eUnaryExpr, - eImportSpec, - eTypeSpec, - eValueSpec, - eAssignStmt, - eBadStmt, - eBlockStmt, - eBranchStmt, - eCaseClause, - eCommClause, - eDeclStmt, - eDeferStmt, - eEmptyStmt, - eExprStmt, - eForStmt, - eGoStmt, - eIfStmt, - eIncDecStmt, - eLabeledStmt, - eRangeStmt, - eReturnStmt, - eSelectStmt, - eSendStmt, - eSwitchStmt, - eTypeSwitchStmt, - eField, - eFieldList, - }; - - virtual ~GoASTNode() = default; - - NodeKind GetKind() const { return m_kind; } - - virtual const char *GetKindName() const = 0; - - template void WalkChildren(V &v); - -protected: - explicit GoASTNode(NodeKind kind) : m_kind(kind) {} - -private: - const NodeKind m_kind; - - GoASTNode(const GoASTNode &) = delete; - const GoASTNode &operator=(const GoASTNode &) = delete; -}; - -class GoASTDecl : public GoASTNode { -public: - template R Visit(V *v) const; - - static bool classof(const GoASTNode *n) { - return n->GetKind() >= eBadDecl && n->GetKind() <= eGenDecl; - } - -protected: - explicit GoASTDecl(NodeKind kind) : GoASTNode(kind) {} - -private: - GoASTDecl(const GoASTDecl &) = delete; - const GoASTDecl &operator=(const GoASTDecl &) = delete; -}; - -class GoASTExpr : public GoASTNode { -public: - template R Visit(V *v) const; - - static bool classof(const GoASTNode *n) { - return n->GetKind() >= eArrayType && n->GetKind() <= eUnaryExpr; - } - -protected: - explicit GoASTExpr(NodeKind kind) : GoASTNode(kind) {} - -private: - GoASTExpr(const GoASTExpr &) = delete; - const GoASTExpr &operator=(const GoASTExpr &) = delete; -}; - -class GoASTSpec : public GoASTNode { -public: - template R Visit(V *v) const; - - static bool classof(const GoASTNode *n) { - return n->GetKind() >= eImportSpec && n->GetKind() <= eValueSpec; - } - -protected: - explicit GoASTSpec(NodeKind kind) : GoASTNode(kind) {} - -private: - GoASTSpec(const GoASTSpec &) = delete; - const GoASTSpec &operator=(const GoASTSpec &) = delete; -}; - -class GoASTStmt : public GoASTNode { -public: - template R Visit(V *v) const; - - static bool classof(const GoASTNode *n) { - return n->GetKind() >= eAssignStmt && n->GetKind() <= eTypeSwitchStmt; - } - -protected: - explicit GoASTStmt(NodeKind kind) : GoASTNode(kind) {} - -private: - GoASTStmt(const GoASTStmt &) = delete; - const GoASTStmt &operator=(const GoASTStmt &) = delete; -}; - -class GoASTArrayType : public GoASTExpr { -public: - GoASTArrayType(GoASTExpr *len, GoASTExpr *elt) - : GoASTExpr(eArrayType), m_len_up(len), m_elt_up(elt) {} - ~GoASTArrayType() override = default; - - const char *GetKindName() const override { return "ArrayType"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eArrayType; } - - const GoASTExpr *GetLen() const { return m_len_up.get(); } - void SetLen(GoASTExpr *len) { m_len_up.reset(len); } - - const GoASTExpr *GetElt() const { return m_elt_up.get(); } - void SetElt(GoASTExpr *elt) { m_elt_up.reset(elt); } - -private: - friend class GoASTNode; - std::unique_ptr m_len_up; - std::unique_ptr m_elt_up; - - GoASTArrayType(const GoASTArrayType &) = delete; - const GoASTArrayType &operator=(const GoASTArrayType &) = delete; -}; - -class GoASTAssignStmt : public GoASTStmt { -public: - explicit GoASTAssignStmt(bool define) - : GoASTStmt(eAssignStmt), m_define(define) {} - ~GoASTAssignStmt() override = default; - - const char *GetKindName() const override { return "AssignStmt"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eAssignStmt; - } - - size_t NumLhs() const { return m_lhs.size(); } - const GoASTExpr *GetLhs(int i) const { return m_lhs[i].get(); } - void AddLhs(GoASTExpr *lhs) { - m_lhs.push_back(std::unique_ptr(lhs)); - } - - size_t NumRhs() const { return m_rhs.size(); } - const GoASTExpr *GetRhs(int i) const { return m_rhs[i].get(); } - void AddRhs(GoASTExpr *rhs) { - m_rhs.push_back(std::unique_ptr(rhs)); - } - - bool GetDefine() const { return m_define; } - void SetDefine(bool define) { m_define = define; } - -private: - friend class GoASTNode; - std::vector> m_lhs; - std::vector> m_rhs; - bool m_define; - - GoASTAssignStmt(const GoASTAssignStmt &) = delete; - const GoASTAssignStmt &operator=(const GoASTAssignStmt &) = delete; -}; - -class GoASTBadDecl : public GoASTDecl { -public: - GoASTBadDecl() : GoASTDecl(eBadDecl) {} - ~GoASTBadDecl() override = default; - - const char *GetKindName() const override { return "BadDecl"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eBadDecl; } - - GoASTBadDecl(const GoASTBadDecl &) = delete; - const GoASTBadDecl &operator=(const GoASTBadDecl &) = delete; -}; - -class GoASTBadExpr : public GoASTExpr { -public: - GoASTBadExpr() : GoASTExpr(eBadExpr) {} - ~GoASTBadExpr() override = default; - - const char *GetKindName() const override { return "BadExpr"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eBadExpr; } - - GoASTBadExpr(const GoASTBadExpr &) = delete; - const GoASTBadExpr &operator=(const GoASTBadExpr &) = delete; -}; - -class GoASTBadStmt : public GoASTStmt { -public: - GoASTBadStmt() : GoASTStmt(eBadStmt) {} - ~GoASTBadStmt() override = default; - - const char *GetKindName() const override { return "BadStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eBadStmt; } - - GoASTBadStmt(const GoASTBadStmt &) = delete; - const GoASTBadStmt &operator=(const GoASTBadStmt &) = delete; -}; - -class GoASTBasicLit : public GoASTExpr { -public: - explicit GoASTBasicLit(Token value) : GoASTExpr(eBasicLit), m_value(value) {} - ~GoASTBasicLit() override = default; - - const char *GetKindName() const override { return "BasicLit"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eBasicLit; } - - Token GetValue() const { return m_value; } - void SetValue(Token value) { m_value = value; } - -private: - friend class GoASTNode; - Token m_value; - - GoASTBasicLit(const GoASTBasicLit &) = delete; - const GoASTBasicLit &operator=(const GoASTBasicLit &) = delete; -}; - -class GoASTBinaryExpr : public GoASTExpr { -public: - GoASTBinaryExpr(GoASTExpr *x, GoASTExpr *y, TokenType op) - : GoASTExpr(eBinaryExpr), m_x_up(x), m_y_up(y), m_op(op) {} - ~GoASTBinaryExpr() override = default; - - const char *GetKindName() const override { return "BinaryExpr"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eBinaryExpr; - } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - - const GoASTExpr *GetY() const { return m_y_up.get(); } - void SetY(GoASTExpr *y) { m_y_up.reset(y); } - - TokenType GetOp() const { return m_op; } - void SetOp(TokenType op) { m_op = op; } - -private: - friend class GoASTNode; - std::unique_ptr m_x_up; - std::unique_ptr m_y_up; - TokenType m_op; - - GoASTBinaryExpr(const GoASTBinaryExpr &) = delete; - const GoASTBinaryExpr &operator=(const GoASTBinaryExpr &) = delete; -}; - -class GoASTBlockStmt : public GoASTStmt { -public: - GoASTBlockStmt() : GoASTStmt(eBlockStmt) {} - ~GoASTBlockStmt() override = default; - - const char *GetKindName() const override { return "BlockStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eBlockStmt; } - - size_t NumList() const { return m_list.size(); } - const GoASTStmt *GetList(int i) const { return m_list[i].get(); } - void AddList(GoASTStmt *list) { - m_list.push_back(std::unique_ptr(list)); - } - -private: - friend class GoASTNode; - std::vector> m_list; - - GoASTBlockStmt(const GoASTBlockStmt &) = delete; - const GoASTBlockStmt &operator=(const GoASTBlockStmt &) = delete; -}; - -class GoASTIdent : public GoASTExpr { -public: - explicit GoASTIdent(Token name) : GoASTExpr(eIdent), m_name(name) {} - ~GoASTIdent() override = default; - - const char *GetKindName() const override { return "Ident"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eIdent; } - - Token GetName() const { return m_name; } - void SetName(Token name) { m_name = name; } - -private: - friend class GoASTNode; - Token m_name; - - GoASTIdent(const GoASTIdent &) = delete; - const GoASTIdent &operator=(const GoASTIdent &) = delete; -}; - -class GoASTBranchStmt : public GoASTStmt { -public: - GoASTBranchStmt(GoASTIdent *label, TokenType tok) - : GoASTStmt(eBranchStmt), m_label_up(label), m_tok(tok) {} - ~GoASTBranchStmt() override = default; - - const char *GetKindName() const override { return "BranchStmt"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eBranchStmt; - } - - const GoASTIdent *GetLabel() const { return m_label_up.get(); } - void SetLabel(GoASTIdent *label) { m_label_up.reset(label); } - - TokenType GetTok() const { return m_tok; } - void SetTok(TokenType tok) { m_tok = tok; } - -private: - friend class GoASTNode; - std::unique_ptr m_label_up; - TokenType m_tok; - - GoASTBranchStmt(const GoASTBranchStmt &) = delete; - const GoASTBranchStmt &operator=(const GoASTBranchStmt &) = delete; -}; - -class GoASTCallExpr : public GoASTExpr { -public: - explicit GoASTCallExpr(bool ellipsis) - : GoASTExpr(eCallExpr), m_ellipsis(ellipsis) {} - ~GoASTCallExpr() override = default; - - const char *GetKindName() const override { return "CallExpr"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eCallExpr; } - - const GoASTExpr *GetFun() const { return m_fun_up.get(); } - void SetFun(GoASTExpr *fun) { m_fun_up.reset(fun); } - - size_t NumArgs() const { return m_args.size(); } - const GoASTExpr *GetArgs(int i) const { return m_args[i].get(); } - void AddArgs(GoASTExpr *args) { - m_args.push_back(std::unique_ptr(args)); - } - - bool GetEllipsis() const { return m_ellipsis; } - void SetEllipsis(bool ellipsis) { m_ellipsis = ellipsis; } - -private: - friend class GoASTNode; - std::unique_ptr m_fun_up; - std::vector> m_args; - bool m_ellipsis; - - GoASTCallExpr(const GoASTCallExpr &) = delete; - const GoASTCallExpr &operator=(const GoASTCallExpr &) = delete; -}; - -class GoASTCaseClause : public GoASTStmt { -public: - GoASTCaseClause() : GoASTStmt(eCaseClause) {} - ~GoASTCaseClause() override = default; - - const char *GetKindName() const override { return "CaseClause"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eCaseClause; - } - - size_t NumList() const { return m_list.size(); } - const GoASTExpr *GetList(int i) const { return m_list[i].get(); } - void AddList(GoASTExpr *list) { - m_list.push_back(std::unique_ptr(list)); - } - - size_t NumBody() const { return m_body.size(); } - const GoASTStmt *GetBody(int i) const { return m_body[i].get(); } - void AddBody(GoASTStmt *body) { - m_body.push_back(std::unique_ptr(body)); - } - -private: - friend class GoASTNode; - std::vector> m_list; - std::vector> m_body; - - GoASTCaseClause(const GoASTCaseClause &) = delete; - const GoASTCaseClause &operator=(const GoASTCaseClause &) = delete; -}; - -class GoASTChanType : public GoASTExpr { -public: - GoASTChanType(ChanDir dir, GoASTExpr *value) - : GoASTExpr(eChanType), m_dir(dir), m_value_up(value) {} - ~GoASTChanType() override = default; - - const char *GetKindName() const override { return "ChanType"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eChanType; } - - ChanDir GetDir() const { return m_dir; } - void SetDir(ChanDir dir) { m_dir = dir; } - - const GoASTExpr *GetValue() const { return m_value_up.get(); } - void SetValue(GoASTExpr *value) { m_value_up.reset(value); } - -private: - friend class GoASTNode; - ChanDir m_dir; - std::unique_ptr m_value_up; - - GoASTChanType(const GoASTChanType &) = delete; - const GoASTChanType &operator=(const GoASTChanType &) = delete; -}; - -class GoASTCommClause : public GoASTStmt { -public: - GoASTCommClause() : GoASTStmt(eCommClause) {} - ~GoASTCommClause() override = default; - - const char *GetKindName() const override { return "CommClause"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eCommClause; - } - - const GoASTStmt *GetComm() const { return m_comm_up.get(); } - void SetComm(GoASTStmt *comm) { m_comm_up.reset(comm); } - - size_t NumBody() const { return m_body.size(); } - const GoASTStmt *GetBody(int i) const { return m_body[i].get(); } - void AddBody(GoASTStmt *body) { - m_body.push_back(std::unique_ptr(body)); - } - -private: - friend class GoASTNode; - std::unique_ptr m_comm_up; - std::vector> m_body; - - GoASTCommClause(const GoASTCommClause &) = delete; - const GoASTCommClause &operator=(const GoASTCommClause &) = delete; -}; - -class GoASTCompositeLit : public GoASTExpr { -public: - GoASTCompositeLit() : GoASTExpr(eCompositeLit) {} - ~GoASTCompositeLit() override = default; - - const char *GetKindName() const override { return "CompositeLit"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eCompositeLit; - } - - const GoASTExpr *GetType() const { return m_type_up.get(); } - void SetType(GoASTExpr *type) { m_type_up.reset(type); } - - size_t NumElts() const { return m_elts.size(); } - const GoASTExpr *GetElts(int i) const { return m_elts[i].get(); } - void AddElts(GoASTExpr *elts) { - m_elts.push_back(std::unique_ptr(elts)); - } - -private: - friend class GoASTNode; - std::unique_ptr m_type_up; - std::vector> m_elts; - - GoASTCompositeLit(const GoASTCompositeLit &) = delete; - const GoASTCompositeLit &operator=(const GoASTCompositeLit &) = delete; -}; - -class GoASTDeclStmt : public GoASTStmt { -public: - explicit GoASTDeclStmt(GoASTDecl *decl) - : GoASTStmt(eDeclStmt), m_decl_up(decl) {} - ~GoASTDeclStmt() override = default; - - const char *GetKindName() const override { return "DeclStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eDeclStmt; } - - const GoASTDecl *GetDecl() const { return m_decl_up.get(); } - void SetDecl(GoASTDecl *decl) { m_decl_up.reset(decl); } - -private: - friend class GoASTNode; - std::unique_ptr m_decl_up; - - GoASTDeclStmt(const GoASTDeclStmt &) = delete; - const GoASTDeclStmt &operator=(const GoASTDeclStmt &) = delete; -}; - -class GoASTDeferStmt : public GoASTStmt { -public: - explicit GoASTDeferStmt(GoASTCallExpr *call) - : GoASTStmt(eDeferStmt), m_call_up(call) {} - ~GoASTDeferStmt() override = default; - - const char *GetKindName() const override { return "DeferStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eDeferStmt; } - - const GoASTCallExpr *GetCall() const { return m_call_up.get(); } - void SetCall(GoASTCallExpr *call) { m_call_up.reset(call); } - -private: - friend class GoASTNode; - std::unique_ptr m_call_up; - - GoASTDeferStmt(const GoASTDeferStmt &) = delete; - const GoASTDeferStmt &operator=(const GoASTDeferStmt &) = delete; -}; - -class GoASTEllipsis : public GoASTExpr { -public: - explicit GoASTEllipsis(GoASTExpr *elt) - : GoASTExpr(eEllipsis), m_elt_up(elt) {} - ~GoASTEllipsis() override = default; - - const char *GetKindName() const override { return "Ellipsis"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eEllipsis; } - - const GoASTExpr *GetElt() const { return m_elt_up.get(); } - void SetElt(GoASTExpr *elt) { m_elt_up.reset(elt); } - -private: - friend class GoASTNode; - std::unique_ptr m_elt_up; - - GoASTEllipsis(const GoASTEllipsis &) = delete; - const GoASTEllipsis &operator=(const GoASTEllipsis &) = delete; -}; - -class GoASTEmptyStmt : public GoASTStmt { -public: - GoASTEmptyStmt() : GoASTStmt(eEmptyStmt) {} - ~GoASTEmptyStmt() override = default; - - const char *GetKindName() const override { return "EmptyStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eEmptyStmt; } - - GoASTEmptyStmt(const GoASTEmptyStmt &) = delete; - const GoASTEmptyStmt &operator=(const GoASTEmptyStmt &) = delete; -}; - -class GoASTExprStmt : public GoASTStmt { -public: - explicit GoASTExprStmt(GoASTExpr *x) : GoASTStmt(eExprStmt), m_x_up(x) {} - ~GoASTExprStmt() override = default; - - const char *GetKindName() const override { return "ExprStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eExprStmt; } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - -private: - friend class GoASTNode; - std::unique_ptr m_x_up; - - GoASTExprStmt(const GoASTExprStmt &) = delete; - const GoASTExprStmt &operator=(const GoASTExprStmt &) = delete; -}; - -class GoASTField : public GoASTNode { -public: - GoASTField() : GoASTNode(eField) {} - ~GoASTField() override = default; - - const char *GetKindName() const override { return "Field"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eField; } - - size_t NumNames() const { return m_names.size(); } - const GoASTIdent *GetNames(int i) const { return m_names[i].get(); } - void AddNames(GoASTIdent *names) { - m_names.push_back(std::unique_ptr(names)); - } - - const GoASTExpr *GetType() const { return m_type_up.get(); } - void SetType(GoASTExpr *type) { m_type_up.reset(type); } - - const GoASTBasicLit *GetTag() const { return m_tag_up.get(); } - void SetTag(GoASTBasicLit *tag) { m_tag_up.reset(tag); } - -private: - friend class GoASTNode; - std::vector> m_names; - std::unique_ptr m_type_up; - std::unique_ptr m_tag_up; - - GoASTField(const GoASTField &) = delete; - const GoASTField &operator=(const GoASTField &) = delete; -}; - -class GoASTFieldList : public GoASTNode { -public: - GoASTFieldList() : GoASTNode(eFieldList) {} - ~GoASTFieldList() override = default; - - const char *GetKindName() const override { return "FieldList"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eFieldList; } - - size_t NumList() const { return m_list.size(); } - const GoASTField *GetList(int i) const { return m_list[i].get(); } - void AddList(GoASTField *list) { - m_list.push_back(std::unique_ptr(list)); - } - -private: - friend class GoASTNode; - std::vector> m_list; - - GoASTFieldList(const GoASTFieldList &) = delete; - const GoASTFieldList &operator=(const GoASTFieldList &) = delete; -}; - -class GoASTForStmt : public GoASTStmt { -public: - GoASTForStmt(GoASTStmt *init, GoASTExpr *cond, GoASTStmt *post, - GoASTBlockStmt *body) - : GoASTStmt(eForStmt), m_init_up(init), m_cond_up(cond), m_post_up(post), - m_body_up(body) {} - ~GoASTForStmt() override = default; - - const char *GetKindName() const override { return "ForStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eForStmt; } - - const GoASTStmt *GetInit() const { return m_init_up.get(); } - void SetInit(GoASTStmt *init) { m_init_up.reset(init); } - - const GoASTExpr *GetCond() const { return m_cond_up.get(); } - void SetCond(GoASTExpr *cond) { m_cond_up.reset(cond); } - - const GoASTStmt *GetPost() const { return m_post_up.get(); } - void SetPost(GoASTStmt *post) { m_post_up.reset(post); } - - const GoASTBlockStmt *GetBody() const { return m_body_up.get(); } - void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); } - -private: - friend class GoASTNode; - std::unique_ptr m_init_up; - std::unique_ptr m_cond_up; - std::unique_ptr m_post_up; - std::unique_ptr m_body_up; - - GoASTForStmt(const GoASTForStmt &) = delete; - const GoASTForStmt &operator=(const GoASTForStmt &) = delete; -}; - -class GoASTFuncType : public GoASTExpr { -public: - GoASTFuncType(GoASTFieldList *params, GoASTFieldList *results) - : GoASTExpr(eFuncType), m_params_up(params), m_results_up(results) {} - ~GoASTFuncType() override = default; - - const char *GetKindName() const override { return "FuncType"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eFuncType; } - - const GoASTFieldList *GetParams() const { return m_params_up.get(); } - void SetParams(GoASTFieldList *params) { m_params_up.reset(params); } - - const GoASTFieldList *GetResults() const { return m_results_up.get(); } - void SetResults(GoASTFieldList *results) { m_results_up.reset(results); } - -private: - friend class GoASTNode; - std::unique_ptr m_params_up; - std::unique_ptr m_results_up; - - GoASTFuncType(const GoASTFuncType &) = delete; - const GoASTFuncType &operator=(const GoASTFuncType &) = delete; -}; - -class GoASTFuncDecl : public GoASTDecl { -public: - GoASTFuncDecl(GoASTFieldList *recv, GoASTIdent *name, GoASTFuncType *type, - GoASTBlockStmt *body) - : GoASTDecl(eFuncDecl), m_recv_up(recv), m_name_up(name), m_type_up(type), - m_body_up(body) {} - ~GoASTFuncDecl() override = default; - - const char *GetKindName() const override { return "FuncDecl"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eFuncDecl; } - - const GoASTFieldList *GetRecv() const { return m_recv_up.get(); } - void SetRecv(GoASTFieldList *recv) { m_recv_up.reset(recv); } - - const GoASTIdent *GetName() const { return m_name_up.get(); } - void SetName(GoASTIdent *name) { m_name_up.reset(name); } - - const GoASTFuncType *GetType() const { return m_type_up.get(); } - void SetType(GoASTFuncType *type) { m_type_up.reset(type); } - - const GoASTBlockStmt *GetBody() const { return m_body_up.get(); } - void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); } - -private: - friend class GoASTNode; - std::unique_ptr m_recv_up; - std::unique_ptr m_name_up; - std::unique_ptr m_type_up; - std::unique_ptr m_body_up; - - GoASTFuncDecl(const GoASTFuncDecl &) = delete; - const GoASTFuncDecl &operator=(const GoASTFuncDecl &) = delete; -}; - -class GoASTFuncLit : public GoASTExpr { -public: - GoASTFuncLit(GoASTFuncType *type, GoASTBlockStmt *body) - : GoASTExpr(eFuncLit), m_type_up(type), m_body_up(body) {} - ~GoASTFuncLit() override = default; - - const char *GetKindName() const override { return "FuncLit"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eFuncLit; } - - const GoASTFuncType *GetType() const { return m_type_up.get(); } - void SetType(GoASTFuncType *type) { m_type_up.reset(type); } - - const GoASTBlockStmt *GetBody() const { return m_body_up.get(); } - void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); } - -private: - friend class GoASTNode; - std::unique_ptr m_type_up; - std::unique_ptr m_body_up; - - GoASTFuncLit(const GoASTFuncLit &) = delete; - const GoASTFuncLit &operator=(const GoASTFuncLit &) = delete; -}; - -class GoASTGenDecl : public GoASTDecl { -public: - explicit GoASTGenDecl(TokenType tok) : GoASTDecl(eGenDecl), m_tok(tok) {} - ~GoASTGenDecl() override = default; - - const char *GetKindName() const override { return "GenDecl"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eGenDecl; } - - TokenType GetTok() const { return m_tok; } - void SetTok(TokenType tok) { m_tok = tok; } - - size_t NumSpecs() const { return m_specs.size(); } - const GoASTSpec *GetSpecs(int i) const { return m_specs[i].get(); } - void AddSpecs(GoASTSpec *specs) { - m_specs.push_back(std::unique_ptr(specs)); - } - -private: - friend class GoASTNode; - TokenType m_tok; - std::vector> m_specs; - - GoASTGenDecl(const GoASTGenDecl &) = delete; - const GoASTGenDecl &operator=(const GoASTGenDecl &) = delete; -}; - -class GoASTGoStmt : public GoASTStmt { -public: - explicit GoASTGoStmt(GoASTCallExpr *call) - : GoASTStmt(eGoStmt), m_call_up(call) {} - ~GoASTGoStmt() override = default; - - const char *GetKindName() const override { return "GoStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eGoStmt; } - - const GoASTCallExpr *GetCall() const { return m_call_up.get(); } - void SetCall(GoASTCallExpr *call) { m_call_up.reset(call); } - -private: - friend class GoASTNode; - std::unique_ptr m_call_up; - - GoASTGoStmt(const GoASTGoStmt &) = delete; - const GoASTGoStmt &operator=(const GoASTGoStmt &) = delete; -}; - -class GoASTIfStmt : public GoASTStmt { -public: - GoASTIfStmt(GoASTStmt *init, GoASTExpr *cond, GoASTBlockStmt *body, - GoASTStmt *els) - : GoASTStmt(eIfStmt), m_init_up(init), m_cond_up(cond), m_body_up(body), - m_els_up(els) {} - ~GoASTIfStmt() override = default; - - const char *GetKindName() const override { return "IfStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eIfStmt; } - - const GoASTStmt *GetInit() const { return m_init_up.get(); } - void SetInit(GoASTStmt *init) { m_init_up.reset(init); } - - const GoASTExpr *GetCond() const { return m_cond_up.get(); } - void SetCond(GoASTExpr *cond) { m_cond_up.reset(cond); } - - const GoASTBlockStmt *GetBody() const { return m_body_up.get(); } - void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); } - - const GoASTStmt *GetEls() const { return m_els_up.get(); } - void SetEls(GoASTStmt *els) { m_els_up.reset(els); } - -private: - friend class GoASTNode; - std::unique_ptr m_init_up; - std::unique_ptr m_cond_up; - std::unique_ptr m_body_up; - std::unique_ptr m_els_up; - - GoASTIfStmt(const GoASTIfStmt &) = delete; - const GoASTIfStmt &operator=(const GoASTIfStmt &) = delete; -}; - -class GoASTImportSpec : public GoASTSpec { -public: - GoASTImportSpec(GoASTIdent *name, GoASTBasicLit *path) - : GoASTSpec(eImportSpec), m_name_up(name), m_path_up(path) {} - ~GoASTImportSpec() override = default; - - const char *GetKindName() const override { return "ImportSpec"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eImportSpec; - } - - const GoASTIdent *GetName() const { return m_name_up.get(); } - void SetName(GoASTIdent *name) { m_name_up.reset(name); } - - const GoASTBasicLit *GetPath() const { return m_path_up.get(); } - void SetPath(GoASTBasicLit *path) { m_path_up.reset(path); } - -private: - friend class GoASTNode; - std::unique_ptr m_name_up; - std::unique_ptr m_path_up; - - GoASTImportSpec(const GoASTImportSpec &) = delete; - const GoASTImportSpec &operator=(const GoASTImportSpec &) = delete; -}; - -class GoASTIncDecStmt : public GoASTStmt { -public: - GoASTIncDecStmt(GoASTExpr *x, TokenType tok) - : GoASTStmt(eIncDecStmt), m_x_up(x), m_tok(tok) {} - ~GoASTIncDecStmt() override = default; - - const char *GetKindName() const override { return "IncDecStmt"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eIncDecStmt; - } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - - TokenType GetTok() const { return m_tok; } - void SetTok(TokenType tok) { m_tok = tok; } - -private: - friend class GoASTNode; - std::unique_ptr m_x_up; - TokenType m_tok; - - GoASTIncDecStmt(const GoASTIncDecStmt &) = delete; - const GoASTIncDecStmt &operator=(const GoASTIncDecStmt &) = delete; -}; - -class GoASTIndexExpr : public GoASTExpr { -public: - GoASTIndexExpr(GoASTExpr *x, GoASTExpr *index) - : GoASTExpr(eIndexExpr), m_x_up(x), m_index_up(index) {} - ~GoASTIndexExpr() override = default; - - const char *GetKindName() const override { return "IndexExpr"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eIndexExpr; } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - - const GoASTExpr *GetIndex() const { return m_index_up.get(); } - void SetIndex(GoASTExpr *index) { m_index_up.reset(index); } - -private: - friend class GoASTNode; - std::unique_ptr m_x_up; - std::unique_ptr m_index_up; - - GoASTIndexExpr(const GoASTIndexExpr &) = delete; - const GoASTIndexExpr &operator=(const GoASTIndexExpr &) = delete; -}; - -class GoASTInterfaceType : public GoASTExpr { -public: - explicit GoASTInterfaceType(GoASTFieldList *methods) - : GoASTExpr(eInterfaceType), m_methods_up(methods) {} - ~GoASTInterfaceType() override = default; - - const char *GetKindName() const override { return "InterfaceType"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eInterfaceType; - } - - const GoASTFieldList *GetMethods() const { return m_methods_up.get(); } - void SetMethods(GoASTFieldList *methods) { m_methods_up.reset(methods); } - -private: - friend class GoASTNode; - std::unique_ptr m_methods_up; - - GoASTInterfaceType(const GoASTInterfaceType &) = delete; - const GoASTInterfaceType &operator=(const GoASTInterfaceType &) = delete; -}; - -class GoASTKeyValueExpr : public GoASTExpr { -public: - GoASTKeyValueExpr(GoASTExpr *key, GoASTExpr *value) - : GoASTExpr(eKeyValueExpr), m_key_up(key), m_value_up(value) {} - ~GoASTKeyValueExpr() override = default; - - const char *GetKindName() const override { return "KeyValueExpr"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eKeyValueExpr; - } - - const GoASTExpr *GetKey() const { return m_key_up.get(); } - void SetKey(GoASTExpr *key) { m_key_up.reset(key); } - - const GoASTExpr *GetValue() const { return m_value_up.get(); } - void SetValue(GoASTExpr *value) { m_value_up.reset(value); } - -private: - friend class GoASTNode; - std::unique_ptr m_key_up; - std::unique_ptr m_value_up; - - GoASTKeyValueExpr(const GoASTKeyValueExpr &) = delete; - const GoASTKeyValueExpr &operator=(const GoASTKeyValueExpr &) = delete; -}; - -class GoASTLabeledStmt : public GoASTStmt { -public: - GoASTLabeledStmt(GoASTIdent *label, GoASTStmt *stmt) - : GoASTStmt(eLabeledStmt), m_label_up(label), m_stmt_up(stmt) {} - ~GoASTLabeledStmt() override = default; - - const char *GetKindName() const override { return "LabeledStmt"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eLabeledStmt; - } - - const GoASTIdent *GetLabel() const { return m_label_up.get(); } - void SetLabel(GoASTIdent *label) { m_label_up.reset(label); } - - const GoASTStmt *GetStmt() const { return m_stmt_up.get(); } - void SetStmt(GoASTStmt *stmt) { m_stmt_up.reset(stmt); } - -private: - friend class GoASTNode; - std::unique_ptr m_label_up; - std::unique_ptr m_stmt_up; - - GoASTLabeledStmt(const GoASTLabeledStmt &) = delete; - const GoASTLabeledStmt &operator=(const GoASTLabeledStmt &) = delete; -}; - -class GoASTMapType : public GoASTExpr { -public: - GoASTMapType(GoASTExpr *key, GoASTExpr *value) - : GoASTExpr(eMapType), m_key_up(key), m_value_up(value) {} - ~GoASTMapType() override = default; - - const char *GetKindName() const override { return "MapType"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eMapType; } - - const GoASTExpr *GetKey() const { return m_key_up.get(); } - void SetKey(GoASTExpr *key) { m_key_up.reset(key); } - - const GoASTExpr *GetValue() const { return m_value_up.get(); } - void SetValue(GoASTExpr *value) { m_value_up.reset(value); } - -private: - friend class GoASTNode; - std::unique_ptr m_key_up; - std::unique_ptr m_value_up; - - GoASTMapType(const GoASTMapType &) = delete; - const GoASTMapType &operator=(const GoASTMapType &) = delete; -}; - -class GoASTParenExpr : public GoASTExpr { -public: - explicit GoASTParenExpr(GoASTExpr *x) : GoASTExpr(eParenExpr), m_x_up(x) {} - ~GoASTParenExpr() override = default; - - const char *GetKindName() const override { return "ParenExpr"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eParenExpr; } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - -private: - friend class GoASTNode; - std::unique_ptr m_x_up; - - GoASTParenExpr(const GoASTParenExpr &) = delete; - const GoASTParenExpr &operator=(const GoASTParenExpr &) = delete; -}; - -class GoASTRangeStmt : public GoASTStmt { -public: - GoASTRangeStmt(GoASTExpr *key, GoASTExpr *value, bool define, GoASTExpr *x, - GoASTBlockStmt *body) - : GoASTStmt(eRangeStmt), m_key_up(key), m_value_up(value), - m_define(define), m_x_up(x), m_body_up(body) {} - ~GoASTRangeStmt() override = default; - - const char *GetKindName() const override { return "RangeStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eRangeStmt; } - - const GoASTExpr *GetKey() const { return m_key_up.get(); } - void SetKey(GoASTExpr *key) { m_key_up.reset(key); } - - const GoASTExpr *GetValue() const { return m_value_up.get(); } - void SetValue(GoASTExpr *value) { m_value_up.reset(value); } - - bool GetDefine() const { return m_define; } - void SetDefine(bool define) { m_define = define; } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - - const GoASTBlockStmt *GetBody() const { return m_body_up.get(); } - void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); } - -private: - friend class GoASTNode; - std::unique_ptr m_key_up; - std::unique_ptr m_value_up; - bool m_define; - std::unique_ptr m_x_up; - std::unique_ptr m_body_up; - - GoASTRangeStmt(const GoASTRangeStmt &) = delete; - const GoASTRangeStmt &operator=(const GoASTRangeStmt &) = delete; -}; - -class GoASTReturnStmt : public GoASTStmt { -public: - GoASTReturnStmt() : GoASTStmt(eReturnStmt) {} - ~GoASTReturnStmt() override = default; - - const char *GetKindName() const override { return "ReturnStmt"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eReturnStmt; - } - - size_t NumResults() const { return m_results.size(); } - const GoASTExpr *GetResults(int i) const { return m_results[i].get(); } - void AddResults(GoASTExpr *results) { - m_results.push_back(std::unique_ptr(results)); - } - -private: - friend class GoASTNode; - std::vector> m_results; - - GoASTReturnStmt(const GoASTReturnStmt &) = delete; - const GoASTReturnStmt &operator=(const GoASTReturnStmt &) = delete; -}; - -class GoASTSelectStmt : public GoASTStmt { -public: - explicit GoASTSelectStmt(GoASTBlockStmt *body) - : GoASTStmt(eSelectStmt), m_body_up(body) {} - ~GoASTSelectStmt() override = default; - - const char *GetKindName() const override { return "SelectStmt"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eSelectStmt; - } - - const GoASTBlockStmt *GetBody() const { return m_body_up.get(); } - void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); } - -private: - friend class GoASTNode; - std::unique_ptr m_body_up; - - GoASTSelectStmt(const GoASTSelectStmt &) = delete; - const GoASTSelectStmt &operator=(const GoASTSelectStmt &) = delete; -}; - -class GoASTSelectorExpr : public GoASTExpr { -public: - GoASTSelectorExpr(GoASTExpr *x, GoASTIdent *sel) - : GoASTExpr(eSelectorExpr), m_x_up(x), m_sel_up(sel) {} - ~GoASTSelectorExpr() override = default; - - const char *GetKindName() const override { return "SelectorExpr"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eSelectorExpr; - } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - - const GoASTIdent *GetSel() const { return m_sel_up.get(); } - void SetSel(GoASTIdent *sel) { m_sel_up.reset(sel); } - -private: - friend class GoASTNode; - std::unique_ptr m_x_up; - std::unique_ptr m_sel_up; - - GoASTSelectorExpr(const GoASTSelectorExpr &) = delete; - const GoASTSelectorExpr &operator=(const GoASTSelectorExpr &) = delete; -}; - -class GoASTSendStmt : public GoASTStmt { -public: - GoASTSendStmt(GoASTExpr *chan, GoASTExpr *value) - : GoASTStmt(eSendStmt), m_chan_up(chan), m_value_up(value) {} - ~GoASTSendStmt() override = default; - - const char *GetKindName() const override { return "SendStmt"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eSendStmt; } - - const GoASTExpr *GetChan() const { return m_chan_up.get(); } - void SetChan(GoASTExpr *chan) { m_chan_up.reset(chan); } - - const GoASTExpr *GetValue() const { return m_value_up.get(); } - void SetValue(GoASTExpr *value) { m_value_up.reset(value); } - -private: - friend class GoASTNode; - std::unique_ptr m_chan_up; - std::unique_ptr m_value_up; - - GoASTSendStmt(const GoASTSendStmt &) = delete; - const GoASTSendStmt &operator=(const GoASTSendStmt &) = delete; -}; - -class GoASTSliceExpr : public GoASTExpr { -public: - GoASTSliceExpr(GoASTExpr *x, GoASTExpr *low, GoASTExpr *high, GoASTExpr *max, - bool slice3) - : GoASTExpr(eSliceExpr), m_x_up(x), m_low_up(low), m_high_up(high), - m_max_up(max), m_slice3(slice3) {} - ~GoASTSliceExpr() override = default; - - const char *GetKindName() const override { return "SliceExpr"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eSliceExpr; } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - - const GoASTExpr *GetLow() const { return m_low_up.get(); } - void SetLow(GoASTExpr *low) { m_low_up.reset(low); } - - const GoASTExpr *GetHigh() const { return m_high_up.get(); } - void SetHigh(GoASTExpr *high) { m_high_up.reset(high); } - - const GoASTExpr *GetMax() const { return m_max_up.get(); } - void SetMax(GoASTExpr *max) { m_max_up.reset(max); } - - bool GetSlice3() const { return m_slice3; } - void SetSlice3(bool slice3) { m_slice3 = slice3; } - -private: - friend class GoASTNode; - std::unique_ptr m_x_up; - std::unique_ptr m_low_up; - std::unique_ptr m_high_up; - std::unique_ptr m_max_up; - bool m_slice3; - - GoASTSliceExpr(const GoASTSliceExpr &) = delete; - const GoASTSliceExpr &operator=(const GoASTSliceExpr &) = delete; -}; - -class GoASTStarExpr : public GoASTExpr { -public: - explicit GoASTStarExpr(GoASTExpr *x) : GoASTExpr(eStarExpr), m_x_up(x) {} - ~GoASTStarExpr() override = default; - - const char *GetKindName() const override { return "StarExpr"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eStarExpr; } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - -private: - friend class GoASTNode; - std::unique_ptr m_x_up; - - GoASTStarExpr(const GoASTStarExpr &) = delete; - const GoASTStarExpr &operator=(const GoASTStarExpr &) = delete; -}; - -class GoASTStructType : public GoASTExpr { -public: - explicit GoASTStructType(GoASTFieldList *fields) - : GoASTExpr(eStructType), m_fields_up(fields) {} - ~GoASTStructType() override = default; - - const char *GetKindName() const override { return "StructType"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eStructType; - } - - const GoASTFieldList *GetFields() const { return m_fields_up.get(); } - void SetFields(GoASTFieldList *fields) { m_fields_up.reset(fields); } - -private: - friend class GoASTNode; - std::unique_ptr m_fields_up; - - GoASTStructType(const GoASTStructType &) = delete; - const GoASTStructType &operator=(const GoASTStructType &) = delete; -}; - -class GoASTSwitchStmt : public GoASTStmt { -public: - GoASTSwitchStmt(GoASTStmt *init, GoASTExpr *tag, GoASTBlockStmt *body) - : GoASTStmt(eSwitchStmt), m_init_up(init), m_tag_up(tag), - m_body_up(body) {} - ~GoASTSwitchStmt() override = default; - - const char *GetKindName() const override { return "SwitchStmt"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eSwitchStmt; - } - - const GoASTStmt *GetInit() const { return m_init_up.get(); } - void SetInit(GoASTStmt *init) { m_init_up.reset(init); } - - const GoASTExpr *GetTag() const { return m_tag_up.get(); } - void SetTag(GoASTExpr *tag) { m_tag_up.reset(tag); } - - const GoASTBlockStmt *GetBody() const { return m_body_up.get(); } - void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); } - -private: - friend class GoASTNode; - std::unique_ptr m_init_up; - std::unique_ptr m_tag_up; - std::unique_ptr m_body_up; - - GoASTSwitchStmt(const GoASTSwitchStmt &) = delete; - const GoASTSwitchStmt &operator=(const GoASTSwitchStmt &) = delete; -}; - -class GoASTTypeAssertExpr : public GoASTExpr { -public: - GoASTTypeAssertExpr(GoASTExpr *x, GoASTExpr *type) - : GoASTExpr(eTypeAssertExpr), m_x_up(x), m_type_up(type) {} - ~GoASTTypeAssertExpr() override = default; - - const char *GetKindName() const override { return "TypeAssertExpr"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eTypeAssertExpr; - } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - - const GoASTExpr *GetType() const { return m_type_up.get(); } - void SetType(GoASTExpr *type) { m_type_up.reset(type); } - -private: - friend class GoASTNode; - std::unique_ptr m_x_up; - std::unique_ptr m_type_up; - - GoASTTypeAssertExpr(const GoASTTypeAssertExpr &) = delete; - const GoASTTypeAssertExpr &operator=(const GoASTTypeAssertExpr &) = delete; -}; - -class GoASTTypeSpec : public GoASTSpec { -public: - GoASTTypeSpec(GoASTIdent *name, GoASTExpr *type) - : GoASTSpec(eTypeSpec), m_name_up(name), m_type_up(type) {} - ~GoASTTypeSpec() override = default; - - const char *GetKindName() const override { return "TypeSpec"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eTypeSpec; } - - const GoASTIdent *GetName() const { return m_name_up.get(); } - void SetName(GoASTIdent *name) { m_name_up.reset(name); } - - const GoASTExpr *GetType() const { return m_type_up.get(); } - void SetType(GoASTExpr *type) { m_type_up.reset(type); } - -private: - friend class GoASTNode; - std::unique_ptr m_name_up; - std::unique_ptr m_type_up; - - GoASTTypeSpec(const GoASTTypeSpec &) = delete; - const GoASTTypeSpec &operator=(const GoASTTypeSpec &) = delete; -}; - -class GoASTTypeSwitchStmt : public GoASTStmt { -public: - GoASTTypeSwitchStmt(GoASTStmt *init, GoASTStmt *assign, GoASTBlockStmt *body) - : GoASTStmt(eTypeSwitchStmt), m_init_up(init), m_assign_up(assign), - m_body_up(body) {} - ~GoASTTypeSwitchStmt() override = default; - - const char *GetKindName() const override { return "TypeSwitchStmt"; } - - static bool classof(const GoASTNode *n) { - return n->GetKind() == eTypeSwitchStmt; - } - - const GoASTStmt *GetInit() const { return m_init_up.get(); } - void SetInit(GoASTStmt *init) { m_init_up.reset(init); } - - const GoASTStmt *GetAssign() const { return m_assign_up.get(); } - void SetAssign(GoASTStmt *assign) { m_assign_up.reset(assign); } - - const GoASTBlockStmt *GetBody() const { return m_body_up.get(); } - void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); } - -private: - friend class GoASTNode; - std::unique_ptr m_init_up; - std::unique_ptr m_assign_up; - std::unique_ptr m_body_up; - - GoASTTypeSwitchStmt(const GoASTTypeSwitchStmt &) = delete; - const GoASTTypeSwitchStmt &operator=(const GoASTTypeSwitchStmt &) = delete; -}; - -class GoASTUnaryExpr : public GoASTExpr { -public: - GoASTUnaryExpr(TokenType op, GoASTExpr *x) - : GoASTExpr(eUnaryExpr), m_op(op), m_x_up(x) {} - ~GoASTUnaryExpr() override = default; - - const char *GetKindName() const override { return "UnaryExpr"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eUnaryExpr; } - - TokenType GetOp() const { return m_op; } - void SetOp(TokenType op) { m_op = op; } - - const GoASTExpr *GetX() const { return m_x_up.get(); } - void SetX(GoASTExpr *x) { m_x_up.reset(x); } - -private: - friend class GoASTNode; - TokenType m_op; - std::unique_ptr m_x_up; - - GoASTUnaryExpr(const GoASTUnaryExpr &) = delete; - const GoASTUnaryExpr &operator=(const GoASTUnaryExpr &) = delete; -}; - -class GoASTValueSpec : public GoASTSpec { -public: - GoASTValueSpec() : GoASTSpec(eValueSpec) {} - ~GoASTValueSpec() override = default; - - const char *GetKindName() const override { return "ValueSpec"; } - - static bool classof(const GoASTNode *n) { return n->GetKind() == eValueSpec; } - - size_t NumNames() const { return m_names.size(); } - const GoASTIdent *GetNames(int i) const { return m_names[i].get(); } - void AddNames(GoASTIdent *names) { - m_names.push_back(std::unique_ptr(names)); - } - - const GoASTExpr *GetType() const { return m_type_up.get(); } - void SetType(GoASTExpr *type) { m_type_up.reset(type); } - - size_t NumValues() const { return m_values.size(); } - const GoASTExpr *GetValues(int i) const { return m_values[i].get(); } - void AddValues(GoASTExpr *values) { - m_values.push_back(std::unique_ptr(values)); - } - -private: - friend class GoASTNode; - std::vector> m_names; - std::unique_ptr m_type_up; - std::vector> m_values; - - GoASTValueSpec(const GoASTValueSpec &) = delete; - const GoASTValueSpec &operator=(const GoASTValueSpec &) = delete; -}; - -template R GoASTDecl::Visit(V *v) const { - switch (GetKind()) { - case eBadDecl: - return v->VisitBadDecl(llvm::cast(this)); - case eFuncDecl: - return v->VisitFuncDecl(llvm::cast(this)); - case eGenDecl: - return v->VisitGenDecl(llvm::cast(this)); - default: - assert(false && "Invalid kind"); - } -} - -template R GoASTExpr::Visit(V *v) const { - switch (GetKind()) { - case eArrayType: - return v->VisitArrayType(llvm::cast(this)); - case eBadExpr: - return v->VisitBadExpr(llvm::cast(this)); - case eBasicLit: - return v->VisitBasicLit(llvm::cast(this)); - case eBinaryExpr: - return v->VisitBinaryExpr(llvm::cast(this)); - case eIdent: - return v->VisitIdent(llvm::cast(this)); - case eCallExpr: - return v->VisitCallExpr(llvm::cast(this)); - case eChanType: - return v->VisitChanType(llvm::cast(this)); - case eCompositeLit: - return v->VisitCompositeLit(llvm::cast(this)); - case eEllipsis: - return v->VisitEllipsis(llvm::cast(this)); - case eFuncType: - return v->VisitFuncType(llvm::cast(this)); - case eFuncLit: - return v->VisitFuncLit(llvm::cast(this)); - case eIndexExpr: - return v->VisitIndexExpr(llvm::cast(this)); - case eInterfaceType: - return v->VisitInterfaceType(llvm::cast(this)); - case eKeyValueExpr: - return v->VisitKeyValueExpr(llvm::cast(this)); - case eMapType: - return v->VisitMapType(llvm::cast(this)); - case eParenExpr: - return v->VisitParenExpr(llvm::cast(this)); - case eSelectorExpr: - return v->VisitSelectorExpr(llvm::cast(this)); - case eSliceExpr: - return v->VisitSliceExpr(llvm::cast(this)); - case eStarExpr: - return v->VisitStarExpr(llvm::cast(this)); - case eStructType: - return v->VisitStructType(llvm::cast(this)); - case eTypeAssertExpr: - return v->VisitTypeAssertExpr(llvm::cast(this)); - case eUnaryExpr: - return v->VisitUnaryExpr(llvm::cast(this)); - default: - assert(false && "Invalid kind"); - return R(); - } -} - -template R GoASTSpec::Visit(V *v) const { - switch (GetKind()) { - case eImportSpec: - return v->VisitImportSpec(llvm::cast(this)); - case eTypeSpec: - return v->VisitTypeSpec(llvm::cast(this)); - case eValueSpec: - return v->VisitValueSpec(llvm::cast(this)); - default: - assert(false && "Invalid kind"); - } -} - -template R GoASTStmt::Visit(V *v) const { - switch (GetKind()) { - case eAssignStmt: - return v->VisitAssignStmt(llvm::cast(this)); - case eBadStmt: - return v->VisitBadStmt(llvm::cast(this)); - case eBlockStmt: - return v->VisitBlockStmt(llvm::cast(this)); - case eBranchStmt: - return v->VisitBranchStmt(llvm::cast(this)); - case eCaseClause: - return v->VisitCaseClause(llvm::cast(this)); - case eCommClause: - return v->VisitCommClause(llvm::cast(this)); - case eDeclStmt: - return v->VisitDeclStmt(llvm::cast(this)); - case eDeferStmt: - return v->VisitDeferStmt(llvm::cast(this)); - case eEmptyStmt: - return v->VisitEmptyStmt(llvm::cast(this)); - case eExprStmt: - return v->VisitExprStmt(llvm::cast(this)); - case eForStmt: - return v->VisitForStmt(llvm::cast(this)); - case eGoStmt: - return v->VisitGoStmt(llvm::cast(this)); - case eIfStmt: - return v->VisitIfStmt(llvm::cast(this)); - case eIncDecStmt: - return v->VisitIncDecStmt(llvm::cast(this)); - case eLabeledStmt: - return v->VisitLabeledStmt(llvm::cast(this)); - case eRangeStmt: - return v->VisitRangeStmt(llvm::cast(this)); - case eReturnStmt: - return v->VisitReturnStmt(llvm::cast(this)); - case eSelectStmt: - return v->VisitSelectStmt(llvm::cast(this)); - case eSendStmt: - return v->VisitSendStmt(llvm::cast(this)); - case eSwitchStmt: - return v->VisitSwitchStmt(llvm::cast(this)); - case eTypeSwitchStmt: - return v->VisitTypeSwitchStmt(llvm::cast(this)); - default: - assert(false && "Invalid kind"); - } -} - -template void GoASTNode::WalkChildren(V &v) { - switch (m_kind) { - - case eArrayType: { - GoASTArrayType *n = llvm::cast(this); - (void)n; - v(n->m_len_up.get()); - v(n->m_elt_up.get()); - return; - } - case eAssignStmt: { - GoASTAssignStmt *n = llvm::cast(this); - (void)n; - for (auto &e : n->m_lhs) { - v(e.get()); - } - for (auto &e : n->m_rhs) { - v(e.get()); - } - return; - } - case eBasicLit: { - GoASTBasicLit *n = llvm::cast(this); - (void)n; - return; - } - case eBinaryExpr: { - GoASTBinaryExpr *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - v(n->m_y_up.get()); - return; - } - case eBlockStmt: { - GoASTBlockStmt *n = llvm::cast(this); - (void)n; - for (auto &e : n->m_list) { - v(e.get()); - } - return; - } - case eIdent: { - GoASTIdent *n = llvm::cast(this); - (void)n; - return; - } - case eBranchStmt: { - GoASTBranchStmt *n = llvm::cast(this); - (void)n; - v(n->m_label_up.get()); - return; - } - case eCallExpr: { - GoASTCallExpr *n = llvm::cast(this); - (void)n; - v(n->m_fun_up.get()); - for (auto &e : n->m_args) { - v(e.get()); - } - return; - } - case eCaseClause: { - GoASTCaseClause *n = llvm::cast(this); - (void)n; - for (auto &e : n->m_list) { - v(e.get()); - } - for (auto &e : n->m_body) { - v(e.get()); - } - return; - } - case eChanType: { - GoASTChanType *n = llvm::cast(this); - (void)n; - v(n->m_value_up.get()); - return; - } - case eCommClause: { - GoASTCommClause *n = llvm::cast(this); - (void)n; - v(n->m_comm_up.get()); - for (auto &e : n->m_body) { - v(e.get()); - } - return; - } - case eCompositeLit: { - GoASTCompositeLit *n = llvm::cast(this); - (void)n; - v(n->m_type_up.get()); - for (auto &e : n->m_elts) { - v(e.get()); - } - return; - } - case eDeclStmt: { - GoASTDeclStmt *n = llvm::cast(this); - (void)n; - v(n->m_decl_up.get()); - return; - } - case eDeferStmt: { - GoASTDeferStmt *n = llvm::cast(this); - (void)n; - v(n->m_call_up.get()); - return; - } - case eEllipsis: { - GoASTEllipsis *n = llvm::cast(this); - (void)n; - v(n->m_elt_up.get()); - return; - } - case eExprStmt: { - GoASTExprStmt *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - return; - } - case eField: { - GoASTField *n = llvm::cast(this); - (void)n; - for (auto &e : n->m_names) { - v(e.get()); - } - v(n->m_type_up.get()); - v(n->m_tag_up.get()); - return; - } - case eFieldList: { - GoASTFieldList *n = llvm::cast(this); - (void)n; - for (auto &e : n->m_list) { - v(e.get()); - } - return; - } - case eForStmt: { - GoASTForStmt *n = llvm::cast(this); - (void)n; - v(n->m_init_up.get()); - v(n->m_cond_up.get()); - v(n->m_post_up.get()); - v(n->m_body_up.get()); - return; - } - case eFuncType: { - GoASTFuncType *n = llvm::cast(this); - (void)n; - v(n->m_params_up.get()); - v(n->m_results_up.get()); - return; - } - case eFuncDecl: { - GoASTFuncDecl *n = llvm::cast(this); - (void)n; - v(n->m_recv_up.get()); - v(n->m_name_up.get()); - v(n->m_type_up.get()); - v(n->m_body_up.get()); - return; - } - case eFuncLit: { - GoASTFuncLit *n = llvm::cast(this); - (void)n; - v(n->m_type_up.get()); - v(n->m_body_up.get()); - return; - } - case eGenDecl: { - GoASTGenDecl *n = llvm::cast(this); - (void)n; - for (auto &e : n->m_specs) { - v(e.get()); - } - return; - } - case eGoStmt: { - GoASTGoStmt *n = llvm::cast(this); - (void)n; - v(n->m_call_up.get()); - return; - } - case eIfStmt: { - GoASTIfStmt *n = llvm::cast(this); - (void)n; - v(n->m_init_up.get()); - v(n->m_cond_up.get()); - v(n->m_body_up.get()); - v(n->m_els_up.get()); - return; - } - case eImportSpec: { - GoASTImportSpec *n = llvm::cast(this); - (void)n; - v(n->m_name_up.get()); - v(n->m_path_up.get()); - return; - } - case eIncDecStmt: { - GoASTIncDecStmt *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - return; - } - case eIndexExpr: { - GoASTIndexExpr *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - v(n->m_index_up.get()); - return; - } - case eInterfaceType: { - GoASTInterfaceType *n = llvm::cast(this); - (void)n; - v(n->m_methods_up.get()); - return; - } - case eKeyValueExpr: { - GoASTKeyValueExpr *n = llvm::cast(this); - (void)n; - v(n->m_key_up.get()); - v(n->m_value_up.get()); - return; - } - case eLabeledStmt: { - GoASTLabeledStmt *n = llvm::cast(this); - (void)n; - v(n->m_label_up.get()); - v(n->m_stmt_up.get()); - return; - } - case eMapType: { - GoASTMapType *n = llvm::cast(this); - (void)n; - v(n->m_key_up.get()); - v(n->m_value_up.get()); - return; - } - case eParenExpr: { - GoASTParenExpr *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - return; - } - case eRangeStmt: { - GoASTRangeStmt *n = llvm::cast(this); - (void)n; - v(n->m_key_up.get()); - v(n->m_value_up.get()); - v(n->m_x_up.get()); - v(n->m_body_up.get()); - return; - } - case eReturnStmt: { - GoASTReturnStmt *n = llvm::cast(this); - (void)n; - for (auto &e : n->m_results) { - v(e.get()); - } - return; - } - case eSelectStmt: { - GoASTSelectStmt *n = llvm::cast(this); - (void)n; - v(n->m_body_up.get()); - return; - } - case eSelectorExpr: { - GoASTSelectorExpr *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - v(n->m_sel_up.get()); - return; - } - case eSendStmt: { - GoASTSendStmt *n = llvm::cast(this); - (void)n; - v(n->m_chan_up.get()); - v(n->m_value_up.get()); - return; - } - case eSliceExpr: { - GoASTSliceExpr *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - v(n->m_low_up.get()); - v(n->m_high_up.get()); - v(n->m_max_up.get()); - return; - } - case eStarExpr: { - GoASTStarExpr *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - return; - } - case eStructType: { - GoASTStructType *n = llvm::cast(this); - (void)n; - v(n->m_fields_up.get()); - return; - } - case eSwitchStmt: { - GoASTSwitchStmt *n = llvm::cast(this); - (void)n; - v(n->m_init_up.get()); - v(n->m_tag_up.get()); - v(n->m_body_up.get()); - return; - } - case eTypeAssertExpr: { - GoASTTypeAssertExpr *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - v(n->m_type_up.get()); - return; - } - case eTypeSpec: { - GoASTTypeSpec *n = llvm::cast(this); - (void)n; - v(n->m_name_up.get()); - v(n->m_type_up.get()); - return; - } - case eTypeSwitchStmt: { - GoASTTypeSwitchStmt *n = llvm::cast(this); - (void)n; - v(n->m_init_up.get()); - v(n->m_assign_up.get()); - v(n->m_body_up.get()); - return; - } - case eUnaryExpr: { - GoASTUnaryExpr *n = llvm::cast(this); - (void)n; - v(n->m_x_up.get()); - return; - } - case eValueSpec: { - GoASTValueSpec *n = llvm::cast(this); - (void)n; - for (auto &e : n->m_names) { - v(e.get()); - } - v(n->m_type_up.get()); - for (auto &e : n->m_values) { - v(e.get()); - } - return; - } - - case eEmptyStmt: - case eBadDecl: - case eBadExpr: - case eBadStmt: - break; - } -} - -} // namespace lldb_private - -#endif Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoLexer.h =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Go/GoLexer.h +++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoLexer.h @@ -1,181 +0,0 @@ -//===-- GoLexer.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_GoLexer_h -#define liblldb_GoLexer_h - -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringRef.h" - -namespace lldb_private { - -class GoLexer { -public: - explicit GoLexer(const char *src); - - enum TokenType { - TOK_EOF, - TOK_INVALID, - TOK_IDENTIFIER, - LIT_INTEGER, - LIT_FLOAT, - LIT_IMAGINARY, - LIT_RUNE, - LIT_STRING, - KEYWORD_BREAK, - KEYWORD_DEFAULT, - KEYWORD_FUNC, - KEYWORD_INTERFACE, - KEYWORD_SELECT, - KEYWORD_CASE, - KEYWORD_DEFER, - KEYWORD_GO, - KEYWORD_MAP, - KEYWORD_STRUCT, - KEYWORD_CHAN, - KEYWORD_ELSE, - KEYWORD_GOTO, - KEYWORD_PACKAGE, - KEYWORD_SWITCH, - KEYWORD_CONST, - KEYWORD_FALLTHROUGH, - KEYWORD_IF, - KEYWORD_RANGE, - KEYWORD_TYPE, - KEYWORD_CONTINUE, - KEYWORD_FOR, - KEYWORD_IMPORT, - KEYWORD_RETURN, - KEYWORD_VAR, - OP_PLUS, - OP_MINUS, - OP_STAR, - OP_SLASH, - OP_PERCENT, - OP_AMP, - OP_PIPE, - OP_CARET, - OP_LSHIFT, - OP_RSHIFT, - OP_AMP_CARET, - OP_PLUS_EQ, - OP_MINUS_EQ, - OP_STAR_EQ, - OP_SLASH_EQ, - OP_PERCENT_EQ, - OP_AMP_EQ, - OP_PIPE_EQ, - OP_CARET_EQ, - OP_LSHIFT_EQ, - OP_RSHIFT_EQ, - OP_AMP_CARET_EQ, - OP_AMP_AMP, - OP_PIPE_PIPE, - OP_LT_MINUS, - OP_PLUS_PLUS, - OP_MINUS_MINUS, - OP_EQ_EQ, - OP_LT, - OP_GT, - OP_EQ, - OP_BANG, - OP_BANG_EQ, - OP_LT_EQ, - OP_GT_EQ, - OP_COLON_EQ, - OP_DOTS, - OP_LPAREN, - OP_LBRACK, - OP_LBRACE, - OP_COMMA, - OP_DOT, - OP_RPAREN, - OP_RBRACK, - OP_RBRACE, - OP_SEMICOLON, - OP_COLON, - }; - - struct Token { - explicit Token(TokenType t, llvm::StringRef text) - : m_type(t), m_value(text) {} - TokenType m_type; - llvm::StringRef m_value; - }; - - const Token &Lex(); - - size_t BytesRemaining() const { return m_end - m_src; } - llvm::StringRef GetString(int len) const { - return llvm::StringRef(m_src, len); - } - - static TokenType LookupKeyword(llvm::StringRef id); - static llvm::StringRef LookupToken(TokenType t); - -private: - bool IsDecimal(char c) { return c >= '0' && c <= '9'; } - bool IsHexChar(char c) { - if (c >= '0' && c <= '9') - return true; - if (c >= 'A' && c <= 'F') - return true; - if (c >= 'a' && c <= 'f') - return true; - return false; - } - bool IsLetterOrDigit(char c) { - if (c >= 'a' && c <= 'z') - return true; - if (c >= 'A' && c <= 'Z') - return true; - if (c == '_') - return true; - if (c >= '0' && c <= '9') - return true; - // Treat all non-ascii chars as letters for simplicity. - return 0 != (c & 0x80); - } - bool IsWhitespace(char c) { - switch (c) { - case ' ': - case '\t': - case '\r': - return true; - } - return false; - } - - bool SkipWhitespace(); - bool SkipComment(); - - TokenType InternalLex(bool newline); - - TokenType DoOperator(); - - TokenType DoIdent(); - - TokenType DoNumber(); - - TokenType DoRune(); - - TokenType DoString(); - - static llvm::StringMap *InitKeywords(); - - static llvm::StringMap *m_keywords; - - const char *m_src; - const char *m_end; - Token m_last_token; -}; - -} // namespace lldb_private - -#endif Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoLexer.cpp =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Go/GoLexer.cpp +++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoLexer.cpp @@ -1,350 +0,0 @@ -//===-- GoLexer.cpp ---------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include - -#include "GoLexer.h" - -using namespace lldb_private; - -llvm::StringMap *GoLexer::m_keywords; - -GoLexer::GoLexer(const char *src) - : m_src(src), m_end(src + strlen(src)), m_last_token(TOK_INVALID, "") {} - -bool GoLexer::SkipWhitespace() { - bool saw_newline = false; - for (; m_src < m_end; ++m_src) { - if (*m_src == '\n') - saw_newline = true; - if (*m_src == '/' && !SkipComment()) - return saw_newline; - else if (!IsWhitespace(*m_src)) - return saw_newline; - } - return saw_newline; -} - -bool GoLexer::SkipComment() { - if (m_src[0] == '/' && m_src[1] == '/') { - for (const char *c = m_src + 2; c < m_end; ++c) { - if (*c == '\n') { - m_src = c - 1; - return true; - } - } - return true; - } else if (m_src[0] == '/' && m_src[1] == '*') { - for (const char *c = m_src + 2; c < m_end; ++c) { - if (c[0] == '*' && c[1] == '/') { - m_src = c + 1; - return true; - } - } - } - return false; -} - -const GoLexer::Token &GoLexer::Lex() { - bool newline = SkipWhitespace(); - const char *start = m_src; - m_last_token.m_type = InternalLex(newline); - m_last_token.m_value = llvm::StringRef(start, m_src - start); - return m_last_token; -} - -GoLexer::TokenType GoLexer::InternalLex(bool newline) { - if (m_src >= m_end) { - return TOK_EOF; - } - if (newline) { - switch (m_last_token.m_type) { - case TOK_IDENTIFIER: - case LIT_FLOAT: - case LIT_IMAGINARY: - case LIT_INTEGER: - case LIT_RUNE: - case LIT_STRING: - case KEYWORD_BREAK: - case KEYWORD_CONTINUE: - case KEYWORD_FALLTHROUGH: - case KEYWORD_RETURN: - case OP_PLUS_PLUS: - case OP_MINUS_MINUS: - case OP_RPAREN: - case OP_RBRACK: - case OP_RBRACE: - return OP_SEMICOLON; - default: - break; - } - } - char c = *m_src; - switch (c) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - return DoNumber(); - case '+': - case '-': - case '*': - case '/': - case '%': - case '&': - case '|': - case '^': - case '<': - case '>': - case '!': - case ':': - case ';': - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': - case ',': - case '=': - return DoOperator(); - case '.': - if (IsDecimal(m_src[1])) - return DoNumber(); - return DoOperator(); - case '$': - // For lldb persistent vars. - return DoIdent(); - case '"': - case '`': - return DoString(); - case '\'': - return DoRune(); - default: - break; - } - if (IsLetterOrDigit(c)) - return DoIdent(); - ++m_src; - return TOK_INVALID; -} - -GoLexer::TokenType GoLexer::DoOperator() { - TokenType t = TOK_INVALID; - if (m_end - m_src > 2) { - t = LookupKeyword(llvm::StringRef(m_src, 3)); - if (t != TOK_INVALID) - m_src += 3; - } - if (t == TOK_INVALID && m_end - m_src > 1) { - t = LookupKeyword(llvm::StringRef(m_src, 2)); - if (t != TOK_INVALID) - m_src += 2; - } - if (t == TOK_INVALID) { - t = LookupKeyword(llvm::StringRef(m_src, 1)); - ++m_src; - } - return t; -} - -GoLexer::TokenType GoLexer::DoIdent() { - const char *start = m_src++; - while (m_src < m_end && IsLetterOrDigit(*m_src)) { - ++m_src; - } - TokenType kw = LookupKeyword(llvm::StringRef(start, m_src - start)); - if (kw != TOK_INVALID) - return kw; - return TOK_IDENTIFIER; -} - -GoLexer::TokenType GoLexer::DoNumber() { - if (m_src[0] == '0' && (m_src[1] == 'x' || m_src[1] == 'X')) { - m_src += 2; - while (IsHexChar(*m_src)) - ++m_src; - return LIT_INTEGER; - } - bool dot_ok = true; - bool e_ok = true; - while (true) { - while (IsDecimal(*m_src)) - ++m_src; - switch (*m_src) { - case 'i': - ++m_src; - return LIT_IMAGINARY; - case '.': - if (!dot_ok) - return LIT_FLOAT; - ++m_src; - dot_ok = false; - break; - case 'e': - case 'E': - if (!e_ok) - return LIT_FLOAT; - dot_ok = e_ok = false; - ++m_src; - if (*m_src == '+' || *m_src == '-') - ++m_src; - break; - default: - if (dot_ok) - return LIT_INTEGER; - return LIT_FLOAT; - } - } -} - -GoLexer::TokenType GoLexer::DoRune() { - while (++m_src < m_end) { - switch (*m_src) { - case '\'': - ++m_src; - return LIT_RUNE; - case '\n': - return TOK_INVALID; - case '\\': - if (m_src[1] == '\n') - return TOK_INVALID; - ++m_src; - } - } - return TOK_INVALID; -} - -GoLexer::TokenType GoLexer::DoString() { - if (*m_src == '`') { - while (++m_src < m_end) { - if (*m_src == '`') { - ++m_src; - return LIT_STRING; - } - } - return TOK_INVALID; - } - while (++m_src < m_end) { - switch (*m_src) { - case '"': - ++m_src; - return LIT_STRING; - case '\n': - return TOK_INVALID; - case '\\': - if (m_src[1] == '\n') - return TOK_INVALID; - ++m_src; - } - } - return TOK_INVALID; -} - -GoLexer::TokenType GoLexer::LookupKeyword(llvm::StringRef id) { - if (m_keywords == nullptr) - m_keywords = InitKeywords(); - const auto &it = m_keywords->find(id); - if (it == m_keywords->end()) - return TOK_INVALID; - return it->second; -} - -llvm::StringRef GoLexer::LookupToken(TokenType t) { - if (m_keywords == nullptr) - m_keywords = InitKeywords(); - for (const auto &e : *m_keywords) { - if (e.getValue() == t) - return e.getKey(); - } - return ""; -} - -llvm::StringMap *GoLexer::InitKeywords() { - auto &result = *new llvm::StringMap(128); - result["break"] = KEYWORD_BREAK; - result["default"] = KEYWORD_DEFAULT; - result["func"] = KEYWORD_FUNC; - result["interface"] = KEYWORD_INTERFACE; - result["select"] = KEYWORD_SELECT; - result["case"] = KEYWORD_CASE; - result["defer"] = KEYWORD_DEFER; - result["go"] = KEYWORD_GO; - result["map"] = KEYWORD_MAP; - result["struct"] = KEYWORD_STRUCT; - result["chan"] = KEYWORD_CHAN; - result["else"] = KEYWORD_ELSE; - result["goto"] = KEYWORD_GOTO; - result["package"] = KEYWORD_PACKAGE; - result["switch"] = KEYWORD_SWITCH; - result["const"] = KEYWORD_CONST; - result["fallthrough"] = KEYWORD_FALLTHROUGH; - result["if"] = KEYWORD_IF; - result["range"] = KEYWORD_RANGE; - result["type"] = KEYWORD_TYPE; - result["continue"] = KEYWORD_CONTINUE; - result["for"] = KEYWORD_FOR; - result["import"] = KEYWORD_IMPORT; - result["return"] = KEYWORD_RETURN; - result["var"] = KEYWORD_VAR; - result["+"] = OP_PLUS; - result["-"] = OP_MINUS; - result["*"] = OP_STAR; - result["/"] = OP_SLASH; - result["%"] = OP_PERCENT; - result["&"] = OP_AMP; - result["|"] = OP_PIPE; - result["^"] = OP_CARET; - result["<<"] = OP_LSHIFT; - result[">>"] = OP_RSHIFT; - result["&^"] = OP_AMP_CARET; - result["+="] = OP_PLUS_EQ; - result["-="] = OP_MINUS_EQ; - result["*="] = OP_STAR_EQ; - result["/="] = OP_SLASH_EQ; - result["%="] = OP_PERCENT_EQ; - result["&="] = OP_AMP_EQ; - result["|="] = OP_PIPE_EQ; - result["^="] = OP_CARET_EQ; - result["<<="] = OP_LSHIFT_EQ; - result[">>="] = OP_RSHIFT_EQ; - result["&^="] = OP_AMP_CARET_EQ; - result["&&"] = OP_AMP_AMP; - result["||"] = OP_PIPE_PIPE; - result["<-"] = OP_LT_MINUS; - result["++"] = OP_PLUS_PLUS; - result["--"] = OP_MINUS_MINUS; - result["=="] = OP_EQ_EQ; - result["<"] = OP_LT; - result[">"] = OP_GT; - result["="] = OP_EQ; - result["!"] = OP_BANG; - result["!="] = OP_BANG_EQ; - result["<="] = OP_LT_EQ; - result[">="] = OP_GT_EQ; - result[":="] = OP_COLON_EQ; - result["..."] = OP_DOTS; - result["("] = OP_LPAREN; - result["["] = OP_LBRACK; - result["{"] = OP_LBRACE; - result[","] = OP_COMMA; - result["."] = OP_DOT; - result[")"] = OP_RPAREN; - result["]"] = OP_RBRACK; - result["}"] = OP_RBRACE; - result[";"] = OP_SEMICOLON; - result[":"] = OP_COLON; - return &result; -} Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.h =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.h +++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.h @@ -1,145 +0,0 @@ -//===-- GoParser.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_GoParser_h -#define liblldb_GoParser_h - -#include "Plugins/ExpressionParser/Go/GoAST.h" -#include "Plugins/ExpressionParser/Go/GoLexer.h" -#include "lldb/lldb-private.h" - -namespace lldb_private { -class GoParser { -public: - explicit GoParser(const char *src); - - GoASTStmt *Statement(); - - GoASTStmt *GoStmt(); - GoASTStmt *ReturnStmt(); - GoASTStmt *BranchStmt(); - GoASTStmt *EmptyStmt(); - GoASTStmt *ExpressionStmt(GoASTExpr *e); - GoASTStmt *IncDecStmt(GoASTExpr *e); - GoASTStmt *Assignment(GoASTExpr *e); - GoASTBlockStmt *Block(); - - GoASTExpr *MoreExpressionList(); // ["," Expression] - GoASTIdent *MoreIdentifierList(); // ["," Identifier] - - GoASTExpr *Expression(); - GoASTExpr *UnaryExpr(); - GoASTExpr *OrExpr(); - GoASTExpr *AndExpr(); - GoASTExpr *RelExpr(); - GoASTExpr *AddExpr(); - GoASTExpr *MulExpr(); - GoASTExpr *PrimaryExpr(); - GoASTExpr *Operand(); - GoASTExpr *Conversion(); - - GoASTExpr *Selector(GoASTExpr *e); - GoASTExpr *IndexOrSlice(GoASTExpr *e); - GoASTExpr *TypeAssertion(GoASTExpr *e); - GoASTExpr *Arguments(GoASTExpr *e); - - GoASTExpr *Type(); - GoASTExpr *Type2(); - GoASTExpr *ArrayOrSliceType(bool allowEllipsis); - GoASTExpr *StructType(); - GoASTExpr *FunctionType(); - GoASTExpr *InterfaceType(); - GoASTExpr *MapType(); - GoASTExpr *ChanType(); - GoASTExpr *ChanType2(); - - GoASTExpr *Name(); - GoASTExpr *QualifiedIdent(GoASTIdent *p); - GoASTIdent *Identifier(); - - GoASTField *FieldDecl(); - GoASTExpr *AnonymousFieldType(); - GoASTExpr *FieldNamesAndType(GoASTField *f); - - GoASTFieldList *Params(); - GoASTField *ParamDecl(); - GoASTExpr *ParamType(); - GoASTFuncType *Signature(); - GoASTExpr *CompositeLit(); - GoASTExpr *FunctionLit(); - GoASTExpr *Element(); - GoASTCompositeLit *LiteralValue(); - - bool Failed() const { return m_failed; } - bool AtEOF() const { - return m_lexer.BytesRemaining() == 0 && m_pos == m_tokens.size(); - } - - void GetError(Status &error); - -private: - class Rule; - friend class Rule; - - std::nullptr_t syntaxerror() { - m_failed = true; - return nullptr; - } - GoLexer::Token &next() { - if (m_pos >= m_tokens.size()) { - if (m_pos != 0 && (m_tokens.back().m_type == GoLexer::TOK_EOF || - m_tokens.back().m_type == GoLexer::TOK_INVALID)) - return m_tokens.back(); - m_pos = m_tokens.size(); - m_tokens.push_back(m_lexer.Lex()); - } - return m_tokens[m_pos++]; - } - GoLexer::TokenType peek() { - GoLexer::Token &tok = next(); - --m_pos; - return tok.m_type; - } - GoLexer::Token *match(GoLexer::TokenType t) { - GoLexer::Token &tok = next(); - if (tok.m_type == t) - return &tok; - --m_pos; - m_last_tok = t; - return nullptr; - } - GoLexer::Token *mustMatch(GoLexer::TokenType t) { - GoLexer::Token *tok = match(t); - if (tok) - return tok; - return syntaxerror(); - } - bool Semicolon(); - - GoASTStmt *FinishStmt(GoASTStmt *s) { - if (!Semicolon()) - m_failed = true; - return s; - } - - llvm::StringRef CopyString(llvm::StringRef s); - - GoLexer m_lexer; - std::vector m_tokens; - size_t m_pos; - llvm::StringRef m_error; - llvm::StringRef m_last; - GoLexer::TokenType m_last_tok; - llvm::StringMap m_strings; - bool m_failed; -}; -} - -#endif Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.cpp =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.cpp +++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoParser.cpp @@ -1,886 +0,0 @@ -//===-- GoParser.cpp ---------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include - -#include "GoParser.h" - -#include "Plugins/ExpressionParser/Go/GoAST.h" -#include "lldb/Utility/Status.h" -#include "llvm/ADT/SmallString.h" - -using namespace lldb_private; -using namespace lldb; - -namespace { -llvm::StringRef DescribeToken(GoLexer::TokenType t) { - switch (t) { - case GoLexer::TOK_EOF: - return ""; - case GoLexer::TOK_IDENTIFIER: - return "identifier"; - case GoLexer::LIT_FLOAT: - return "float"; - case GoLexer::LIT_IMAGINARY: - return "imaginary"; - case GoLexer::LIT_INTEGER: - return "integer"; - case GoLexer::LIT_RUNE: - return "rune"; - case GoLexer::LIT_STRING: - return "string"; - default: - return GoLexer::LookupToken(t); - } -} -} // namespace - -class GoParser::Rule { -public: - Rule(llvm::StringRef name, GoParser *p) - : m_name(name), m_parser(p), m_pos(p->m_pos) {} - - std::nullptr_t error() { - if (!m_parser->m_failed) { - // Set m_error in case this is the top level. - if (m_parser->m_last_tok == GoLexer::TOK_INVALID) - m_parser->m_error = m_parser->m_last; - else - m_parser->m_error = DescribeToken(m_parser->m_last_tok); - // And set m_last in case it isn't. - m_parser->m_last = m_name; - m_parser->m_last_tok = GoLexer::TOK_INVALID; - m_parser->m_pos = m_pos; - } - return nullptr; - } - -private: - llvm::StringRef m_name; - GoParser *m_parser; - size_t m_pos; -}; - -GoParser::GoParser(const char *src) - : m_lexer(src), m_pos(0), m_last_tok(GoLexer::TOK_INVALID), - m_failed(false) {} - -GoASTStmt *GoParser::Statement() { - Rule r("Statement", this); - GoLexer::TokenType t = peek(); - GoASTStmt *ret = nullptr; - switch (t) { - case GoLexer::TOK_EOF: - case GoLexer::OP_SEMICOLON: - case GoLexer::OP_RPAREN: - case GoLexer::OP_RBRACE: - case GoLexer::TOK_INVALID: - return EmptyStmt(); - case GoLexer::OP_LBRACE: - return Block(); - - /* TODO: -case GoLexer::KEYWORD_GO: - return GoStmt(); -case GoLexer::KEYWORD_RETURN: - return ReturnStmt(); -case GoLexer::KEYWORD_BREAK: -case GoLexer::KEYWORD_CONTINUE: -case GoLexer::KEYWORD_GOTO: -case GoLexer::KEYWORD_FALLTHROUGH: - return BranchStmt(); -case GoLexer::KEYWORD_IF: - return IfStmt(); -case GoLexer::KEYWORD_SWITCH: - return SwitchStmt(); -case GoLexer::KEYWORD_SELECT: - return SelectStmt(); -case GoLexer::KEYWORD_FOR: - return ForStmt(); -case GoLexer::KEYWORD_DEFER: - return DeferStmt(); -case GoLexer::KEYWORD_CONST: -case GoLexer::KEYWORD_TYPE: -case GoLexer::KEYWORD_VAR: - return DeclStmt(); -case GoLexer::TOK_IDENTIFIER: - if ((ret = LabeledStmt()) || - (ret = ShortVarDecl())) - { - return ret; - } -*/ - default: - break; - } - GoASTExpr *expr = Expression(); - if (expr == nullptr) - return r.error(); - if (/*(ret = SendStmt(expr)) ||*/ - (ret = IncDecStmt(expr)) || (ret = Assignment(expr)) || - (ret = ExpressionStmt(expr))) { - return ret; - } - delete expr; - return r.error(); -} - -GoASTStmt *GoParser::ExpressionStmt(GoASTExpr *e) { - if (Semicolon()) - return new GoASTExprStmt(e); - return nullptr; -} - -GoASTStmt *GoParser::IncDecStmt(GoASTExpr *e) { - Rule r("IncDecStmt", this); - if (match(GoLexer::OP_PLUS_PLUS)) - return Semicolon() ? new GoASTIncDecStmt(e, GoLexer::OP_PLUS_PLUS) - : r.error(); - if (match(GoLexer::OP_MINUS_MINUS)) - return Semicolon() ? new GoASTIncDecStmt(e, GoLexer::OP_MINUS_MINUS) - : r.error(); - return nullptr; -} - -GoASTStmt *GoParser::Assignment(lldb_private::GoASTExpr *e) { - Rule r("Assignment", this); - std::vector> lhs; - for (GoASTExpr *l = MoreExpressionList(); l; l = MoreExpressionList()) - lhs.push_back(std::unique_ptr(l)); - switch (peek()) { - case GoLexer::OP_EQ: - case GoLexer::OP_PLUS_EQ: - case GoLexer::OP_MINUS_EQ: - case GoLexer::OP_PIPE_EQ: - case GoLexer::OP_CARET_EQ: - case GoLexer::OP_STAR_EQ: - case GoLexer::OP_SLASH_EQ: - case GoLexer::OP_PERCENT_EQ: - case GoLexer::OP_LSHIFT_EQ: - case GoLexer::OP_RSHIFT_EQ: - case GoLexer::OP_AMP_EQ: - case GoLexer::OP_AMP_CARET_EQ: - break; - default: - return r.error(); - } - // We don't want to own e until we know this is an assignment. - std::unique_ptr stmt(new GoASTAssignStmt(false)); - stmt->AddLhs(e); - for (auto &l : lhs) - stmt->AddLhs(l.release()); - for (GoASTExpr *r = Expression(); r; r = MoreExpressionList()) - stmt->AddRhs(r); - if (!Semicolon() || stmt->NumRhs() == 0) - return new GoASTBadStmt; - return stmt.release(); -} - -GoASTStmt *GoParser::EmptyStmt() { - if (match(GoLexer::TOK_EOF)) - return nullptr; - if (Semicolon()) - return new GoASTEmptyStmt; - return nullptr; -} - -GoASTStmt *GoParser::GoStmt() { - if (match(GoLexer::KEYWORD_GO)) { - if (GoASTCallExpr *e = - llvm::dyn_cast_or_null(Expression())) { - return FinishStmt(new GoASTGoStmt(e)); - } - m_last = "call expression"; - m_failed = true; - return new GoASTBadStmt(); - } - return nullptr; -} - -GoASTStmt *GoParser::ReturnStmt() { - if (match(GoLexer::KEYWORD_RETURN)) { - std::unique_ptr r(new GoASTReturnStmt()); - for (GoASTExpr *e = Expression(); e; e = MoreExpressionList()) - r->AddResults(e); - return FinishStmt(r.release()); - } - return nullptr; -} - -GoASTStmt *GoParser::BranchStmt() { - GoLexer::Token *tok; - if ((tok = match(GoLexer::KEYWORD_BREAK)) || - (tok = match(GoLexer::KEYWORD_CONTINUE)) || - (tok = match(GoLexer::KEYWORD_GOTO))) { - auto *e = Identifier(); - if (tok->m_type == GoLexer::KEYWORD_GOTO && !e) - return syntaxerror(); - return FinishStmt(new GoASTBranchStmt(e, tok->m_type)); - } - if ((tok = match(GoLexer::KEYWORD_FALLTHROUGH))) - return FinishStmt(new GoASTBranchStmt(nullptr, tok->m_type)); - - return nullptr; -} - -GoASTIdent *GoParser::Identifier() { - if (auto *tok = match(GoLexer::TOK_IDENTIFIER)) - return new GoASTIdent(*tok); - return nullptr; -} - -GoASTExpr *GoParser::MoreExpressionList() { - if (match(GoLexer::OP_COMMA)) { - auto *e = Expression(); - if (!e) - return syntaxerror(); - return e; - } - return nullptr; -} - -GoASTIdent *GoParser::MoreIdentifierList() { - if (match(GoLexer::OP_COMMA)) { - auto *i = Identifier(); - if (!i) - return syntaxerror(); - return i; - } - return nullptr; -} - -GoASTExpr *GoParser::Expression() { - Rule r("Expression", this); - if (GoASTExpr *ret = OrExpr()) - return ret; - return r.error(); -} - -GoASTExpr *GoParser::UnaryExpr() { - switch (peek()) { - case GoLexer::OP_PLUS: - case GoLexer::OP_MINUS: - case GoLexer::OP_BANG: - case GoLexer::OP_CARET: - case GoLexer::OP_STAR: - case GoLexer::OP_AMP: - case GoLexer::OP_LT_MINUS: { - const GoLexer::Token t = next(); - if (GoASTExpr *e = UnaryExpr()) { - if (t.m_type == GoLexer::OP_STAR) - return new GoASTStarExpr(e); - else - return new GoASTUnaryExpr(t.m_type, e); - } - return syntaxerror(); - } - default: - return PrimaryExpr(); - } -} - -GoASTExpr *GoParser::OrExpr() { - std::unique_ptr l(AndExpr()); - if (l) { - while (match(GoLexer::OP_PIPE_PIPE)) { - GoASTExpr *r = AndExpr(); - if (r) - l.reset(new GoASTBinaryExpr(l.release(), r, GoLexer::OP_PIPE_PIPE)); - else - return syntaxerror(); - } - return l.release(); - } - return nullptr; -} - -GoASTExpr *GoParser::AndExpr() { - std::unique_ptr l(RelExpr()); - if (l) { - while (match(GoLexer::OP_AMP_AMP)) { - GoASTExpr *r = RelExpr(); - if (r) - l.reset(new GoASTBinaryExpr(l.release(), r, GoLexer::OP_AMP_AMP)); - else - return syntaxerror(); - } - return l.release(); - } - return nullptr; -} - -GoASTExpr *GoParser::RelExpr() { - std::unique_ptr l(AddExpr()); - if (l) { - for (GoLexer::Token *t; - (t = match(GoLexer::OP_EQ_EQ)) || (t = match(GoLexer::OP_BANG_EQ)) || - (t = match(GoLexer::OP_LT)) || (t = match(GoLexer::OP_LT_EQ)) || - (t = match(GoLexer::OP_GT)) || (t = match(GoLexer::OP_GT_EQ));) { - GoLexer::TokenType op = t->m_type; - GoASTExpr *r = AddExpr(); - if (r) - l.reset(new GoASTBinaryExpr(l.release(), r, op)); - else - return syntaxerror(); - } - return l.release(); - } - return nullptr; -} - -GoASTExpr *GoParser::AddExpr() { - std::unique_ptr l(MulExpr()); - if (l) { - for (GoLexer::Token *t; - (t = match(GoLexer::OP_PLUS)) || (t = match(GoLexer::OP_MINUS)) || - (t = match(GoLexer::OP_PIPE)) || (t = match(GoLexer::OP_CARET));) { - GoLexer::TokenType op = t->m_type; - GoASTExpr *r = MulExpr(); - if (r) - l.reset(new GoASTBinaryExpr(l.release(), r, op)); - else - return syntaxerror(); - } - return l.release(); - } - return nullptr; -} - -GoASTExpr *GoParser::MulExpr() { - std::unique_ptr l(UnaryExpr()); - if (l) { - for (GoLexer::Token *t; - (t = match(GoLexer::OP_STAR)) || (t = match(GoLexer::OP_SLASH)) || - (t = match(GoLexer::OP_PERCENT)) || (t = match(GoLexer::OP_LSHIFT)) || - (t = match(GoLexer::OP_RSHIFT)) || (t = match(GoLexer::OP_AMP)) || - (t = match(GoLexer::OP_AMP_CARET));) { - GoLexer::TokenType op = t->m_type; - GoASTExpr *r = UnaryExpr(); - if (r) - l.reset(new GoASTBinaryExpr(l.release(), r, op)); - else - return syntaxerror(); - } - return l.release(); - } - return nullptr; -} - -GoASTExpr *GoParser::PrimaryExpr() { - GoASTExpr *l; - GoASTExpr *r; - (l = Conversion()) || (l = Operand()); - if (!l) - return nullptr; - while ((r = Selector(l)) || (r = IndexOrSlice(l)) || (r = TypeAssertion(l)) || - (r = Arguments(l))) { - l = r; - } - return l; -} - -GoASTExpr *GoParser::Operand() { - GoLexer::Token *lit; - if ((lit = match(GoLexer::LIT_INTEGER)) || - (lit = match(GoLexer::LIT_FLOAT)) || - (lit = match(GoLexer::LIT_IMAGINARY)) || - (lit = match(GoLexer::LIT_RUNE)) || (lit = match(GoLexer::LIT_STRING))) - return new GoASTBasicLit(*lit); - if (match(GoLexer::OP_LPAREN)) { - GoASTExpr *e; - if (!((e = Expression()) && match(GoLexer::OP_RPAREN))) - return syntaxerror(); - return e; - } - // MethodExpr should be handled by Selector - if (GoASTExpr *e = CompositeLit()) - return e; - if (GoASTExpr *n = Name()) - return n; - return FunctionLit(); -} - -GoASTExpr *GoParser::FunctionLit() { - if (!match(GoLexer::KEYWORD_FUNC)) - return nullptr; - auto *sig = Signature(); - if (!sig) - return syntaxerror(); - auto *body = Block(); - if (!body) { - delete sig; - return syntaxerror(); - } - return new GoASTFuncLit(sig, body); -} - -GoASTBlockStmt *GoParser::Block() { - if (!match(GoLexer::OP_LBRACE)) - return nullptr; - std::unique_ptr block(new GoASTBlockStmt); - for (auto *s = Statement(); s; s = Statement()) - block->AddList(s); - if (!match(GoLexer::OP_RBRACE)) - return syntaxerror(); - return block.release(); -} - -GoASTExpr *GoParser::CompositeLit() { - Rule r("CompositeLit", this); - GoASTExpr *type; - (type = StructType()) || (type = ArrayOrSliceType(true)) || - (type = MapType()) || (type = Name()); - if (!type) - return r.error(); - GoASTCompositeLit *lit = LiteralValue(); - if (!lit) { - delete type; - return r.error(); - } - lit->SetType(type); - return lit; -} - -GoASTCompositeLit *GoParser::LiteralValue() { - if (!match(GoLexer::OP_LBRACE)) - return nullptr; - std::unique_ptr lit(new GoASTCompositeLit); - for (GoASTExpr *e = Element(); e; e = Element()) { - lit->AddElts(e); - if (!match(GoLexer::OP_COMMA)) - break; - } - if (!mustMatch(GoLexer::OP_RBRACE)) - return nullptr; - return lit.release(); -} - -GoASTExpr *GoParser::Element() { - GoASTExpr *key; - if (!((key = Expression()) || (key = LiteralValue()))) - return nullptr; - if (!match(GoLexer::OP_COLON)) - return key; - GoASTExpr *value; - if ((value = Expression()) || (value = LiteralValue())) - return new GoASTKeyValueExpr(key, value); - delete key; - return syntaxerror(); -} - -GoASTExpr *GoParser::Selector(GoASTExpr *e) { - Rule r("Selector", this); - if (match(GoLexer::OP_DOT)) { - if (auto *name = Identifier()) - return new GoASTSelectorExpr(e, name); - } - return r.error(); -} - -GoASTExpr *GoParser::IndexOrSlice(GoASTExpr *e) { - Rule r("IndexOrSlice", this); - if (match(GoLexer::OP_LBRACK)) { - std::unique_ptr i1(Expression()), i2, i3; - bool slice = false; - if (match(GoLexer::OP_COLON)) { - slice = true; - i2.reset(Expression()); - if (i2 && match(GoLexer::OP_COLON)) { - i3.reset(Expression()); - if (!i3) - return syntaxerror(); - } - } - if (!(slice || i1)) - return syntaxerror(); - if (!mustMatch(GoLexer::OP_RBRACK)) - return nullptr; - if (slice) { - bool slice3 = i3.get(); - return new GoASTSliceExpr(e, i1.release(), i2.release(), i3.release(), - slice3); - } - return new GoASTIndexExpr(e, i1.release()); - } - return r.error(); -} - -GoASTExpr *GoParser::TypeAssertion(GoASTExpr *e) { - Rule r("TypeAssertion", this); - if (match(GoLexer::OP_DOT) && match(GoLexer::OP_LPAREN)) { - if (auto *t = Type()) { - if (!mustMatch(GoLexer::OP_RPAREN)) - return nullptr; - return new GoASTTypeAssertExpr(e, t); - } - return syntaxerror(); - } - return r.error(); -} - -GoASTExpr *GoParser::Arguments(GoASTExpr *e) { - if (match(GoLexer::OP_LPAREN)) { - std::unique_ptr call(new GoASTCallExpr(false)); - GoASTExpr *arg; - // ( ExpressionList | Type [ "," ExpressionList ] ) - for ((arg = Expression()) || (arg = Type()); arg; - arg = MoreExpressionList()) { - call->AddArgs(arg); - } - if (match(GoLexer::OP_DOTS)) - call->SetEllipsis(true); - - // Eat trailing comma - match(GoLexer::OP_COMMA); - - if (!mustMatch(GoLexer::OP_RPAREN)) - return nullptr; - call->SetFun(e); - return call.release(); - } - return nullptr; -} - -GoASTExpr *GoParser::Conversion() { - Rule r("Conversion", this); - if (GoASTExpr *t = Type2()) { - std::unique_ptr owner(t); - if (match(GoLexer::OP_LPAREN)) { - GoASTExpr *v = Expression(); - if (!v) - return syntaxerror(); - match(GoLexer::OP_COMMA); - if (!mustMatch(GoLexer::OP_RPAREN)) - return r.error(); - GoASTCallExpr *call = new GoASTCallExpr(false); - call->SetFun(t); - owner.release(); - call->AddArgs(v); - return call; - } - } - return r.error(); -} - -GoASTExpr *GoParser::Type2() { - switch (peek()) { - case GoLexer::OP_LBRACK: - return ArrayOrSliceType(false); - case GoLexer::KEYWORD_STRUCT: - return StructType(); - case GoLexer::KEYWORD_FUNC: - return FunctionType(); - case GoLexer::KEYWORD_INTERFACE: - return InterfaceType(); - case GoLexer::KEYWORD_MAP: - return MapType(); - case GoLexer::KEYWORD_CHAN: - return ChanType2(); - default: - return nullptr; - } -} - -GoASTExpr *GoParser::ArrayOrSliceType(bool allowEllipsis) { - Rule r("ArrayType", this); - if (match(GoLexer::OP_LBRACK)) { - std::unique_ptr len; - if (allowEllipsis && match(GoLexer::OP_DOTS)) { - len.reset(new GoASTEllipsis(nullptr)); - } else { - len.reset(Expression()); - } - - if (!match(GoLexer::OP_RBRACK)) - return r.error(); - GoASTExpr *elem = Type(); - if (!elem) - return syntaxerror(); - return new GoASTArrayType(len.release(), elem); - } - return r.error(); -} - -GoASTExpr *GoParser::StructType() { - if (!(match(GoLexer::KEYWORD_STRUCT) && mustMatch(GoLexer::OP_LBRACE))) - return nullptr; - std::unique_ptr fields(new GoASTFieldList); - while (auto *field = FieldDecl()) - fields->AddList(field); - if (!mustMatch(GoLexer::OP_RBRACE)) - return nullptr; - return new GoASTStructType(fields.release()); -} - -GoASTField *GoParser::FieldDecl() { - std::unique_ptr f(new GoASTField); - GoASTExpr *t = FieldNamesAndType(f.get()); - if (!t) - t = AnonymousFieldType(); - if (!t) - return nullptr; - - if (auto *tok = match(GoLexer::LIT_STRING)) - f->SetTag(new GoASTBasicLit(*tok)); - if (!Semicolon()) - return syntaxerror(); - return f.release(); -} - -GoASTExpr *GoParser::FieldNamesAndType(GoASTField *field) { - Rule r("FieldNames", this); - for (auto *id = Identifier(); id; id = MoreIdentifierList()) - field->AddNames(id); - if (m_failed) - return nullptr; - GoASTExpr *t = Type(); - if (t) - return t; - return r.error(); -} - -GoASTExpr *GoParser::AnonymousFieldType() { - bool pointer = match(GoLexer::OP_STAR); - GoASTExpr *t = Type(); - if (!t) - return nullptr; - if (pointer) - return new GoASTStarExpr(t); - return t; -} - -GoASTExpr *GoParser::FunctionType() { - if (!match(GoLexer::KEYWORD_FUNC)) - return nullptr; - return Signature(); -} - -GoASTFuncType *GoParser::Signature() { - auto *params = Params(); - if (!params) - return syntaxerror(); - auto *result = Params(); - if (!result) { - if (auto *t = Type()) { - result = new GoASTFieldList; - auto *f = new GoASTField; - f->SetType(t); - result->AddList(f); - } - } - return new GoASTFuncType(params, result); -} - -GoASTFieldList *GoParser::Params() { - if (!match(GoLexer::OP_LPAREN)) - return nullptr; - std::unique_ptr l(new GoASTFieldList); - while (GoASTField *p = ParamDecl()) { - l->AddList(p); - if (!match(GoLexer::OP_COMMA)) - break; - } - if (!mustMatch(GoLexer::OP_RPAREN)) - return nullptr; - return l.release(); -} - -GoASTField *GoParser::ParamDecl() { - std::unique_ptr field(new GoASTField); - GoASTIdent *id = Identifier(); - if (id) { - // Try `IdentifierList [ "..." ] Type`. - // If that fails, backtrack and try `[ "..." ] Type`. - Rule r("NamedParam", this); - for (; id; id = MoreIdentifierList()) - field->AddNames(id); - GoASTExpr *t = ParamType(); - if (t) { - field->SetType(t); - return field.release(); - } - field.reset(new GoASTField); - r.error(); - } - GoASTExpr *t = ParamType(); - if (t) { - field->SetType(t); - return field.release(); - } - return nullptr; -} - -GoASTExpr *GoParser::ParamType() { - bool dots = match(GoLexer::OP_DOTS); - GoASTExpr *t = Type(); - if (!dots) - return t; - if (!t) - return syntaxerror(); - return new GoASTEllipsis(t); -} - -GoASTExpr *GoParser::InterfaceType() { - if (!match(GoLexer::KEYWORD_INTERFACE) || !mustMatch(GoLexer::OP_LBRACE)) - return nullptr; - std::unique_ptr methods(new GoASTFieldList); - while (true) { - Rule r("MethodSpec", this); - // ( identifier Signature | TypeName ) ; - std::unique_ptr id(Identifier()); - if (!id) - break; - GoASTExpr *type = Signature(); - if (!type) { - r.error(); - id.reset(); - type = Name(); - } - if (!Semicolon()) - return syntaxerror(); - auto *f = new GoASTField; - if (id) - f->AddNames(id.release()); - f->SetType(type); - methods->AddList(f); - } - if (!mustMatch(GoLexer::OP_RBRACE)) - return nullptr; - return new GoASTInterfaceType(methods.release()); -} - -GoASTExpr *GoParser::MapType() { - if (!(match(GoLexer::KEYWORD_MAP) && mustMatch(GoLexer::OP_LBRACK))) - return nullptr; - std::unique_ptr key(Type()); - if (!key) - return syntaxerror(); - if (!mustMatch(GoLexer::OP_RBRACK)) - return nullptr; - auto *elem = Type(); - if (!elem) - return syntaxerror(); - return new GoASTMapType(key.release(), elem); -} - -GoASTExpr *GoParser::ChanType() { - Rule r("chan", this); - if (match(GoLexer::OP_LT_MINUS)) { - if (match(GoLexer::KEYWORD_CHAN)) { - auto *elem = Type(); - if (!elem) - return syntaxerror(); - return new GoASTChanType(GoASTNode::eChanRecv, elem); - } - return r.error(); - } - return ChanType2(); -} - -GoASTExpr *GoParser::ChanType2() { - if (!match(GoLexer::KEYWORD_CHAN)) - return nullptr; - auto dir = GoASTNode::eChanBidir; - if (match(GoLexer::OP_LT_MINUS)) - dir = GoASTNode::eChanSend; - auto *elem = Type(); - if (!elem) - return syntaxerror(); - return new GoASTChanType(dir, elem); -} - -GoASTExpr *GoParser::Type() { - if (GoASTExpr *t = Type2()) - return t; - if (GoASTExpr *t = Name()) - return t; - if (GoASTExpr *t = ChanType()) - return t; - if (match(GoLexer::OP_STAR)) { - GoASTExpr *t = Type(); - if (!t) - return syntaxerror(); - return new GoASTStarExpr(t); - } - if (match(GoLexer::OP_LPAREN)) { - std::unique_ptr t(Type()); - if (!t || !match(GoLexer::OP_RPAREN)) - return syntaxerror(); - return t.release(); - } - return nullptr; -} - -bool GoParser::Semicolon() { - if (match(GoLexer::OP_SEMICOLON)) - return true; - switch (peek()) { - case GoLexer::OP_RPAREN: - case GoLexer::OP_RBRACE: - case GoLexer::TOK_EOF: - return true; - default: - return false; - } -} - -GoASTExpr *GoParser::Name() { - if (auto *id = Identifier()) { - if (GoASTExpr *qual = QualifiedIdent(id)) - return qual; - return id; - } - return nullptr; -} - -GoASTExpr *GoParser::QualifiedIdent(lldb_private::GoASTIdent *p) { - Rule r("QualifiedIdent", this); - llvm::SmallString<32> path(p->GetName().m_value); - GoLexer::Token *next; - bool have_slashes = false; - // LLDB extension: support full/package/path.name - while (match(GoLexer::OP_SLASH) && (next = match(GoLexer::TOK_IDENTIFIER))) { - have_slashes = true; - path.append("/"); - path.append(next->m_value); - } - if (match(GoLexer::OP_DOT)) { - auto *name = Identifier(); - if (name) { - if (have_slashes) { - p->SetName(GoLexer::Token(GoLexer::TOK_IDENTIFIER, CopyString(path))); - } - return new GoASTSelectorExpr(p, name); - } - } - return r.error(); -} - -llvm::StringRef GoParser::CopyString(llvm::StringRef s) { - return m_strings.insert(std::make_pair(s, 'x')).first->getKey(); -} - -void GoParser::GetError(Status &error) { - llvm::StringRef want; - if (m_failed) - want = - m_last_tok == GoLexer::TOK_INVALID ? DescribeToken(m_last_tok) : m_last; - else - want = m_error; - size_t len = m_lexer.BytesRemaining(); - if (len > 10) - len = 10; - llvm::StringRef got; - if (len == 0) - got = ""; - else - got = m_lexer.GetString(len); - error.SetErrorStringWithFormat("Syntax error: expected %s before '%s'.", - want.str().c_str(), got.str().c_str()); -} Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h +++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.h @@ -1,94 +0,0 @@ -//===-- GoUserExpression.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_GoUserExpression_h_ -#define liblldb_GoUserExpression_h_ - -// C Includes -// C++ Includes -#include - -// Other libraries and framework includes -// Project includes -#include "lldb/Expression/ExpressionVariable.h" -#include "lldb/Expression/UserExpression.h" -#include "lldb/Target/ExecutionContext.h" -#include "lldb/lldb-forward.h" -#include "lldb/lldb-private.h" - -namespace lldb_private { -class GoParser; - -class GoPersistentExpressionState : public PersistentExpressionState { -public: - GoPersistentExpressionState(); - - llvm::StringRef - GetPersistentVariablePrefix(bool is_error) const override { - return "$go"; - } - void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override; - - lldb::addr_t LookupSymbol(const ConstString &name) override { - return LLDB_INVALID_ADDRESS; - } - - static bool classof(const PersistentExpressionState *pv) { - return pv->getKind() == PersistentExpressionState::eKindGo; - } - -private: - uint32_t m_next_persistent_variable_id; ///< The counter used by - ///GetNextResultName(). -}; - -//---------------------------------------------------------------------- -/// @class GoUserExpression GoUserExpression.h -/// "lldb/Expression/GoUserExpression.h" Encapsulates a single expression for -/// use with Go -/// -/// LLDB uses expressions for various purposes, notably to call functions -/// and as a backend for the expr command. GoUserExpression encapsulates the -/// objects needed to parse and interpret an expression. -//---------------------------------------------------------------------- -class GoUserExpression : public UserExpression { -public: - GoUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr, - llvm::StringRef prefix, lldb::LanguageType language, - ResultType desired_type, - const EvaluateExpressionOptions &options); - - bool Parse(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, - lldb_private::ExecutionPolicy execution_policy, - bool keep_result_in_memory, bool generate_debug_info) override; - - bool CanInterpret() override { return true; } - bool FinalizeJITExecution( - DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, - lldb::ExpressionVariableSP &result, - lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS, - lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override { - return true; - } - -protected: - lldb::ExpressionResults - DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, - const EvaluateExpressionOptions &options, - lldb::UserExpressionSP &shared_ptr_to_me, - lldb::ExpressionVariableSP &result) override; - -private: - class GoInterpreter; - std::unique_ptr m_interpreter; -}; - -} // namespace lldb_private - -#endif // liblldb_GoUserExpression_h_ Index: lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp +++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp @@ -1,668 +0,0 @@ -//===-- GoUserExpression.cpp ------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// C Includes -#include -#if HAVE_SYS_TYPES_H -#include -#endif - -// C++ Includes -#include -#include -#include -#include - -// Other libraries and framework includes -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringRef.h" - -// Project includes -#include "GoUserExpression.h" - -#include "lldb/Core/Module.h" -#include "lldb/Core/StreamFile.h" -#include "lldb/Core/ValueObjectConstResult.h" -#include "lldb/Core/ValueObjectRegister.h" -#include "lldb/Expression/DiagnosticManager.h" -#include "lldb/Expression/ExpressionVariable.h" -#include "lldb/Symbol/GoASTContext.h" -#include "lldb/Symbol/SymbolFile.h" -#include "lldb/Symbol/TypeList.h" -#include "lldb/Symbol/VariableList.h" -#include "lldb/Target/ExecutionContext.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/RegisterContext.h" -#include "lldb/Target/StackFrame.h" -#include "lldb/Target/Target.h" -#include "lldb/Target/ThreadPlan.h" -#include "lldb/Target/ThreadPlanCallUserExpression.h" -#include "lldb/Utility/ConstString.h" -#include "lldb/Utility/DataBufferHeap.h" -#include "lldb/Utility/DataEncoder.h" -#include "lldb/Utility/DataExtractor.h" -#include "lldb/Utility/Log.h" -#include "lldb/Utility/StreamString.h" -#include "lldb/lldb-private.h" - -#include "Plugins/ExpressionParser/Go/GoAST.h" -#include "Plugins/ExpressionParser/Go/GoParser.h" - -using namespace lldb_private; -using namespace lldb; - -class GoUserExpression::GoInterpreter { -public: - GoInterpreter(ExecutionContext &exe_ctx, const char *expr) - : m_exe_ctx(exe_ctx), m_frame(exe_ctx.GetFrameSP()), m_parser(expr) { - if (m_frame) { - const SymbolContext &ctx = - m_frame->GetSymbolContext(eSymbolContextFunction); - ConstString fname = ctx.GetFunctionName(); - if (fname.GetLength() > 0) { - size_t dot = fname.GetStringRef().find('.'); - if (dot != llvm::StringRef::npos) - m_package = llvm::StringRef(fname.AsCString(), dot); - } - } - } - - void set_use_dynamic(DynamicValueType use_dynamic) { - m_use_dynamic = use_dynamic; - } - - bool Parse(); - lldb::ValueObjectSP Evaluate(ExecutionContext &exe_ctx); - lldb::ValueObjectSP EvaluateStatement(const GoASTStmt *s); - lldb::ValueObjectSP EvaluateExpr(const GoASTExpr *e); - - ValueObjectSP VisitBadExpr(const GoASTBadExpr *e) { - m_parser.GetError(m_error); - return nullptr; - } - - ValueObjectSP VisitParenExpr(const GoASTParenExpr *e); - ValueObjectSP VisitIdent(const GoASTIdent *e); - ValueObjectSP VisitStarExpr(const GoASTStarExpr *e); - ValueObjectSP VisitSelectorExpr(const GoASTSelectorExpr *e); - ValueObjectSP VisitBasicLit(const GoASTBasicLit *e); - ValueObjectSP VisitIndexExpr(const GoASTIndexExpr *e); - ValueObjectSP VisitUnaryExpr(const GoASTUnaryExpr *e); - ValueObjectSP VisitCallExpr(const GoASTCallExpr *e); - - ValueObjectSP VisitTypeAssertExpr(const GoASTTypeAssertExpr *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitBinaryExpr(const GoASTBinaryExpr *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitArrayType(const GoASTArrayType *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitChanType(const GoASTChanType *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitCompositeLit(const GoASTCompositeLit *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitEllipsis(const GoASTEllipsis *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitFuncType(const GoASTFuncType *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitFuncLit(const GoASTFuncLit *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitInterfaceType(const GoASTInterfaceType *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitKeyValueExpr(const GoASTKeyValueExpr *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitMapType(const GoASTMapType *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitSliceExpr(const GoASTSliceExpr *e) { - return NotImplemented(e); - } - - ValueObjectSP VisitStructType(const GoASTStructType *e) { - return NotImplemented(e); - } - - CompilerType EvaluateType(const GoASTExpr *e); - - Status &error() { return m_error; } - -private: - std::nullptr_t NotImplemented(const GoASTExpr *e) { - m_error.SetErrorStringWithFormat("%s node not implemented", - e->GetKindName()); - return nullptr; - } - - ExecutionContext m_exe_ctx; - lldb::StackFrameSP m_frame; - GoParser m_parser; - DynamicValueType m_use_dynamic; - Status m_error; - llvm::StringRef m_package; - std::vector> m_statements; -}; - -VariableSP FindGlobalVariable(TargetSP target, llvm::Twine name) { - ConstString fullname(name.str()); - VariableList variable_list; - if (!target) { - return nullptr; - } - const uint32_t match_count = - target->GetImages().FindGlobalVariables(fullname, 1, variable_list); - if (match_count == 1) { - return variable_list.GetVariableAtIndex(0); - } - return nullptr; -} - -CompilerType LookupType(TargetSP target, ConstString name) { - if (!target) - return CompilerType(); - SymbolContext sc; - TypeList type_list; - llvm::DenseSet searched_symbol_files; - uint32_t num_matches = target->GetImages().FindTypes( - sc, name, false, 2, searched_symbol_files, type_list); - if (num_matches > 0) { - return type_list.GetTypeAtIndex(0)->GetFullCompilerType(); - } - return CompilerType(); -} - -GoUserExpression::GoUserExpression(ExecutionContextScope &exe_scope, - llvm::StringRef expr, llvm::StringRef prefix, - lldb::LanguageType language, - ResultType desired_type, - const EvaluateExpressionOptions &options) - : UserExpression(exe_scope, expr, prefix, language, desired_type, options) { -} - -bool GoUserExpression::Parse(DiagnosticManager &diagnostic_manager, - ExecutionContext &exe_ctx, - lldb_private::ExecutionPolicy execution_policy, - bool keep_result_in_memory, - bool generate_debug_info) { - InstallContext(exe_ctx); - m_interpreter.reset(new GoInterpreter(exe_ctx, GetUserText())); - if (m_interpreter->Parse()) - return true; - const char *error_cstr = m_interpreter->error().AsCString(); - if (error_cstr && error_cstr[0]) - diagnostic_manager.PutString(eDiagnosticSeverityError, error_cstr); - else - diagnostic_manager.Printf(eDiagnosticSeverityError, - "expression can't be interpreted or run"); - return false; -} - -lldb::ExpressionResults -GoUserExpression::DoExecute(DiagnosticManager &diagnostic_manager, - ExecutionContext &exe_ctx, - const EvaluateExpressionOptions &options, - lldb::UserExpressionSP &shared_ptr_to_me, - lldb::ExpressionVariableSP &result) { - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | - LIBLLDB_LOG_STEP)); - - lldb_private::ExecutionPolicy execution_policy = options.GetExecutionPolicy(); - lldb::ExpressionResults execution_results = lldb::eExpressionSetupError; - - Process *process = exe_ctx.GetProcessPtr(); - Target *target = exe_ctx.GetTargetPtr(); - - if (target == nullptr || process == nullptr || - process->GetState() != lldb::eStateStopped) { - if (execution_policy == eExecutionPolicyAlways) { - if (log) - log->Printf("== [GoUserExpression::Evaluate] Expression may not run, " - "but is not constant =="); - - diagnostic_manager.PutString(eDiagnosticSeverityError, - "expression needed to run but couldn't"); - - return execution_results; - } - } - - m_interpreter->set_use_dynamic(options.GetUseDynamic()); - ValueObjectSP result_val_sp = m_interpreter->Evaluate(exe_ctx); - Status err = m_interpreter->error(); - m_interpreter.reset(); - - if (!result_val_sp) { - const char *error_cstr = err.AsCString(); - if (error_cstr && error_cstr[0]) - diagnostic_manager.PutString(eDiagnosticSeverityError, error_cstr); - else - diagnostic_manager.PutString(eDiagnosticSeverityError, - "expression can't be interpreted or run"); - return lldb::eExpressionDiscarded; - } - result.reset(new ExpressionVariable(ExpressionVariable::eKindGo)); - result->m_live_sp = result->m_frozen_sp = result_val_sp; - result->m_flags |= ExpressionVariable::EVIsProgramReference; - PersistentExpressionState *pv = - target->GetPersistentExpressionStateForLanguage(eLanguageTypeGo); - if (pv != nullptr) { - result->SetName(pv->GetNextPersistentVariableName( - *target, pv->GetPersistentVariablePrefix())); - pv->AddVariable(result); - } - return lldb::eExpressionCompleted; -} - -bool GoUserExpression::GoInterpreter::Parse() { - for (std::unique_ptr stmt(m_parser.Statement()); stmt; - stmt.reset(m_parser.Statement())) { - if (m_parser.Failed()) - break; - m_statements.emplace_back(std::move(stmt)); - } - if (m_parser.Failed() || !m_parser.AtEOF()) - m_parser.GetError(m_error); - - return m_error.Success(); -} - -ValueObjectSP -GoUserExpression::GoInterpreter::Evaluate(ExecutionContext &exe_ctx) { - m_exe_ctx = exe_ctx; - ValueObjectSP result; - for (const std::unique_ptr &stmt : m_statements) { - result = EvaluateStatement(stmt.get()); - if (m_error.Fail()) - return nullptr; - } - return result; -} - -ValueObjectSP GoUserExpression::GoInterpreter::EvaluateStatement( - const lldb_private::GoASTStmt *stmt) { - ValueObjectSP result; - switch (stmt->GetKind()) { - case GoASTNode::eBlockStmt: { - const GoASTBlockStmt *block = llvm::cast(stmt); - for (size_t i = 0; i < block->NumList(); ++i) - result = EvaluateStatement(block->GetList(i)); - break; - } - case GoASTNode::eBadStmt: - m_parser.GetError(m_error); - break; - case GoASTNode::eExprStmt: { - const GoASTExprStmt *expr = llvm::cast(stmt); - return EvaluateExpr(expr->GetX()); - } - default: - m_error.SetErrorStringWithFormat("%s node not supported", - stmt->GetKindName()); - } - return result; -} - -ValueObjectSP GoUserExpression::GoInterpreter::EvaluateExpr( - const lldb_private::GoASTExpr *e) { - if (e) - return e->Visit(this); - return ValueObjectSP(); -} - -ValueObjectSP GoUserExpression::GoInterpreter::VisitParenExpr( - const lldb_private::GoASTParenExpr *e) { - return EvaluateExpr(e->GetX()); -} - -ValueObjectSP GoUserExpression::GoInterpreter::VisitIdent(const GoASTIdent *e) { - ValueObjectSP val; - if (m_frame) { - VariableSP var_sp; - std::string varname = e->GetName().m_value.str(); - if (varname.size() > 1 && varname[0] == '$') { - RegisterContextSP reg_ctx_sp = m_frame->GetRegisterContext(); - const RegisterInfo *reg = - reg_ctx_sp->GetRegisterInfoByName(varname.c_str() + 1); - if (reg) { - std::string type; - switch (reg->encoding) { - case lldb::eEncodingSint: - type.append("int"); - break; - case lldb::eEncodingUint: - type.append("uint"); - break; - case lldb::eEncodingIEEE754: - type.append("float"); - break; - default: - m_error.SetErrorString("Invalid register encoding"); - return nullptr; - } - switch (reg->byte_size) { - case 8: - type.append("64"); - break; - case 4: - type.append("32"); - break; - case 2: - type.append("16"); - break; - case 1: - type.append("8"); - break; - default: - m_error.SetErrorString("Invalid register size"); - return nullptr; - } - ValueObjectSP regVal = ValueObjectRegister::Create( - m_frame.get(), reg_ctx_sp, reg->kinds[eRegisterKindLLDB]); - CompilerType goType = - LookupType(m_frame->CalculateTarget(), ConstString(type)); - if (regVal) { - regVal = regVal->Cast(goType); - return regVal; - } - } - m_error.SetErrorString("Invalid register name"); - return nullptr; - } - VariableListSP var_list_sp(m_frame->GetInScopeVariableList(false)); - if (var_list_sp) { - var_sp = var_list_sp->FindVariable(ConstString(varname)); - if (var_sp) - val = m_frame->GetValueObjectForFrameVariable(var_sp, m_use_dynamic); - else { - // When a variable is on the heap instead of the stack, go records a - // variable '&x' instead of 'x'. - var_sp = var_list_sp->FindVariable(ConstString("&" + varname)); - if (var_sp) { - val = m_frame->GetValueObjectForFrameVariable(var_sp, m_use_dynamic); - if (val) - val = val->Dereference(m_error); - if (m_error.Fail()) - return nullptr; - } - } - } - if (!val) { - m_error.Clear(); - TargetSP target = m_frame->CalculateTarget(); - if (!target) { - m_error.SetErrorString("No target"); - return nullptr; - } - var_sp = - FindGlobalVariable(target, m_package + "." + e->GetName().m_value); - if (var_sp) - return m_frame->TrackGlobalVariable(var_sp, m_use_dynamic); - } - } - if (!val) - m_error.SetErrorStringWithFormat("Unknown variable %s", - e->GetName().m_value.str().c_str()); - return val; -} - -ValueObjectSP -GoUserExpression::GoInterpreter::VisitStarExpr(const GoASTStarExpr *e) { - ValueObjectSP target = EvaluateExpr(e->GetX()); - if (!target) - return nullptr; - return target->Dereference(m_error); -} - -ValueObjectSP GoUserExpression::GoInterpreter::VisitSelectorExpr( - const lldb_private::GoASTSelectorExpr *e) { - ValueObjectSP target = EvaluateExpr(e->GetX()); - if (target) { - if (target->GetCompilerType().IsPointerType()) { - target = target->Dereference(m_error); - if (m_error.Fail()) - return nullptr; - } - ConstString field(e->GetSel()->GetName().m_value); - ValueObjectSP result = target->GetChildMemberWithName(field, true); - if (!result) - m_error.SetErrorStringWithFormat("Unknown child %s", field.AsCString()); - return result; - } - if (const GoASTIdent *package = llvm::dyn_cast(e->GetX())) { - if (VariableSP global = FindGlobalVariable( - m_exe_ctx.GetTargetSP(), package->GetName().m_value + "." + - e->GetSel()->GetName().m_value)) { - if (m_frame) { - m_error.Clear(); - return m_frame->GetValueObjectForFrameVariable(global, m_use_dynamic); - } - } - } - if (const GoASTBasicLit *packageLit = - llvm::dyn_cast(e->GetX())) { - if (packageLit->GetValue().m_type == GoLexer::LIT_STRING) { - std::string value = packageLit->GetValue().m_value.str(); - value = value.substr(1, value.size() - 2); - if (VariableSP global = FindGlobalVariable( - m_exe_ctx.GetTargetSP(), - value + "." + e->GetSel()->GetName().m_value)) { - if (m_frame) { - m_error.Clear(); - return m_frame->TrackGlobalVariable(global, m_use_dynamic); - } - } - } - } - // EvaluateExpr should have already set m_error. - return target; -} - -ValueObjectSP GoUserExpression::GoInterpreter::VisitBasicLit( - const lldb_private::GoASTBasicLit *e) { - std::string value = e->GetValue().m_value.str(); - if (e->GetValue().m_type != GoLexer::LIT_INTEGER) { - m_error.SetErrorStringWithFormat("Unsupported literal %s", value.c_str()); - return nullptr; - } - errno = 0; - int64_t intvalue = strtol(value.c_str(), nullptr, 0); - if (errno != 0) { - m_error.SetErrorToErrno(); - return nullptr; - } - DataBufferSP buf(new DataBufferHeap(sizeof(intvalue), 0)); - TargetSP target = m_exe_ctx.GetTargetSP(); - if (!target) { - m_error.SetErrorString("No target"); - return nullptr; - } - ByteOrder order = target->GetArchitecture().GetByteOrder(); - uint8_t addr_size = target->GetArchitecture().GetAddressByteSize(); - DataEncoder enc(buf, order, addr_size); - enc.PutU64(0, static_cast(intvalue)); - DataExtractor data(buf, order, addr_size); - - CompilerType type = LookupType(target, ConstString("int64")); - return ValueObject::CreateValueObjectFromData(llvm::StringRef(), data, - m_exe_ctx, type); -} - -ValueObjectSP GoUserExpression::GoInterpreter::VisitIndexExpr( - const lldb_private::GoASTIndexExpr *e) { - ValueObjectSP target = EvaluateExpr(e->GetX()); - if (!target) - return nullptr; - ValueObjectSP index = EvaluateExpr(e->GetIndex()); - if (!index) - return nullptr; - bool is_signed; - if (!index->GetCompilerType().IsIntegerType(is_signed)) { - m_error.SetErrorString("Unsupported index"); - return nullptr; - } - size_t idx; - if (is_signed) - idx = index->GetValueAsSigned(0); - else - idx = index->GetValueAsUnsigned(0); - if (GoASTContext::IsGoSlice(target->GetCompilerType())) { - target = target->GetStaticValue(); - ValueObjectSP cap = - target->GetChildMemberWithName(ConstString("cap"), true); - if (cap) { - uint64_t capval = cap->GetValueAsUnsigned(0); - if (idx >= capval) { - m_error.SetErrorStringWithFormat("Invalid index %" PRIu64 - " , cap = %" PRIu64, - uint64_t(idx), capval); - return nullptr; - } - } - target = target->GetChildMemberWithName(ConstString("array"), true); - if (target && m_use_dynamic != eNoDynamicValues) { - ValueObjectSP dynamic = target->GetDynamicValue(m_use_dynamic); - if (dynamic) - target = dynamic; - } - if (!target) - return nullptr; - return target->GetSyntheticArrayMember(idx, true); - } - return target->GetChildAtIndex(idx, true); -} - -ValueObjectSP -GoUserExpression::GoInterpreter::VisitUnaryExpr(const GoASTUnaryExpr *e) { - ValueObjectSP x = EvaluateExpr(e->GetX()); - if (!x) - return nullptr; - switch (e->GetOp()) { - case GoLexer::OP_AMP: { - CompilerType type = x->GetCompilerType().GetPointerType(); - uint64_t address = x->GetAddressOf(); - return ValueObject::CreateValueObjectFromAddress(llvm::StringRef(), address, - m_exe_ctx, type); - } - case GoLexer::OP_PLUS: - return x; - default: - m_error.SetErrorStringWithFormat( - "Operator %s not supported", - GoLexer::LookupToken(e->GetOp()).str().c_str()); - return nullptr; - } -} - -CompilerType GoUserExpression::GoInterpreter::EvaluateType(const GoASTExpr *e) { - TargetSP target = m_exe_ctx.GetTargetSP(); - if (auto *id = llvm::dyn_cast(e)) { - CompilerType result = - LookupType(target, ConstString(id->GetName().m_value)); - if (result.IsValid()) - return result; - std::string fullname = (m_package + "." + id->GetName().m_value).str(); - result = LookupType(target, ConstString(fullname)); - if (!result) - m_error.SetErrorStringWithFormat("Unknown type %s", fullname.c_str()); - return result; - } - if (auto *sel = llvm::dyn_cast(e)) { - std::string package; - if (auto *pkg_node = llvm::dyn_cast(sel->GetX())) { - package = pkg_node->GetName().m_value.str(); - } else if (auto *str_node = llvm::dyn_cast(sel->GetX())) { - if (str_node->GetValue().m_type == GoLexer::LIT_STRING) { - package = str_node->GetValue().m_value.substr(1).str(); - package.resize(package.length() - 1); - } - } - if (package.empty()) { - m_error.SetErrorStringWithFormat("Invalid %s in type expression", - sel->GetX()->GetKindName()); - return CompilerType(); - } - std::string fullname = - (package + "." + sel->GetSel()->GetName().m_value).str(); - CompilerType result = LookupType(target, ConstString(fullname)); - if (!result) - m_error.SetErrorStringWithFormat("Unknown type %s", fullname.c_str()); - return result; - } - if (auto *star = llvm::dyn_cast(e)) { - CompilerType elem = EvaluateType(star->GetX()); - return elem.GetPointerType(); - } - if (auto *paren = llvm::dyn_cast(e)) - return EvaluateType(paren->GetX()); - if (auto *array = llvm::dyn_cast(e)) { - CompilerType elem = EvaluateType(array->GetElt()); - } - - m_error.SetErrorStringWithFormat("Invalid %s in type expression", - e->GetKindName()); - return CompilerType(); -} - -ValueObjectSP GoUserExpression::GoInterpreter::VisitCallExpr( - const lldb_private::GoASTCallExpr *e) { - ValueObjectSP x = EvaluateExpr(e->GetFun()); - if (x || e->NumArgs() != 1) { - m_error.SetErrorStringWithFormat("Code execution not supported"); - return nullptr; - } - m_error.Clear(); - CompilerType type = EvaluateType(e->GetFun()); - if (!type) { - return nullptr; - } - ValueObjectSP value = EvaluateExpr(e->GetArgs(0)); - if (!value) - return nullptr; - // TODO: Handle special conversions - return value->Cast(type); -} - -GoPersistentExpressionState::GoPersistentExpressionState() - : PersistentExpressionState(eKindGo) {} - -void GoPersistentExpressionState::RemovePersistentVariable( - lldb::ExpressionVariableSP variable) { - RemoveVariable(variable); - - const char *name = variable->GetName().AsCString(); - - if (*(name++) != '$') - return; - if (*(name++) != 'g') - return; - if (*(name++) != 'o') - return; - - if (strtoul(name, nullptr, 0) == m_next_persistent_variable_id - 1) - m_next_persistent_variable_id--; -} Index: lldb/trunk/source/Plugins/ExpressionParser/Go/gen_go_ast.py =================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Go/gen_go_ast.py +++ lldb/trunk/source/Plugins/ExpressionParser/Go/gen_go_ast.py @@ -1,464 +0,0 @@ -import StringIO - - -def addNodes(): - addNode("ArrayType", "Expr", "len", "Expr", "elt", "Expr") - addNode( - "AssignStmt", - "Stmt", - "lhs", - "[]Expr", - "rhs", - "[]Expr", - "define", - "bool") - addNode("BadDecl", "Decl") - addNode("BadExpr", "Expr") - addNode("BadStmt", "Stmt") - addNode("BasicLit", "Expr", "value", "Token") - addNode("BinaryExpr", "Expr", "x", "Expr", "y", "Expr", "op", "TokenType") - addNode("BlockStmt", "Stmt", "list", "[]Stmt") - addNode("Ident", "Expr", "name", "Token") - addNode("BranchStmt", "Stmt", "label", "Ident", "tok", "TokenType") - addNode( - "CallExpr", - "Expr", - "fun", - "Expr", - "args", - "[]Expr", - "ellipsis", - "bool") - addNode("CaseClause", "Stmt", "list", "[]Expr", "body", "[]Stmt") - addNode("ChanType", "Expr", "dir", "ChanDir", "value", "Expr") - addNode("CommClause", "Stmt", "comm", "Stmt", "body", "[]Stmt") - addNode("CompositeLit", "Expr", "type", "Expr", "elts", "[]Expr") - addNode("DeclStmt", "Stmt", "decl", "Decl") - addNode("DeferStmt", "Stmt", "call", "CallExpr") - addNode("Ellipsis", "Expr", "elt", "Expr") - addNode("EmptyStmt", "Stmt") - addNode("ExprStmt", "Stmt", "x", "Expr") - addNode( - "Field", - "Node", - "names", - "[]Ident", - "type", - "Expr", - "tag", - "BasicLit") - addNode("FieldList", "Node", "list", "[]Field") - addNode( - "ForStmt", - "Stmt", - "init", - "Stmt", - "cond", - "Expr", - "post", - "Stmt", - "body", - "BlockStmt") - addNode("FuncType", "Expr", "params", "FieldList", "results", "FieldList") - addNode( - "FuncDecl", - "Decl", - "recv", - "FieldList", - "name", - "Ident", - "type", - "FuncType", - "body", - "BlockStmt") - addNode("FuncLit", "Expr", "type", "FuncType", "body", "BlockStmt") - addNode("GenDecl", "Decl", "tok", "TokenType", "specs", "[]Spec") - addNode("GoStmt", "Stmt", "call", "CallExpr") - addNode( - "IfStmt", - "Stmt", - "init", - "Stmt", - "cond", - "Expr", - "body", - "BlockStmt", - "els", - "Stmt") - addNode("ImportSpec", "Spec", "name", "Ident", "path", "BasicLit") - addNode("IncDecStmt", "Stmt", "x", "Expr", "tok", "TokenType") - addNode("IndexExpr", "Expr", "x", "Expr", "index", "Expr") - addNode("InterfaceType", "Expr", "methods", "FieldList") - addNode("KeyValueExpr", "Expr", "key", "Expr", "value", "Expr") - addNode("LabeledStmt", "Stmt", "label", "Ident", "stmt", "Stmt") - addNode("MapType", "Expr", "key", "Expr", "value", "Expr") - addNode("ParenExpr", "Expr", "x", "Expr") - addNode( - "RangeStmt", - "Stmt", - "key", - "Expr", - "value", - "Expr", - "define", - "bool", - "x", - "Expr", - "body", - "BlockStmt") - addNode("ReturnStmt", "Stmt", "results", "[]Expr") - addNode("SelectStmt", "Stmt", "body", "BlockStmt") - addNode("SelectorExpr", "Expr", "x", "Expr", "sel", "Ident") - addNode("SendStmt", "Stmt", "chan", "Expr", "value", "Expr") - addNode( - "SliceExpr", - "Expr", - "x", - "Expr", - "low", - "Expr", - "high", - "Expr", - "max", - "Expr", - "slice3", - "bool") - addNode("StarExpr", "Expr", "x", "Expr") - addNode("StructType", "Expr", "fields", "FieldList") - addNode( - "SwitchStmt", - "Stmt", - "init", - "Stmt", - "tag", - "Expr", - "body", - "BlockStmt") - addNode("TypeAssertExpr", "Expr", "x", "Expr", "type", "Expr") - addNode("TypeSpec", "Spec", "name", "Ident", "type", "Expr") - addNode( - "TypeSwitchStmt", - "Stmt", - "init", - "Stmt", - "assign", - "Stmt", - "body", - "BlockStmt") - addNode("UnaryExpr", "Expr", "op", "TokenType", "x", "Expr") - addNode( - "ValueSpec", - "Spec", - "names", - "[]Ident", - "type", - "Expr", - "values", - "[]Expr") - addParent("Decl", "Node") - addParent("Expr", "Node") - addParent("Spec", "Node") - addParent("Stmt", "Node") - - -class Member(object): - - def __init__(self, name, typename): - self.title = name.title() - self.sname = name - self.mname = 'm_' + name - self.is_list = typename.startswith("[]") - self.is_value = isValueType(typename) - if self.is_value: - self.argtype = typename - self.mtype = typename - elif self.is_list: - self.argtype = 'GoAST' + typename[2:] - self.mtype = 'std::vector >' % self.argtype - else: - self.argtype = 'GoAST' + typename - self.mtype = 'std::unique_ptr<%s>' % self.argtype - self.mname = self.mname + '_up' - - -kinds = {} -parentClasses = StringIO.StringIO() -childClasses = StringIO.StringIO() -walker = StringIO.StringIO() - - -def startClass(name, parent, out): - out.write(""" -class GoAST%s : public GoAST%s -{ - public: -""" % (name, parent)) - - -def endClass(name, out): - out.write(""" - %(name)s(const %(name)s &) = delete; - const %(name)s &operator=(const %(name)s &) = delete; -}; -""" % {'name': 'GoAST' + name}) - - -def addNode(name, parent, *children): - startClass(name, parent, childClasses) - l = kinds.setdefault(parent, []) - l.append(name) - children = createMembers(name, children) - addConstructor(name, parent, children) - childClasses.write(""" - const char * - GetKindName() const override - { - return "%(name)s"; - } - - static bool - classof(const GoASTNode *n) - { - return n->GetKind() == e%(name)s; - } - """ % {'name': name}) - addChildren(name, children) - endClass(name, childClasses) - - -def isValueType(typename): - if typename[0].islower(): - return True - if typename[0].isupper(): - return typename.startswith('Token') or typename == 'ChanDir' - return False - - -def createMembers(name, children): - l = len(children) - if (l % 2) != 0: - raise Exception("Invalid children for %s: %s" % (name, children)) - return [Member(children[i], children[i + 1]) for i in xrange(0, l, 2)] - - -def addConstructor(name, parent, children): - for c in children: - if c.is_list: - children = [x for x in children if x.is_value] - break - childClasses.write(' ') - if len(children) == 1: - childClasses.write('explicit ') - childClasses.write('GoAST%s(' % name) - for i in xrange(len(children)): - if i > 0: - childClasses.write(', ') - - c = children[i] - if c.is_value: - childClasses.write(c.argtype) - childClasses.write(' ') - else: - childClasses.write('%s *' % c.argtype) - childClasses.write(c.sname) - childClasses.write(') : GoAST%s(e%s)' % (parent, name)) - for c in children: - childClasses.write(', ') - childClasses.write('%(mname)s(%(sname)s)' % c.__dict__) - childClasses.write(""" {} - ~GoAST%s() override = default; -""" % name) - - -def addChildren(name, children): - if len(children) == 0: - return - walker.write(""" - case e%(n)s: - { - GoAST%(n)s *n = llvm::cast(this); - (void)n;""" % {'n': name}) - for c in children: - if c.is_list: - childClasses.write(""" - size_t - Num%(title)s() const - { - return %(mname)s.size(); - } - const %(argtype)s * - Get%(title)s(int i) const - { - return %(mname)s[i].get(); - } - void - Add%(title)s(%(argtype)s *%(sname)s) - { - %(mname)s.push_back(std::unique_ptr<%(argtype)s>(%(sname)s)); - } -""" % c.__dict__) - walker.write(""" - for (auto& e : n->%s) { v(e.get()); }""" % c.mname) - else: - const = '' - get = '' - set = '' - t = c.argtype - if isValueType(t): - set = '%(mname)s = %(sname)s' % c.__dict__ - t = t + ' ' - else: - t = t + ' *' - const = 'const ' - get = '.get()' - set = '%(mname)s.reset(%(sname)s)' % c.__dict__ - walker.write(""" - v(n->%s.get());""" % c.mname) - childClasses.write(""" - %(const)s%(type)s - Get%(title)s() const - { - return %(mname)s%(get)s; - } - void - Set%(title)s(%(type)s%(sname)s) - { - %(set)s; - } -""" % {'const': const, 'title': c.title, 'sname': c.sname, 'get': get, 'set': set, 'type': t, 'mname': c.mname}) - childClasses.write('\n private:\n friend class GoASTNode;\n') - walker.write(""" - return; - }""") - for c in children: - childClasses.write(' %s %s;\n' % (c.mtype, c.mname)) - - -def addParent(name, parent): - startClass(name, parent, parentClasses) - l = kinds[name] - minName = l[0] - maxName = l[-1] - parentClasses.write(""" template R Visit(V *v) const; - - static bool - classof(const GoASTNode *n) - { - return n->GetKind() >= e%s && n->GetKind() <= e%s; - } - - protected: - explicit GoAST%s(NodeKind kind) : GoASTNode(kind) { } - private: -""" % (minName, maxName, name)) - endClass(name, parentClasses) - -addNodes() - -print """//===-- GoAST.h -------------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// DO NOT EDIT. -// Generated by gen_go_ast.py - -#ifndef liblldb_GoAST_h -#define liblldb_GoAST_h - -#include "lldb/lldb-forward.h" -#include "lldb/lldb-private.h" -#include "llvm/Support/Casting.h" -#include "Plugins/ExpressionParser/Go/GoLexer.h" - -namespace lldb_private -{ - -class GoASTNode -{ - public: - typedef GoLexer::TokenType TokenType; - typedef GoLexer::Token Token; - enum ChanDir - { - eChanBidir, - eChanSend, - eChanRecv, - }; - enum NodeKind - {""" -for l in kinds.itervalues(): - for x in l: - print " e%s," % x -print """ }; - - virtual ~GoASTNode() = default; - - NodeKind - GetKind() const - { - return m_kind; - } - - virtual const char *GetKindName() const = 0; - - template void WalkChildren(V &v); - - protected: - explicit GoASTNode(NodeKind kind) : m_kind(kind) { } - - private: - const NodeKind m_kind; - - GoASTNode(const GoASTNode &) = delete; - const GoASTNode &operator=(const GoASTNode &) = delete; -}; -""" - - -print parentClasses.getvalue() -print childClasses.getvalue() - -for k, l in kinds.iteritems(): - if k == 'Node': - continue - print """ -template -R GoAST%s::Visit(V* v) const -{ - switch(GetKind()) - {""" % k - for subtype in l: - print """ case e%(n)s: - return v->Visit%(n)s(llvm::cast(this));""" % {'n': subtype} - - print """ default: - assert(false && "Invalid kind"); - } -}""" - -print """ -template -void GoASTNode::WalkChildren(V &v) -{ - switch (m_kind) - { -""" -print walker.getvalue() -print""" - case eEmptyStmt: - case eBadDecl: - case eBadExpr: - case eBadStmt: - break; - } -} - -} // namespace lldb_private - -#endif -""" Index: lldb/trunk/source/Plugins/Language/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/Language/CMakeLists.txt +++ lldb/trunk/source/Plugins/Language/CMakeLists.txt @@ -1,6 +1,5 @@ add_subdirectory(ClangCommon) add_subdirectory(CPlusPlus) -add_subdirectory(Go) add_subdirectory(Java) add_subdirectory(ObjC) add_subdirectory(ObjCPlusPlus) Index: lldb/trunk/source/Plugins/Language/Go/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/Language/Go/CMakeLists.txt +++ lldb/trunk/source/Plugins/Language/Go/CMakeLists.txt @@ -1,13 +0,0 @@ -add_lldb_library(lldbPluginGoLanguage PLUGIN - GoLanguage.cpp - GoFormatterFunctions.cpp - - LINK_LIBS - clangAST - lldbCore - lldbDataFormatters - lldbSymbol - lldbTarget - LINK_COMPONENTS - Support -) Index: lldb/trunk/source/Plugins/Language/Go/GoFormatterFunctions.h =================================================================== --- lldb/trunk/source/Plugins/Language/Go/GoFormatterFunctions.h +++ lldb/trunk/source/Plugins/Language/Go/GoFormatterFunctions.h @@ -1,43 +0,0 @@ -//===-- GoFormatterFunctions.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_GoFormatterFunctions_h_ -#define liblldb_GoFormatterFunctions_h_ - -// C Includes -#include -#include - -// C++ Includes -// Other libraries and framework includes -#include "clang/AST/ASTContext.h" - -// Project includes -#include "lldb/lldb-forward.h" - -#include "lldb/DataFormatters/FormatClasses.h" -#include "lldb/DataFormatters/TypeSynthetic.h" -#include "lldb/Target/ExecutionContext.h" -#include "lldb/Target/ObjCLanguageRuntime.h" -#include "lldb/Target/Target.h" -#include "lldb/Utility/ConstString.h" - -namespace lldb_private { -namespace formatters { - -bool GoStringSummaryProvider(ValueObject &valobj, Stream &stream, - const TypeSummaryOptions &options); - -SyntheticChildrenFrontEnd * -GoSliceSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP); - -} // namespace formatters -} // namespace lldb_private - -#endif // liblldb_GoFormatterFunctions_h_ Index: lldb/trunk/source/Plugins/Language/Go/GoFormatterFunctions.cpp =================================================================== --- lldb/trunk/source/Plugins/Language/Go/GoFormatterFunctions.cpp +++ lldb/trunk/source/Plugins/Language/Go/GoFormatterFunctions.cpp @@ -1,152 +0,0 @@ -//===-- GoFormatterFunctions.cpp---------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// C Includes -// C++ Includes -#include - -// Other libraries and framework includes -// Project includes -#include "GoFormatterFunctions.h" -#include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/DataFormatters/StringPrinter.h" - -using namespace lldb; -using namespace lldb_private; -using namespace lldb_private::formatters; - -namespace { -class GoSliceSyntheticFrontEnd : public SyntheticChildrenFrontEnd { -public: - GoSliceSyntheticFrontEnd(ValueObject &valobj) - : SyntheticChildrenFrontEnd(valobj) { - Update(); - } - - ~GoSliceSyntheticFrontEnd() override = default; - - size_t CalculateNumChildren() override { return m_len; } - - lldb::ValueObjectSP GetChildAtIndex(size_t idx) override { - if (idx < m_len) { - ValueObjectSP &cached = m_children[idx]; - if (!cached) { - StreamString idx_name; - idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx); - lldb::addr_t object_at_idx = m_base_data_address; - object_at_idx += idx * m_type.GetByteSize(nullptr); - cached = CreateValueObjectFromAddress( - idx_name.GetString(), object_at_idx, - m_backend.GetExecutionContextRef(), m_type); - } - return cached; - } - return ValueObjectSP(); - } - - bool Update() override { - size_t old_count = m_len; - - ConstString array_const_str("array"); - ValueObjectSP array_sp = - m_backend.GetChildMemberWithName(array_const_str, true); - if (!array_sp) { - m_children.clear(); - return old_count == 0; - } - m_type = array_sp->GetCompilerType().GetPointeeType(); - m_base_data_address = array_sp->GetPointerValue(); - - ConstString len_const_str("len"); - ValueObjectSP len_sp = - m_backend.GetChildMemberWithName(len_const_str, true); - if (len_sp) { - m_len = len_sp->GetValueAsUnsigned(0); - m_children.clear(); - } - - return old_count == m_len; - } - - bool MightHaveChildren() override { return true; } - - size_t GetIndexOfChildWithName(const ConstString &name) override { - return ExtractIndexFromString(name.AsCString()); - } - -private: - CompilerType m_type; - lldb::addr_t m_base_data_address; - size_t m_len; - std::map m_children; -}; - -} // anonymous namespace - -bool lldb_private::formatters::GoStringSummaryProvider( - ValueObject &valobj, Stream &stream, const TypeSummaryOptions &opts) { - ProcessSP process_sp = valobj.GetProcessSP(); - if (!process_sp) - return false; - - if (valobj.IsPointerType()) { - Status err; - ValueObjectSP deref = valobj.Dereference(err); - if (!err.Success()) - return false; - return GoStringSummaryProvider(*deref, stream, opts); - } - - ConstString str_name("str"); - ConstString len_name("len"); - - ValueObjectSP data_sp = valobj.GetChildMemberWithName(str_name, true); - ValueObjectSP len_sp = valobj.GetChildMemberWithName(len_name, true); - if (!data_sp || !len_sp) - return false; - bool success; - lldb::addr_t valobj_addr = data_sp->GetValueAsUnsigned(0, &success); - - if (!success) - return false; - - uint64_t length = len_sp->GetValueAsUnsigned(0); - if (length == 0) { - stream.Printf("\"\""); - return true; - } - - StringPrinter::ReadStringAndDumpToStreamOptions options(valobj); - options.SetLocation(valobj_addr); - options.SetProcessSP(process_sp); - options.SetStream(&stream); - options.SetSourceSize(length); - options.SetNeedsZeroTermination(false); - options.SetLanguage(eLanguageTypeGo); - - if (!StringPrinter::ReadStringAndDumpToStream< - StringPrinter::StringElementType::UTF8>(options)) { - stream.Printf("Summary Unavailable"); - return true; - } - - return true; -} - -SyntheticChildrenFrontEnd * -lldb_private::formatters::GoSliceSyntheticFrontEndCreator( - CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) { - if (!valobj_sp) - return nullptr; - - lldb::ProcessSP process_sp(valobj_sp->GetProcessSP()); - if (!process_sp) - return nullptr; - return new GoSliceSyntheticFrontEnd(*valobj_sp); -} Index: lldb/trunk/source/Plugins/Language/Go/GoLanguage.h =================================================================== --- lldb/trunk/source/Plugins/Language/Go/GoLanguage.h +++ lldb/trunk/source/Plugins/Language/Go/GoLanguage.h @@ -1,65 +0,0 @@ -//===-- GoLanguage.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_GoLanguage_h_ -#define liblldb_GoLanguage_h_ - -// C Includes -// C++ Includes -#include - -// Other libraries and framework includes -#include "llvm/ADT/StringRef.h" - -// Project includes -#include "lldb/Target/Language.h" -#include "lldb/Utility/ConstString.h" -#include "lldb/lldb-private.h" - -namespace lldb_private { - -class GoLanguage : public Language { -public: - GoLanguage() = default; - - ~GoLanguage() override = default; - - lldb::LanguageType GetLanguageType() const override { - return lldb::eLanguageTypeGo; - } - - HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override; - - HardcodedFormatters::HardcodedSyntheticFinder - GetHardcodedSynthetics() override; - - bool IsSourceFile(llvm::StringRef file_path) const override; - - //------------------------------------------------------------------ - // Static Functions - //------------------------------------------------------------------ - static void Initialize(); - - static void Terminate(); - - static lldb_private::Language *CreateInstance(lldb::LanguageType language); - - static lldb_private::ConstString GetPluginNameStatic(); - - //------------------------------------------------------------------ - // PluginInterface protocol - //------------------------------------------------------------------ - ConstString GetPluginName() override; - - uint32_t GetPluginVersion() override; -}; - -} // namespace lldb_private - -#endif // liblldb_GoLanguage_h_ Index: lldb/trunk/source/Plugins/Language/Go/GoLanguage.cpp =================================================================== --- lldb/trunk/source/Plugins/Language/Go/GoLanguage.cpp +++ lldb/trunk/source/Plugins/Language/Go/GoLanguage.cpp @@ -1,131 +0,0 @@ -//===-- GoLanguage.cpp ------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// C Includes -#include -// C++ Includes -#include -#include - -// Other libraries and framework includes -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Threading.h" - -// Project includes -#include "GoLanguage.h" -#include "Plugins/Language/Go/GoFormatterFunctions.h" -#include "lldb/Core/PluginManager.h" -#include "lldb/DataFormatters/FormattersHelpers.h" -#include "lldb/Symbol/GoASTContext.h" -#include "lldb/Utility/ConstString.h" - -using namespace lldb; -using namespace lldb_private; -using namespace lldb_private::formatters; - -void GoLanguage::Initialize() { - PluginManager::RegisterPlugin(GetPluginNameStatic(), "Go Language", - CreateInstance); -} - -void GoLanguage::Terminate() { - PluginManager::UnregisterPlugin(CreateInstance); -} - -lldb_private::ConstString GoLanguage::GetPluginNameStatic() { - static ConstString g_name("Go"); - return g_name; -} - -//------------------------------------------------------------------ -// PluginInterface protocol -//------------------------------------------------------------------ -lldb_private::ConstString GoLanguage::GetPluginName() { - return GetPluginNameStatic(); -} - -uint32_t GoLanguage::GetPluginVersion() { return 1; } - -//------------------------------------------------------------------ -// Static Functions -//------------------------------------------------------------------ -Language *GoLanguage::CreateInstance(lldb::LanguageType language) { - if (language == eLanguageTypeGo) - return new GoLanguage(); - return nullptr; -} - -HardcodedFormatters::HardcodedSummaryFinder -GoLanguage::GetHardcodedSummaries() { - static llvm::once_flag g_initialize; - static HardcodedFormatters::HardcodedSummaryFinder g_formatters; - - llvm::call_once(g_initialize, []() -> void { - g_formatters.push_back( - [](lldb_private::ValueObject &valobj, lldb::DynamicValueType, - FormatManager &) -> TypeSummaryImpl::SharedPointer { - static CXXFunctionSummaryFormat::SharedPointer formatter_sp( - new CXXFunctionSummaryFormat( - TypeSummaryImpl::Flags().SetDontShowChildren(true), - lldb_private::formatters::GoStringSummaryProvider, - "Go string summary provider")); - if (GoASTContext::IsGoString(valobj.GetCompilerType())) { - return formatter_sp; - } - if (GoASTContext::IsGoString( - valobj.GetCompilerType().GetPointeeType())) { - return formatter_sp; - } - return nullptr; - }); - g_formatters.push_back( - [](lldb_private::ValueObject &valobj, lldb::DynamicValueType, - FormatManager &) -> TypeSummaryImpl::SharedPointer { - static lldb::TypeSummaryImplSP formatter_sp(new StringSummaryFormat( - TypeSummaryImpl::Flags().SetHideItemNames(true), - "(len ${var.len}, cap ${var.cap})")); - if (GoASTContext::IsGoSlice(valobj.GetCompilerType())) { - return formatter_sp; - } - if (GoASTContext::IsGoSlice( - valobj.GetCompilerType().GetPointeeType())) { - return formatter_sp; - } - return nullptr; - }); - }); - return g_formatters; -} - -HardcodedFormatters::HardcodedSyntheticFinder -GoLanguage::GetHardcodedSynthetics() { - static llvm::once_flag g_initialize; - static HardcodedFormatters::HardcodedSyntheticFinder g_formatters; - - llvm::call_once(g_initialize, []() -> void { - g_formatters.push_back( - [](lldb_private::ValueObject &valobj, lldb::DynamicValueType, - FormatManager &fmt_mgr) -> SyntheticChildren::SharedPointer { - static CXXSyntheticChildren::SharedPointer formatter_sp( - new CXXSyntheticChildren( - SyntheticChildren::Flags(), "slice synthetic children", - lldb_private::formatters::GoSliceSyntheticFrontEndCreator)); - if (GoASTContext::IsGoSlice(valobj.GetCompilerType())) { - return formatter_sp; - } - return nullptr; - }); - }); - - return g_formatters; -} - -bool GoLanguage::IsSourceFile(llvm::StringRef file_path) const { - return file_path.endswith(".go"); -} Index: lldb/trunk/source/Plugins/LanguageRuntime/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/CMakeLists.txt +++ lldb/trunk/source/Plugins/LanguageRuntime/CMakeLists.txt @@ -1,5 +1,4 @@ add_subdirectory(CPlusPlus) add_subdirectory(ObjC) -add_subdirectory(Go) add_subdirectory(Java) add_subdirectory(RenderScript) Index: lldb/trunk/source/Plugins/LanguageRuntime/Go/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/Go/CMakeLists.txt +++ lldb/trunk/source/Plugins/LanguageRuntime/Go/CMakeLists.txt @@ -1,8 +1,6 @@ set(LLVM_NO_RTTI 1) add_lldb_library(lldbPluginLanguageRuntimeGo PLUGIN - GoLanguageRuntime.cpp - LINK_LIBS lldbBreakpoint lldbCore Index: lldb/trunk/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.h =================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.h +++ lldb/trunk/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.h @@ -1,86 +0,0 @@ -//===-- GoLanguageRuntime.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_GoLanguageRuntime_h_ -#define liblldb_GoLanguageRuntime_h_ - -// C Includes -// C++ Includes -// Other libraries and framework includes -// Project includes -#include "lldb/Breakpoint/BreakpointResolver.h" -#include "lldb/Core/Value.h" -#include "lldb/Target/LanguageRuntime.h" -#include "lldb/lldb-private.h" - -namespace lldb_private { - -class GoLanguageRuntime : public lldb_private::LanguageRuntime { -public: - ~GoLanguageRuntime() override = default; - - //------------------------------------------------------------------ - // Static Functions - //------------------------------------------------------------------ - static void Initialize(); - - static void Terminate(); - - static lldb_private::LanguageRuntime * - CreateInstance(Process *process, lldb::LanguageType language); - - static lldb_private::ConstString GetPluginNameStatic(); - - lldb::LanguageType GetLanguageType() const override { - return lldb::eLanguageTypeGo; - } - - bool GetObjectDescription(Stream &str, ValueObject &object) override { - // TODO(ribrdb): Maybe call String() method? - return false; - } - - bool GetObjectDescription(Stream &str, Value &value, - ExecutionContextScope *exe_scope) override { - return false; - } - - bool GetDynamicTypeAndAddress(ValueObject &in_value, - lldb::DynamicValueType use_dynamic, - TypeAndOrName &class_type_or_name, - Address &address, - Value::ValueType &value_type) override; - - bool CouldHaveDynamicValue(ValueObject &in_value) override; - - lldb::BreakpointResolverSP CreateExceptionResolver(Breakpoint *bkpt, - bool catch_bp, - bool throw_bp) override { - return lldb::BreakpointResolverSP(); - } - - TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, - ValueObject &static_value) override; - - //------------------------------------------------------------------ - // PluginInterface protocol - //------------------------------------------------------------------ - lldb_private::ConstString GetPluginName() override; - - uint32_t GetPluginVersion() override; - -private: - GoLanguageRuntime(Process *process) - : lldb_private::LanguageRuntime(process) { - } // Call CreateInstance instead. -}; - -} // namespace lldb_private - -#endif // liblldb_GoLanguageRuntime_h_ Index: lldb/trunk/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp =================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp +++ lldb/trunk/source/Plugins/LanguageRuntime/Go/GoLanguageRuntime.cpp @@ -1,215 +0,0 @@ -//===-- GoLanguageRuntime.cpp --------------------------------------*- C++ -//-*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "GoLanguageRuntime.h" - -#include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/PluginManager.h" -#include "lldb/Core/ValueObject.h" -#include "lldb/Core/ValueObjectMemory.h" -#include "lldb/Symbol/GoASTContext.h" -#include "lldb/Symbol/Symbol.h" -#include "lldb/Symbol/SymbolFile.h" -#include "lldb/Symbol/TypeList.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/RegisterContext.h" -#include "lldb/Target/SectionLoadList.h" -#include "lldb/Target/StopInfo.h" -#include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" -#include "lldb/Utility/ConstString.h" -#include "lldb/Utility/Log.h" -#include "lldb/Utility/Scalar.h" -#include "lldb/Utility/Status.h" -#include "llvm/ADT/Twine.h" - -#include - -using namespace lldb; -using namespace lldb_private; - -namespace { -ValueObjectSP GetChild(ValueObject &obj, const char *name, - bool dereference = true) { - ConstString name_const_str(name); - ValueObjectSP result = obj.GetChildMemberWithName(name_const_str, true); - if (dereference && result && result->IsPointerType()) { - Status err; - result = result->Dereference(err); - if (err.Fail()) - result.reset(); - } - return result; -} - -ConstString ReadString(ValueObject &str, Process *process) { - ConstString result; - ValueObjectSP data = GetChild(str, "str", false); - ValueObjectSP len = GetChild(str, "len"); - if (len && data) { - Status err; - lldb::addr_t addr = data->GetPointerValue(); - if (addr == LLDB_INVALID_ADDRESS) - return result; - uint64_t byte_size = len->GetValueAsUnsigned(0); - char *buf = new char[byte_size + 1]; - buf[byte_size] = 0; - size_t bytes_read = process->ReadMemory(addr, buf, byte_size, err); - if (!(err.Fail() || bytes_read != byte_size)) - result = ConstString(buf, bytes_read); - delete[] buf; - } - return result; -} - -ConstString ReadTypeName(ValueObjectSP type, Process *process) { - if (ValueObjectSP uncommon = GetChild(*type, "x")) { - ValueObjectSP name = GetChild(*uncommon, "name"); - ValueObjectSP package = GetChild(*uncommon, "pkgpath"); - if (name && name->GetPointerValue() != 0 && package && - package->GetPointerValue() != 0) { - ConstString package_const_str = ReadString(*package, process); - ConstString name_const_str = ReadString(*name, process); - if (package_const_str.GetLength() == 0) - return name_const_str; - return ConstString((package_const_str.GetStringRef() + "." + - name_const_str.GetStringRef()) - .str()); - } - } - ValueObjectSP name = GetChild(*type, "_string"); - if (name) - return ReadString(*name, process); - return ConstString(""); -} - -CompilerType LookupRuntimeType(ValueObjectSP type, ExecutionContext *exe_ctx, - bool *is_direct) { - uint8_t kind = GetChild(*type, "kind")->GetValueAsUnsigned(0); - *is_direct = GoASTContext::IsDirectIface(kind); - if (GoASTContext::IsPointerKind(kind)) { - CompilerType type_ptr = type->GetCompilerType().GetPointerType(); - Status err; - ValueObjectSP elem = - type->CreateValueObjectFromAddress("elem", type->GetAddressOf() + - type->GetByteSize(), - *exe_ctx, type_ptr) - ->Dereference(err); - if (err.Fail()) - return CompilerType(); - bool tmp_direct; - return LookupRuntimeType(elem, exe_ctx, &tmp_direct).GetPointerType(); - } - Target *target = exe_ctx->GetTargetPtr(); - Process *process = exe_ctx->GetProcessPtr(); - - ConstString const_typename = ReadTypeName(type, process); - if (const_typename.GetLength() == 0) - return CompilerType(); - - SymbolContext sc; - TypeList type_list; - llvm::DenseSet searched_symbol_files; - uint32_t num_matches = target->GetImages().FindTypes( - sc, const_typename, false, 2, searched_symbol_files, type_list); - if (num_matches > 0) { - return type_list.GetTypeAtIndex(0)->GetFullCompilerType(); - } - return CompilerType(); -} -} - -bool GoLanguageRuntime::CouldHaveDynamicValue(ValueObject &in_value) { - return GoASTContext::IsGoInterface(in_value.GetCompilerType()); -} - -bool GoLanguageRuntime::GetDynamicTypeAndAddress( - ValueObject &in_value, lldb::DynamicValueType use_dynamic, - TypeAndOrName &class_type_or_name, Address &dynamic_address, - Value::ValueType &value_type) { - value_type = Value::eValueTypeScalar; - class_type_or_name.Clear(); - if (CouldHaveDynamicValue(in_value)) { - Status err; - ValueObjectSP iface = in_value.GetStaticValue(); - ValueObjectSP data_sp = GetChild(*iface, "data", false); - if (!data_sp) - return false; - - if (ValueObjectSP tab = GetChild(*iface, "tab")) - iface = tab; - ValueObjectSP type = GetChild(*iface, "_type"); - if (!type) { - return false; - } - - bool direct; - ExecutionContext exe_ctx(in_value.GetExecutionContextRef()); - CompilerType final_type = LookupRuntimeType(type, &exe_ctx, &direct); - if (!final_type) - return false; - if (direct) { - class_type_or_name.SetCompilerType(final_type); - } else { - // TODO: implement reference types or fix caller to support dynamic types - // that aren't pointers - // so we don't have to introduce this extra pointer. - class_type_or_name.SetCompilerType(final_type.GetPointerType()); - } - - dynamic_address.SetLoadAddress(data_sp->GetPointerValue(), - exe_ctx.GetTargetPtr()); - - return true; - } - return false; -} - -TypeAndOrName -GoLanguageRuntime::FixUpDynamicType(const TypeAndOrName &type_and_or_name, - ValueObject &static_value) { - return type_and_or_name; -} - -//------------------------------------------------------------------ -// Static Functions -//------------------------------------------------------------------ -LanguageRuntime * -GoLanguageRuntime::CreateInstance(Process *process, - lldb::LanguageType language) { - if (language == eLanguageTypeGo) - return new GoLanguageRuntime(process); - else - return NULL; -} - -void GoLanguageRuntime::Initialize() { - PluginManager::RegisterPlugin(GetPluginNameStatic(), "Go Language Runtime", - CreateInstance); -} - -void GoLanguageRuntime::Terminate() { - PluginManager::UnregisterPlugin(CreateInstance); -} - -lldb_private::ConstString GoLanguageRuntime::GetPluginNameStatic() { - static ConstString g_name("golang"); - return g_name; -} - -//------------------------------------------------------------------ -// PluginInterface protocol -//------------------------------------------------------------------ -lldb_private::ConstString GoLanguageRuntime::GetPluginName() { - return GetPluginNameStatic(); -} - -uint32_t GoLanguageRuntime::GetPluginVersion() { return 1; } Index: lldb/trunk/source/Plugins/OperatingSystem/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/OperatingSystem/CMakeLists.txt +++ lldb/trunk/source/Plugins/OperatingSystem/CMakeLists.txt @@ -1,2 +1 @@ -add_subdirectory(Go) add_subdirectory(Python) Index: lldb/trunk/source/Plugins/OperatingSystem/Go/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/OperatingSystem/Go/CMakeLists.txt +++ lldb/trunk/source/Plugins/OperatingSystem/Go/CMakeLists.txt @@ -1,10 +0,0 @@ -add_lldb_library(lldbPluginOSGo PLUGIN - OperatingSystemGo.cpp - - LINK_LIBS - lldbCore - lldbInterpreter - lldbSymbol - lldbTarget - lldbPluginProcessUtility - ) Index: lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.h =================================================================== --- lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.h +++ lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.h @@ -1,90 +0,0 @@ -//===-- OperatingSystemGo.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_OperatingSystemGo_h_ -#define _liblldb_OperatingSystemGo_h_ - -// C Includes -// C++ Includes -#include - -// Other libraries and framework includes -// Project includes -#include "lldb/Target/OperatingSystem.h" - -class DynamicRegisterInfo; - -class OperatingSystemGo : public lldb_private::OperatingSystem { -public: - OperatingSystemGo(lldb_private::Process *process); - - ~OperatingSystemGo() override; - - //------------------------------------------------------------------ - // Static Functions - //------------------------------------------------------------------ - static lldb_private::OperatingSystem * - CreateInstance(lldb_private::Process *process, bool force); - - static void Initialize(); - - static void DebuggerInitialize(lldb_private::Debugger &debugger); - - static void Terminate(); - - static lldb_private::ConstString GetPluginNameStatic(); - - static const char *GetPluginDescriptionStatic(); - - //------------------------------------------------------------------ - // lldb_private::PluginInterface Methods - //------------------------------------------------------------------ - lldb_private::ConstString GetPluginName() override; - - uint32_t GetPluginVersion() override; - - //------------------------------------------------------------------ - // lldb_private::OperatingSystem Methods - //------------------------------------------------------------------ - bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, - lldb_private::ThreadList &real_thread_list, - lldb_private::ThreadList &new_thread_list) override; - - void ThreadWasSelected(lldb_private::Thread *thread) override; - - lldb::RegisterContextSP - CreateRegisterContextForThread(lldb_private::Thread *thread, - lldb::addr_t reg_data_addr) override; - - lldb::StopInfoSP - CreateThreadStopReason(lldb_private::Thread *thread) override; - - //------------------------------------------------------------------ - // Method for lazy creation of threads on demand - //------------------------------------------------------------------ - lldb::ThreadSP CreateThread(lldb::tid_t tid, lldb::addr_t context) override; - -private: - struct Goroutine; - - static lldb::ValueObjectSP FindGlobal(lldb::TargetSP target, - const char *name); - - static lldb::TypeSP FindType(lldb::TargetSP target_sp, const char *name); - - bool Init(lldb_private::ThreadList &threads); - - Goroutine CreateGoroutineAtIndex(uint64_t idx, lldb_private::Status &err); - - std::unique_ptr m_reginfo; - lldb::ValueObjectSP m_allg_sp; - lldb::ValueObjectSP m_allglen_sp; -}; - -#endif // liblldb_OperatingSystemGo_h_ Index: lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp =================================================================== --- lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp +++ lldb/trunk/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp @@ -1,497 +0,0 @@ -//===-- OperatingSystemGo.cpp -----------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// C Includes -// C++ Includes -#include - -// Other libraries and framework includes -// Project includes -#include "OperatingSystemGo.h" - -#include "Plugins/Process/Utility/DynamicRegisterInfo.h" -#include "Plugins/Process/Utility/RegisterContextMemory.h" -#include "Plugins/Process/Utility/ThreadMemory.h" -#include "lldb/Core/Debugger.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/PluginManager.h" -#include "lldb/Core/Section.h" -#include "lldb/Core/ValueObjectVariable.h" -#include "lldb/Interpreter/CommandInterpreter.h" -#include "lldb/Interpreter/OptionGroupBoolean.h" -#include "lldb/Interpreter/OptionGroupUInt64.h" -#include "lldb/Interpreter/OptionValueProperties.h" -#include "lldb/Interpreter/Options.h" -#include "lldb/Interpreter/Property.h" -#include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/Type.h" -#include "lldb/Symbol/VariableList.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/StopInfo.h" -#include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" -#include "lldb/Target/ThreadList.h" -#include "lldb/Utility/DataBufferHeap.h" -#include "lldb/Utility/RegisterValue.h" -#include "lldb/Utility/StreamString.h" - -using namespace lldb; -using namespace lldb_private; - -namespace { - -static constexpr PropertyDefinition g_properties[] = { - {"enable", OptionValue::eTypeBoolean, true, true, nullptr, {}, - "Specify whether goroutines should be treated as threads."}}; - -enum { - ePropertyEnableGoroutines, -}; - -class PluginProperties : public Properties { -public: - PluginProperties() : Properties() { - m_collection_sp.reset(new OptionValueProperties(GetSettingName())); - m_collection_sp->Initialize(g_properties); - } - - ~PluginProperties() override = default; - - static ConstString GetSettingName() { - return OperatingSystemGo::GetPluginNameStatic(); - } - - bool GetEnableGoroutines() { - const uint32_t idx = ePropertyEnableGoroutines; - return m_collection_sp->GetPropertyAtIndexAsBoolean( - NULL, idx, g_properties[idx].default_uint_value); - } - - bool SetEnableGoroutines(bool enable) { - const uint32_t idx = ePropertyEnableGoroutines; - return m_collection_sp->SetPropertyAtIndexAsUInt64(NULL, idx, enable); - } -}; - -typedef std::shared_ptr OperatingSystemGoPropertiesSP; - -static const OperatingSystemGoPropertiesSP &GetGlobalPluginProperties() { - static OperatingSystemGoPropertiesSP g_settings_sp; - if (!g_settings_sp) - g_settings_sp.reset(new PluginProperties()); - return g_settings_sp; -} - -class RegisterContextGo : public RegisterContextMemory { -public: - RegisterContextGo(lldb_private::Thread &thread, uint32_t concrete_frame_idx, - DynamicRegisterInfo ®_info, lldb::addr_t reg_data_addr) - : RegisterContextMemory(thread, concrete_frame_idx, reg_info, - reg_data_addr) { - const RegisterInfo *sp = reg_info.GetRegisterInfoAtIndex( - reg_info.ConvertRegisterKindToRegisterNumber(eRegisterKindGeneric, - LLDB_REGNUM_GENERIC_SP)); - const RegisterInfo *pc = reg_info.GetRegisterInfoAtIndex( - reg_info.ConvertRegisterKindToRegisterNumber(eRegisterKindGeneric, - LLDB_REGNUM_GENERIC_PC)); - size_t byte_size = std::max(sp->byte_offset + sp->byte_size, - pc->byte_offset + pc->byte_size); - - DataBufferSP reg_data_sp(new DataBufferHeap(byte_size, 0)); - m_reg_data.SetData(reg_data_sp); - } - - ~RegisterContextGo() override = default; - - bool ReadRegister(const lldb_private::RegisterInfo *reg_info, - lldb_private::RegisterValue ®_value) override { - switch (reg_info->kinds[eRegisterKindGeneric]) { - case LLDB_REGNUM_GENERIC_SP: - case LLDB_REGNUM_GENERIC_PC: - return RegisterContextMemory::ReadRegister(reg_info, reg_value); - default: - reg_value.SetValueToInvalid(); - return true; - } - } - - bool WriteRegister(const lldb_private::RegisterInfo *reg_info, - const lldb_private::RegisterValue ®_value) override { - switch (reg_info->kinds[eRegisterKindGeneric]) { - case LLDB_REGNUM_GENERIC_SP: - case LLDB_REGNUM_GENERIC_PC: - return RegisterContextMemory::WriteRegister(reg_info, reg_value); - default: - return false; - } - } - -private: - DISALLOW_COPY_AND_ASSIGN(RegisterContextGo); -}; - -} // anonymous namespace - -struct OperatingSystemGo::Goroutine { - uint64_t m_lostack; - uint64_t m_histack; - uint64_t m_goid; - addr_t m_gobuf; - uint32_t m_status; -}; - -void OperatingSystemGo::Initialize() { - PluginManager::RegisterPlugin(GetPluginNameStatic(), - GetPluginDescriptionStatic(), CreateInstance, - DebuggerInitialize); -} - -void OperatingSystemGo::DebuggerInitialize(Debugger &debugger) { - if (!PluginManager::GetSettingForOperatingSystemPlugin( - debugger, PluginProperties::GetSettingName())) { - const bool is_global_setting = true; - PluginManager::CreateSettingForOperatingSystemPlugin( - debugger, GetGlobalPluginProperties()->GetValueProperties(), - ConstString("Properties for the goroutine thread plug-in."), - is_global_setting); - } -} - -void OperatingSystemGo::Terminate() { - PluginManager::UnregisterPlugin(CreateInstance); -} - -OperatingSystem *OperatingSystemGo::CreateInstance(Process *process, - bool force) { - if (!force) { - TargetSP target_sp = process->CalculateTarget(); - if (!target_sp) - return nullptr; - ModuleList &module_list = target_sp->GetImages(); - std::lock_guard guard(module_list.GetMutex()); - const size_t num_modules = module_list.GetSize(); - bool found_go_runtime = false; - for (size_t i = 0; i < num_modules; ++i) { - Module *module = module_list.GetModulePointerAtIndexUnlocked(i); - const SectionList *section_list = module->GetSectionList(); - if (section_list) { - SectionSP section_sp( - section_list->FindSectionByType(eSectionTypeGoSymtab, true)); - if (section_sp) { - found_go_runtime = true; - break; - } - } - } - if (!found_go_runtime) - return nullptr; - } - return new OperatingSystemGo(process); -} - -OperatingSystemGo::OperatingSystemGo(lldb_private::Process *process) - : OperatingSystem(process), m_reginfo(new DynamicRegisterInfo) {} - -OperatingSystemGo::~OperatingSystemGo() = default; - -ConstString OperatingSystemGo::GetPluginNameStatic() { - static ConstString g_name("goroutines"); - return g_name; -} - -const char *OperatingSystemGo::GetPluginDescriptionStatic() { - return "Operating system plug-in that reads runtime data-structures for " - "goroutines."; -} - -bool OperatingSystemGo::Init(ThreadList &threads) { - if (threads.GetSize(false) < 1) - return false; - TargetSP target_sp = m_process->CalculateTarget(); - if (!target_sp) - return false; - // Go 1.6 stores goroutines in a slice called runtime.allgs - ValueObjectSP allgs_sp = FindGlobal(target_sp, "runtime.allgs"); - if (allgs_sp) { - m_allg_sp = allgs_sp->GetChildMemberWithName(ConstString("array"), true); - m_allglen_sp = allgs_sp->GetChildMemberWithName(ConstString("len"), true); - } else { - // Go 1.4 stores goroutines in the variable runtime.allg. - m_allg_sp = FindGlobal(target_sp, "runtime.allg"); - m_allglen_sp = FindGlobal(target_sp, "runtime.allglen"); - } - - if (m_allg_sp && !m_allglen_sp) { - StreamSP error_sp = target_sp->GetDebugger().GetAsyncErrorStream(); - error_sp->Printf("Unsupported Go runtime version detected."); - return false; - } - - if (!m_allg_sp) - return false; - - RegisterContextSP real_registers_sp = - threads.GetThreadAtIndex(0, false)->GetRegisterContext(); - - std::unordered_map register_sets; - for (size_t set_idx = 0; set_idx < real_registers_sp->GetRegisterSetCount(); - ++set_idx) { - const RegisterSet *set = real_registers_sp->GetRegisterSet(set_idx); - ConstString name(set->name); - for (size_t reg_idx = 0; reg_idx < set->num_registers; ++reg_idx) { - register_sets[reg_idx] = name; - } - } - TypeSP gobuf_sp = FindType(target_sp, "runtime.gobuf"); - if (!gobuf_sp) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS)); - - if (log) - log->Printf("OperatingSystemGo unable to find struct Gobuf"); - return false; - } - CompilerType gobuf_type(gobuf_sp->GetLayoutCompilerType()); - for (size_t idx = 0; idx < real_registers_sp->GetRegisterCount(); ++idx) { - RegisterInfo reg = *real_registers_sp->GetRegisterInfoAtIndex(idx); - int field_index = -1; - if (reg.kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_SP) { - field_index = 0; - } else if (reg.kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_PC) { - field_index = 1; - } - if (field_index == -1) { - reg.byte_offset = ~0; - } else { - std::string field_name; - uint64_t bit_offset = 0; - CompilerType field_type = gobuf_type.GetFieldAtIndex( - field_index, field_name, &bit_offset, nullptr, nullptr); - reg.byte_size = field_type.GetByteSize(nullptr); - reg.byte_offset = bit_offset / 8; - } - ConstString name(reg.name); - ConstString alt_name(reg.alt_name); - m_reginfo->AddRegister(reg, name, alt_name, register_sets[idx]); - } - return true; -} - -//------------------------------------------------------------------ -// PluginInterface protocol -//------------------------------------------------------------------ -ConstString OperatingSystemGo::GetPluginName() { return GetPluginNameStatic(); } - -uint32_t OperatingSystemGo::GetPluginVersion() { return 1; } - -bool OperatingSystemGo::UpdateThreadList(ThreadList &old_thread_list, - ThreadList &real_thread_list, - ThreadList &new_thread_list) { - new_thread_list = real_thread_list; - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS)); - - if (!(m_allg_sp || Init(real_thread_list)) || (m_allg_sp && !m_allglen_sp) || - !GetGlobalPluginProperties()->GetEnableGoroutines()) { - return new_thread_list.GetSize(false) > 0; - } - - if (log) - log->Printf("OperatingSystemGo::UpdateThreadList(%d, %d, %d) fetching " - "thread data from Go for pid %" PRIu64, - old_thread_list.GetSize(false), real_thread_list.GetSize(false), - new_thread_list.GetSize(0), m_process->GetID()); - uint64_t allglen = m_allglen_sp->GetValueAsUnsigned(0); - if (allglen == 0) { - return new_thread_list.GetSize(false) > 0; - } - std::vector goroutines; - // The threads that are in "new_thread_list" upon entry are the threads from - // the lldb_private::Process subclass, no memory threads will be in this - // list. - - Status err; - for (uint64_t i = 0; i < allglen; ++i) { - goroutines.push_back(CreateGoroutineAtIndex(i, err)); - if (err.Fail()) { - LLDB_LOG(log, "error: {0}", err); - return new_thread_list.GetSize(false) > 0; - } - } - // Make a map so we can match goroutines with backing threads. - std::map stack_map; - for (uint32_t i = 0; i < real_thread_list.GetSize(false); ++i) { - ThreadSP thread = real_thread_list.GetThreadAtIndex(i, false); - stack_map[thread->GetRegisterContext()->GetSP()] = thread; - } - for (const Goroutine &goroutine : goroutines) { - if (0 /* Gidle */ == goroutine.m_status || - 6 /* Gdead */ == goroutine.m_status) { - continue; - } - ThreadSP memory_thread = - old_thread_list.FindThreadByID(goroutine.m_goid, false); - if (memory_thread && IsOperatingSystemPluginThread(memory_thread) && - memory_thread->IsValid()) { - memory_thread->ClearBackingThread(); - } else { - memory_thread.reset(new ThreadMemory(*m_process, goroutine.m_goid, "", "", - goroutine.m_gobuf)); - } - // Search for the backing thread if the goroutine is running. - if (2 == (goroutine.m_status & 0xfff)) { - auto backing_it = stack_map.lower_bound(goroutine.m_lostack); - if (backing_it != stack_map.end()) { - if (goroutine.m_histack >= backing_it->first) { - if (log) - log->Printf( - "OperatingSystemGo::UpdateThreadList found backing thread " - "%" PRIx64 " (%" PRIx64 ") for thread %" PRIx64 "", - backing_it->second->GetID(), - backing_it->second->GetProtocolID(), memory_thread->GetID()); - memory_thread->SetBackingThread(backing_it->second); - new_thread_list.RemoveThreadByID(backing_it->second->GetID(), false); - } - } - } - new_thread_list.AddThread(memory_thread); - } - - return new_thread_list.GetSize(false) > 0; -} - -void OperatingSystemGo::ThreadWasSelected(Thread *thread) {} - -RegisterContextSP -OperatingSystemGo::CreateRegisterContextForThread(Thread *thread, - addr_t reg_data_addr) { - RegisterContextSP reg_ctx_sp; - if (!thread) - return reg_ctx_sp; - - if (!IsOperatingSystemPluginThread(thread->shared_from_this())) - return reg_ctx_sp; - - reg_ctx_sp.reset( - new RegisterContextGo(*thread, 0, *m_reginfo, reg_data_addr)); - return reg_ctx_sp; -} - -StopInfoSP -OperatingSystemGo::CreateThreadStopReason(lldb_private::Thread *thread) { - StopInfoSP stop_info_sp; - return stop_info_sp; -} - -lldb::ThreadSP OperatingSystemGo::CreateThread(lldb::tid_t tid, - addr_t context) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS)); - - if (log) - log->Printf("OperatingSystemGo::CreateThread (tid = 0x%" PRIx64 - ", context = 0x%" PRIx64 ") not implemented", - tid, context); - - return ThreadSP(); -} - -ValueObjectSP OperatingSystemGo::FindGlobal(TargetSP target, const char *name) { - VariableList variable_list; - - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS)); - - if (log) { - log->Printf( - "exe: %s", - target->GetExecutableModule()->GetSpecificationDescription().c_str()); - log->Printf("modules: %zu", target->GetImages().GetSize()); - } - - uint32_t match_count = target->GetImages().FindGlobalVariables( - ConstString(name), 1, variable_list); - if (match_count > 0) { - ExecutionContextScope *exe_scope = target->GetProcessSP().get(); - if (exe_scope == NULL) - exe_scope = target.get(); - return ValueObjectVariable::Create(exe_scope, - variable_list.GetVariableAtIndex(0)); - } - return ValueObjectSP(); -} - -TypeSP OperatingSystemGo::FindType(TargetSP target_sp, const char *name) { - ConstString const_typename(name); - SymbolContext sc; - const bool exact_match = false; - - const ModuleList &module_list = target_sp->GetImages(); - size_t count = module_list.GetSize(); - for (size_t idx = 0; idx < count; idx++) { - ModuleSP module_sp(module_list.GetModuleAtIndex(idx)); - if (module_sp) { - TypeSP type_sp(module_sp->FindFirstType(sc, const_typename, exact_match)); - if (type_sp) - return type_sp; - } - } - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS)); - - if (log) - log->Printf("OperatingSystemGo::FindType(%s): not found", name); - return TypeSP(); -} - -OperatingSystemGo::Goroutine -OperatingSystemGo::CreateGoroutineAtIndex(uint64_t idx, Status &err) { - err.Clear(); - Goroutine result = {}; - ValueObjectSP g = - m_allg_sp->GetSyntheticArrayMember(idx, true)->Dereference(err); - if (err.Fail()) { - return result; - } - - ConstString name("goid"); - ValueObjectSP val = g->GetChildMemberWithName(name, true); - bool success = false; - result.m_goid = val->GetValueAsUnsigned(0, &success); - if (!success) { - err.SetErrorToGenericError(); - err.SetErrorString("unable to read goid"); - return result; - } - name.SetCString("atomicstatus"); - val = g->GetChildMemberWithName(name, true); - result.m_status = (uint32_t)val->GetValueAsUnsigned(0, &success); - if (!success) { - err.SetErrorToGenericError(); - err.SetErrorString("unable to read atomicstatus"); - return result; - } - name.SetCString("sched"); - val = g->GetChildMemberWithName(name, true); - result.m_gobuf = val->GetAddressOf(false); - name.SetCString("stack"); - val = g->GetChildMemberWithName(name, true); - name.SetCString("lo"); - ValueObjectSP child = val->GetChildMemberWithName(name, true); - result.m_lostack = child->GetValueAsUnsigned(0, &success); - if (!success) { - err.SetErrorToGenericError(); - err.SetErrorString("unable to read stack.lo"); - return result; - } - name.SetCString("hi"); - child = val->GetChildMemberWithName(name, true); - result.m_histack = child->GetValueAsUnsigned(0, &success); - if (!success) { - err.SetErrorToGenericError(); - err.SetErrorString("unable to read stack.hi"); - return result; - } - return result; -} Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/CMakeLists.txt +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/CMakeLists.txt @@ -4,7 +4,6 @@ DIERef.cpp DWARFAbbreviationDeclaration.cpp DWARFASTParserClang.cpp - DWARFASTParserGo.cpp DWARFASTParserJava.cpp DWARFASTParserOCaml.cpp DWARFAttribute.cpp Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.h @@ -1,84 +0,0 @@ -//===-- DWARFASTParserGo.h --------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef SymbolFileDWARF_DWARFASTParserGo_h_ -#define SymbolFileDWARF_DWARFASTParserGo_h_ - -// C Includes -// C++ Includes -// Other libraries and framework includes -#include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/SmallPtrSet.h" -#include "llvm/ADT/SmallVector.h" - -// Project includes -#include "DWARFASTParser.h" -#include "DWARFDIE.h" -#include "DWARFDefines.h" -#include "lldb/Core/PluginInterface.h" -#include "lldb/Symbol/GoASTContext.h" - -class DWARFDebugInfoEntry; -class DWARFDIECollection; - -class DWARFASTParserGo : public DWARFASTParser { -public: - DWARFASTParserGo(lldb_private::GoASTContext &ast); - - ~DWARFASTParserGo() override; - - lldb::TypeSP ParseTypeFromDWARF(const lldb_private::SymbolContext &sc, - const DWARFDIE &die, lldb_private::Log *log, - bool *type_is_new_ptr) override; - - lldb_private::Function * - ParseFunctionFromDWARF(const lldb_private::SymbolContext &sc, - const DWARFDIE &die) override; - - bool CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, - lldb_private::CompilerType &go_type) override; - - lldb_private::CompilerDeclContext - GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override { - return lldb_private::CompilerDeclContext(); - } - - lldb_private::CompilerDeclContext - GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) override { - return lldb_private::CompilerDeclContext(); - } - - lldb_private::CompilerDecl - GetDeclForUIDFromDWARF(const DWARFDIE &die) override { - return lldb_private::CompilerDecl(); - } - - std::vector GetDIEForDeclContext( - lldb_private::CompilerDeclContext decl_context) override { - return std::vector(); - } - -private: - size_t ParseChildParameters( - const lldb_private::SymbolContext &sc, const DWARFDIE &parent_die, - bool &is_variadic, - std::vector &function_param_types); - void ParseChildArrayInfo(const lldb_private::SymbolContext &sc, - const DWARFDIE &parent_die, int64_t &first_index, - std::vector &element_orders, - uint32_t &byte_stride, uint32_t &bit_stride); - - size_t ParseChildMembers(const lldb_private::SymbolContext &sc, - const DWARFDIE &die, - lldb_private::CompilerType &class_compiler_type); - - lldb_private::GoASTContext &m_ast; -}; - -#endif // SymbolFileDWARF_DWARFASTParserGo_h_ Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserGo.cpp @@ -1,772 +0,0 @@ -//===-- DWARFASTParserGo.cpp ---------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "DWARFASTParserGo.h" - -#include "DWARFASTParserGo.h" -#include "DWARFDIE.h" -#include "DWARFDIECollection.h" -#include "DWARFDebugInfo.h" -#include "DWARFDeclContext.h" -#include "DWARFDefines.h" -#include "SymbolFileDWARF.h" -#include "SymbolFileDWARFDebugMap.h" -#include "UniqueDWARFASTType.h" - -#include "clang/Basic/Specifiers.h" - -#include "lldb/Core/Module.h" -#include "lldb/Core/Value.h" -#include "lldb/Symbol/CompileUnit.h" -#include "lldb/Symbol/Function.h" -#include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/TypeList.h" - -//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN - -#ifdef ENABLE_DEBUG_PRINTF -#include -#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) -#else -#define DEBUG_PRINTF(fmt, ...) -#endif - -#define DW_AT_go_kind 0x2900 -#define DW_AT_go_key 0x2901 -#define DW_AT_go_elem 0x2902 - -using namespace lldb; -using namespace lldb_private; -DWARFASTParserGo::DWARFASTParserGo(GoASTContext &ast) : m_ast(ast) {} - -DWARFASTParserGo::~DWARFASTParserGo() {} - -TypeSP DWARFASTParserGo::ParseTypeFromDWARF( - const lldb_private::SymbolContext &sc, const DWARFDIE &die, - lldb_private::Log *log, bool *type_is_new_ptr) { - TypeSP type_sp; - - if (type_is_new_ptr) - *type_is_new_ptr = false; - - if (die) { - SymbolFileDWARF *dwarf = die.GetDWARF(); - if (log) { - dwarf->GetObjectFile()->GetModule()->LogMessage( - log, "DWARFASTParserGo::ParseTypeFromDWARF (die = 0x%8.8x) %s name = " - "'%s')", - die.GetOffset(), DW_TAG_value_to_name(die.Tag()), die.GetName()); - } - - Type *type_ptr = dwarf->m_die_to_type.lookup(die.GetDIE()); - TypeList *type_list = dwarf->GetTypeList(); - if (type_ptr == NULL) { - if (type_is_new_ptr) - *type_is_new_ptr = true; - - const dw_tag_t tag = die.Tag(); - - bool is_forward_declaration = false; - DWARFAttributes attributes; - const char *type_name_cstr = NULL; - ConstString type_name_const_str; - Type::ResolveState resolve_state = Type::eResolveStateUnresolved; - uint64_t byte_size = 0; - uint64_t go_kind = 0; - Declaration decl; - - Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; - CompilerType compiler_type; - DWARFFormValue form_value; - - dw_attr_t attr; - - switch (tag) { - case DW_TAG_base_type: - case DW_TAG_pointer_type: - case DW_TAG_typedef: - case DW_TAG_unspecified_type: { - // Set a bit that lets us know that we are currently parsing this - dwarf->m_die_to_type[die.GetDIE()] = DIE_IS_BEING_PARSED; - - const size_t num_attributes = die.GetAttributes(attributes); - lldb::user_id_t encoding_uid = LLDB_INVALID_UID; - - if (num_attributes > 0) { - uint32_t i; - for (i = 0; i < num_attributes; ++i) { - attr = attributes.AttributeAtIndex(i); - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_name: - type_name_cstr = form_value.AsCString(); - if (type_name_cstr) - type_name_const_str.SetCString(type_name_cstr); - break; - case DW_AT_byte_size: - byte_size = form_value.Unsigned(); - break; - case DW_AT_encoding: - // = form_value.Unsigned(); - break; - case DW_AT_type: - encoding_uid = form_value.Reference(); - break; - case DW_AT_go_kind: - go_kind = form_value.Unsigned(); - break; - default: - // Do we care about DW_AT_go_key or DW_AT_go_elem? - break; - } - } - } - } - - DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", - die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr, - encoding_uid); - - switch (tag) { - default: - break; - - case DW_TAG_unspecified_type: - resolve_state = Type::eResolveStateFull; - compiler_type = m_ast.CreateVoidType(type_name_const_str); - break; - - case DW_TAG_base_type: - resolve_state = Type::eResolveStateFull; - compiler_type = - m_ast.CreateBaseType(go_kind, type_name_const_str, byte_size); - break; - - case DW_TAG_pointer_type: - encoding_data_type = Type::eEncodingIsPointerUID; - break; - case DW_TAG_typedef: - encoding_data_type = Type::eEncodingIsTypedefUID; - CompilerType impl; - Type *type = dwarf->ResolveTypeUID(encoding_uid); - if (type) { - if (go_kind == 0 && type->GetName() == type_name_const_str) { - // Go emits extra typedefs as a forward declaration. Ignore - // these. - dwarf->m_die_to_type[die.GetDIE()] = type; - return type->shared_from_this(); - } - impl = type->GetForwardCompilerType(); - compiler_type = - m_ast.CreateTypedefType(go_kind, type_name_const_str, impl); - } - break; - } - - type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, - byte_size, NULL, encoding_uid, - encoding_data_type, &decl, compiler_type, - resolve_state)); - - dwarf->m_die_to_type[die.GetDIE()] = type_sp.get(); - } break; - - case DW_TAG_structure_type: { - // Set a bit that lets us know that we are currently parsing this - dwarf->m_die_to_type[die.GetDIE()] = DIE_IS_BEING_PARSED; - bool byte_size_valid = false; - - const size_t num_attributes = die.GetAttributes(attributes); - if (num_attributes > 0) { - uint32_t i; - for (i = 0; i < num_attributes; ++i) { - attr = attributes.AttributeAtIndex(i); - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_name: - type_name_cstr = form_value.AsCString(); - type_name_const_str.SetCString(type_name_cstr); - break; - - case DW_AT_byte_size: - byte_size = form_value.Unsigned(); - byte_size_valid = true; - break; - - case DW_AT_go_kind: - go_kind = form_value.Unsigned(); - break; - - // TODO: Should we use SLICETYPE's DW_AT_go_elem? - default: - break; - } - } - } - } - - // TODO(ribrdb): Do we need this? - - // UniqueDWARFASTType is large, so don't create a local variables on - // the stack, put it on the heap. This function is often called - // recursively and clang isn't good and sharing the stack space for - // variables in different blocks. - std::unique_ptr unique_ast_entry_ap( - new UniqueDWARFASTType()); - - // Only try and unique the type if it has a name. - if (type_name_const_str && - dwarf->GetUniqueDWARFASTTypeMap().Find( - type_name_const_str, die, decl, - byte_size_valid ? byte_size : -1, *unique_ast_entry_ap)) { - // We have already parsed this type or from another compile unit. GCC - // loves to use the "one definition rule" which can result in - // multiple definitions of the same class over and over in each - // compile unit. - type_sp = unique_ast_entry_ap->m_type_sp; - if (type_sp) { - dwarf->m_die_to_type[die.GetDIE()] = type_sp.get(); - return type_sp; - } - } - - DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), - DW_TAG_value_to_name(tag), type_name_cstr); - - bool compiler_type_was_created = false; - compiler_type.SetCompilerType( - &m_ast, - dwarf->m_forward_decl_die_to_clang_type.lookup(die.GetDIE())); - if (!compiler_type) { - compiler_type_was_created = true; - compiler_type = - m_ast.CreateStructType(go_kind, type_name_const_str, byte_size); - } - - type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, - byte_size, NULL, LLDB_INVALID_UID, - Type::eEncodingIsUID, &decl, compiler_type, - Type::eResolveStateForward)); - - // Add our type to the unique type map so we don't end up creating many - // copies of the same type over and over in the ASTContext for our - // module - unique_ast_entry_ap->m_type_sp = type_sp; - unique_ast_entry_ap->m_die = die; - unique_ast_entry_ap->m_declaration = decl; - unique_ast_entry_ap->m_byte_size = byte_size; - dwarf->GetUniqueDWARFASTTypeMap().Insert(type_name_const_str, - *unique_ast_entry_ap); - - if (!is_forward_declaration) { - // Always start the definition for a class type so that if the class - // has child classes or types that require the class to be created - // for use as their decl contexts the class will be ready to accept - // these child definitions. - if (die.HasChildren() == false) { - // No children for this struct/union/class, lets finish it - m_ast.CompleteStructType(compiler_type); - } else if (compiler_type_was_created) { - // Leave this as a forward declaration until we need to know the - // details of the type. lldb_private::Type will automatically call - // the SymbolFile virtual function - // "SymbolFileDWARF::CompleteType(Type *)" When the definition - // needs to be defined. - dwarf->m_forward_decl_die_to_clang_type[die.GetDIE()] = - compiler_type.GetOpaqueQualType(); - dwarf->m_forward_decl_clang_type_to_die[compiler_type - .GetOpaqueQualType()] = - die.GetDIERef(); - // SetHasExternalStorage (compiler_type.GetOpaqueQualType(), true); - } - } - } break; - - case DW_TAG_subprogram: - case DW_TAG_subroutine_type: { - // Set a bit that lets us know that we are currently parsing this - dwarf->m_die_to_type[die.GetDIE()] = DIE_IS_BEING_PARSED; - - bool is_variadic = false; - clang::StorageClass storage = - clang::SC_None; //, Extern, Static, PrivateExtern - - const size_t num_attributes = die.GetAttributes(attributes); - if (num_attributes > 0) { - uint32_t i; - for (i = 0; i < num_attributes; ++i) { - attr = attributes.AttributeAtIndex(i); - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_name: - type_name_cstr = form_value.AsCString(); - type_name_const_str.SetCString(type_name_cstr); - break; - - case DW_AT_external: - if (form_value.Unsigned()) { - if (storage == clang::SC_None) - storage = clang::SC_Extern; - else - storage = clang::SC_PrivateExtern; - } - break; - - case DW_AT_high_pc: - case DW_AT_low_pc: - break; - } - } - } - } - - DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), - DW_TAG_value_to_name(tag), type_name_cstr); - - std::vector function_param_types; - - // Parse the function children for the parameters - - if (die.HasChildren()) { - ParseChildParameters(sc, die, is_variadic, function_param_types); - } - - // compiler_type will get the function prototype clang type after this - // call - compiler_type = m_ast.CreateFunctionType( - type_name_const_str, function_param_types.data(), - function_param_types.size(), is_variadic); - - type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, 0, NULL, - LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, - compiler_type, Type::eResolveStateFull)); - assert(type_sp.get()); - } break; - - case DW_TAG_array_type: { - // Set a bit that lets us know that we are currently parsing this - dwarf->m_die_to_type[die.GetDIE()] = DIE_IS_BEING_PARSED; - - lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; - int64_t first_index = 0; - uint32_t byte_stride = 0; - uint32_t bit_stride = 0; - const size_t num_attributes = die.GetAttributes(attributes); - - if (num_attributes > 0) { - uint32_t i; - for (i = 0; i < num_attributes; ++i) { - attr = attributes.AttributeAtIndex(i); - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_name: - type_name_cstr = form_value.AsCString(); - type_name_const_str.SetCString(type_name_cstr); - break; - - case DW_AT_type: - type_die_offset = form_value.Reference(); - break; - case DW_AT_byte_size: - break; // byte_size = form_value.Unsigned(); break; - case DW_AT_go_kind: - go_kind = form_value.Unsigned(); - break; - default: - break; - } - } - } - - DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), - DW_TAG_value_to_name(tag), type_name_cstr); - - Type *element_type = dwarf->ResolveTypeUID(type_die_offset); - - if (element_type) { - std::vector element_orders; - ParseChildArrayInfo(sc, die, first_index, element_orders, - byte_stride, bit_stride); - if (byte_stride == 0) - byte_stride = element_type->GetByteSize(); - CompilerType array_element_type = - element_type->GetForwardCompilerType(); - if (element_orders.size() > 0) { - if (element_orders.size() > 1) - printf("golang: unsupported multi-dimensional array %s\n", - type_name_cstr); - compiler_type = m_ast.CreateArrayType( - type_name_const_str, array_element_type, element_orders[0]); - } else { - compiler_type = m_ast.CreateArrayType(type_name_const_str, - array_element_type, 0); - } - type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, - byte_stride, NULL, type_die_offset, - Type::eEncodingIsUID, &decl, compiler_type, - Type::eResolveStateFull)); - type_sp->SetEncodingType(element_type); - } - } - } break; - - default: - dwarf->GetObjectFile()->GetModule()->ReportError( - "{0x%8.8x}: unhandled type tag 0x%4.4x (%s), " - "please file a bug and attach the file at the " - "start of this error message", - die.GetOffset(), tag, DW_TAG_value_to_name(tag)); - break; - } - - if (type_sp.get()) { - DWARFDIE sc_parent_die = - SymbolFileDWARF::GetParentSymbolContextDIE(die); - dw_tag_t sc_parent_tag = sc_parent_die.Tag(); - - SymbolContextScope *symbol_context_scope = NULL; - if (sc_parent_tag == DW_TAG_compile_unit || - sc_parent_tag == DW_TAG_partial_unit) { - symbol_context_scope = sc.comp_unit; - } else if (sc.function != NULL && sc_parent_die) { - symbol_context_scope = - sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); - if (symbol_context_scope == NULL) - symbol_context_scope = sc.function; - } - - if (symbol_context_scope != NULL) { - type_sp->SetSymbolContextScope(symbol_context_scope); - } - - // We are ready to put this type into the uniqued list up at the module - // level - type_list->Insert(type_sp); - - dwarf->m_die_to_type[die.GetDIE()] = type_sp.get(); - } - } else if (type_ptr != DIE_IS_BEING_PARSED) { - type_sp = type_ptr->shared_from_this(); - } - } - return type_sp; -} - -size_t DWARFASTParserGo::ParseChildParameters( - const SymbolContext &sc, - - const DWARFDIE &parent_die, bool &is_variadic, - std::vector &function_param_types) { - if (!parent_die) - return 0; - - size_t arg_idx = 0; - for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); - die = die.GetSibling()) { - - dw_tag_t tag = die.Tag(); - switch (tag) { - case DW_TAG_formal_parameter: { - DWARFAttributes attributes; - const size_t num_attributes = die.GetAttributes(attributes); - if (num_attributes > 0) { - Declaration decl; - DWARFFormValue param_type_die_offset; - - uint32_t i; - for (i = 0; i < num_attributes; ++i) { - const dw_attr_t attr = attributes.AttributeAtIndex(i); - DWARFFormValue form_value; - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_name: - // = form_value.AsCString(); - break; - case DW_AT_type: - param_type_die_offset = form_value; - break; - case DW_AT_location: - // if (form_value.BlockData()) - // { - // const DWARFDataExtractor& - // debug_info_data = - // debug_info(); - // uint32_t block_length = - // form_value.Unsigned(); - // DWARFDataExtractor - // location(debug_info_data, - // form_value.BlockData() - - // debug_info_data.GetDataStart(), - // block_length); - // } - // else - // { - // } - // break; - default: - break; - } - } - } - - Type *type = parent_die.ResolveTypeUID(DIERef(param_type_die_offset)); - if (type) { - function_param_types.push_back(type->GetForwardCompilerType()); - } - } - arg_idx++; - } break; - - case DW_TAG_unspecified_parameters: - is_variadic = true; - break; - - default: - break; - } - } - return arg_idx; -} - -void DWARFASTParserGo::ParseChildArrayInfo( - const SymbolContext &sc, const DWARFDIE &parent_die, int64_t &first_index, - std::vector &element_orders, uint32_t &byte_stride, - uint32_t &bit_stride) { - if (!parent_die) - return; - - for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); - die = die.GetSibling()) { - const dw_tag_t tag = die.Tag(); - switch (tag) { - case DW_TAG_subrange_type: { - DWARFAttributes attributes; - const size_t num_child_attributes = die.GetAttributes(attributes); - if (num_child_attributes > 0) { - uint64_t num_elements = 0; - uint32_t i; - for (i = 0; i < num_child_attributes; ++i) { - const dw_attr_t attr = attributes.AttributeAtIndex(i); - DWARFFormValue form_value; - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_count: - num_elements = form_value.Unsigned(); - break; - - default: - case DW_AT_type: - break; - } - } - } - - element_orders.push_back(num_elements); - } - } break; - } - } -} - -bool DWARFASTParserGo::CompleteTypeFromDWARF(const DWARFDIE &die, - lldb_private::Type *type, - CompilerType &compiler_type) { - if (!die) - return false; - - const dw_tag_t tag = die.Tag(); - - SymbolFileDWARF *dwarf = die.GetDWARF(); - Log *log = - nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); - if (log) - dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace( - log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", - die.GetID(), DW_TAG_value_to_name(tag), type->GetName().AsCString()); - assert(compiler_type); - DWARFAttributes attributes; - - switch (tag) { - case DW_TAG_structure_type: { - { - if (die.HasChildren()) { - SymbolContext sc(die.GetLLDBCompileUnit()); - - ParseChildMembers(sc, die, compiler_type); - } - } - m_ast.CompleteStructType(compiler_type); - return (bool)compiler_type; - } - - default: - assert(false && "not a forward go type decl!"); - break; - } - - return false; -} - -size_t DWARFASTParserGo::ParseChildMembers(const SymbolContext &sc, - const DWARFDIE &parent_die, - CompilerType &class_compiler_type) { - size_t count = 0; - uint32_t member_idx = 0; - - ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule(); - GoASTContext *ast = - llvm::dyn_cast_or_null(class_compiler_type.GetTypeSystem()); - if (ast == nullptr) - return 0; - - for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); - die = die.GetSibling()) { - dw_tag_t tag = die.Tag(); - - switch (tag) { - case DW_TAG_member: { - DWARFAttributes attributes; - const size_t num_attributes = die.GetAttributes(attributes); - if (num_attributes > 0) { - Declaration decl; - const char *name = NULL; - - DWARFFormValue encoding_uid; - uint32_t member_byte_offset = UINT32_MAX; - uint32_t i; - for (i = 0; i < num_attributes; ++i) { - const dw_attr_t attr = attributes.AttributeAtIndex(i); - DWARFFormValue form_value; - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_name: - name = form_value.AsCString(); - break; - case DW_AT_type: - encoding_uid = form_value; - break; - case DW_AT_data_member_location: - if (form_value.BlockData()) { - Value initialValue(0); - Value memberOffset(0); - const DWARFDataExtractor &debug_info_data = die.GetData(); - uint32_t block_length = form_value.Unsigned(); - uint32_t block_offset = - form_value.BlockData() - debug_info_data.GetDataStart(); - if (DWARFExpression::Evaluate( - NULL, // ExecutionContext * - NULL, // RegisterContext * - module_sp, debug_info_data, die.GetCU(), block_offset, - block_length, eRegisterKindDWARF, &initialValue, NULL, - memberOffset, NULL)) { - member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); - } - } else { - // With DWARF 3 and later, if the value is an integer constant, - // this form value is the offset in bytes from the beginning of - // the containing entity. - member_byte_offset = form_value.Unsigned(); - } - break; - - default: - break; - } - } - } - - Type *member_type = die.ResolveTypeUID(DIERef(encoding_uid)); - if (member_type) { - CompilerType member_go_type = member_type->GetFullCompilerType(); - ConstString name_const_str(name); - m_ast.AddFieldToStruct(class_compiler_type, name_const_str, - member_go_type, member_byte_offset); - } - } - ++member_idx; - } break; - - default: - break; - } - } - - return count; -} - -Function *DWARFASTParserGo::ParseFunctionFromDWARF(const SymbolContext &sc, - const DWARFDIE &die) { - DWARFRangeList func_ranges; - const char *name = NULL; - const char *mangled = NULL; - int decl_file = 0; - int decl_line = 0; - int decl_column = 0; - int call_file = 0; - int call_line = 0; - int call_column = 0; - DWARFExpression frame_base(die.GetCU()); - - assert(die.Tag() == DW_TAG_subprogram); - - if (die.Tag() != DW_TAG_subprogram) - return NULL; - - if (die.GetDIENamesAndRanges(name, mangled, func_ranges, decl_file, decl_line, - decl_column, call_file, call_line, call_column, - &frame_base)) { - // Union of all ranges in the function DIE (if the function is - // discontiguous) - AddressRange func_range; - lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase(0); - lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd(0); - if (lowest_func_addr != LLDB_INVALID_ADDRESS && - lowest_func_addr <= highest_func_addr) { - ModuleSP module_sp(die.GetModule()); - func_range.GetBaseAddress().ResolveAddressUsingFileSections( - lowest_func_addr, module_sp->GetSectionList()); - if (func_range.GetBaseAddress().IsValid()) - func_range.SetByteSize(highest_func_addr - lowest_func_addr); - } - - if (func_range.GetBaseAddress().IsValid()) { - Mangled func_name; - func_name.SetValue(ConstString(name), false); - - FunctionSP func_sp; - std::unique_ptr decl_ap; - if (decl_file != 0 || decl_line != 0 || decl_column != 0) - decl_ap.reset(new Declaration( - sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), - decl_line, decl_column)); - - SymbolFileDWARF *dwarf = die.GetDWARF(); - // Supply the type _only_ if it has already been parsed - Type *func_type = dwarf->m_die_to_type.lookup(die.GetDIE()); - - assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); - - if (dwarf->FixupAddress(func_range.GetBaseAddress())) { - const user_id_t func_user_id = die.GetID(); - func_sp.reset(new Function(sc.comp_unit, - func_user_id, // UserID is the DIE offset - func_user_id, func_name, func_type, - func_range)); // first address range - - if (func_sp.get() != NULL) { - if (frame_base.IsValid()) - func_sp->GetFrameBaseExpression() = frame_base; - sc.comp_unit->AddFunction(func_sp); - return func_sp.get(); - } - } - } - } - return NULL; -} Index: lldb/trunk/source/Symbol/CMakeLists.txt =================================================================== --- lldb/trunk/source/Symbol/CMakeLists.txt +++ lldb/trunk/source/Symbol/CMakeLists.txt @@ -16,7 +16,6 @@ DWARFCallFrameInfo.cpp Function.cpp FuncUnwinders.cpp - GoASTContext.cpp JavaASTContext.cpp LineEntry.cpp LineTable.cpp @@ -29,7 +28,7 @@ Symtab.cpp Type.cpp TypeList.cpp - TypeMap.cpp + TypeMap.cpp TypeSystem.cpp UnwindPlan.cpp UnwindTable.cpp @@ -47,7 +46,6 @@ lldbTarget lldbUtility lldbPluginExpressionParserClang - lldbPluginExpressionParserGo lldbPluginSymbolFileDWARF lldbPluginSymbolFilePDB lldbPluginCPlusPlusLanguage Index: lldb/trunk/source/Symbol/GoASTContext.cpp =================================================================== --- lldb/trunk/source/Symbol/GoASTContext.cpp +++ lldb/trunk/source/Symbol/GoASTContext.cpp @@ -1,1444 +0,0 @@ -//===-- GoASTContext.cpp ----------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include -#include -#include - -#include "lldb/Core/DumpDataExtractor.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamFile.h" -#include "lldb/Core/UniqueCStringMap.h" -#include "lldb/Core/ValueObject.h" -#include "lldb/Symbol/CompilerType.h" -#include "lldb/Symbol/GoASTContext.h" -#include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/SymbolFile.h" -#include "lldb/Symbol/Type.h" -#include "lldb/Target/ExecutionContext.h" -#include "lldb/Target/Target.h" - -#include "llvm/Support/Threading.h" - -#include "Plugins/ExpressionParser/Go/GoUserExpression.h" -#include "Plugins/SymbolFile/DWARF/DWARFASTParserGo.h" - -using namespace lldb; - -namespace lldb_private { -class GoArray; -class GoFunction; -class GoStruct; - -class GoType { -public: - enum { - KIND_BOOL = 1, - KIND_INT = 2, - KIND_INT8 = 3, - KIND_INT16 = 4, - KIND_INT32 = 5, - KIND_INT64 = 6, - KIND_UINT = 7, - KIND_UINT8 = 8, - KIND_UINT16 = 9, - KIND_UINT32 = 10, - KIND_UINT64 = 11, - KIND_UINTPTR = 12, - KIND_FLOAT32 = 13, - KIND_FLOAT64 = 14, - KIND_COMPLEX64 = 15, - KIND_COMPLEX128 = 16, - KIND_ARRAY = 17, - KIND_CHAN = 18, - KIND_FUNC = 19, - KIND_INTERFACE = 20, - KIND_MAP = 21, - KIND_PTR = 22, - KIND_SLICE = 23, - KIND_STRING = 24, - KIND_STRUCT = 25, - KIND_UNSAFEPOINTER = 26, - KIND_LLDB_VOID, // Extension for LLDB, not used by go runtime. - KIND_MASK = (1 << 5) - 1, - KIND_DIRECT_IFACE = 1 << 5 - }; - GoType(int kind, const ConstString &name) - : m_kind(kind & KIND_MASK), m_name(name) { - if (m_kind == KIND_FUNC) - m_kind = KIND_FUNC; - } - virtual ~GoType() {} - - int GetGoKind() const { return m_kind; } - const ConstString &GetName() const { return m_name; } - virtual CompilerType GetElementType() const { return CompilerType(); } - - bool IsTypedef() const { - switch (m_kind) { - case KIND_CHAN: - case KIND_MAP: - case KIND_INTERFACE: - return true; - default: - return false; - } - } - - GoArray *GetArray(); - GoFunction *GetFunction(); - GoStruct *GetStruct(); - -private: - int m_kind; - ConstString m_name; - GoType(const GoType &) = delete; - const GoType &operator=(const GoType &) = delete; -}; - -class GoElem : public GoType { -public: - GoElem(int kind, const ConstString &name, const CompilerType &elem) - : GoType(kind, name), m_elem(elem) {} - virtual CompilerType GetElementType() const { return m_elem; } - -private: - // TODO: should we store this differently? - CompilerType m_elem; - - GoElem(const GoElem &) = delete; - const GoElem &operator=(const GoElem &) = delete; -}; - -class GoArray : public GoElem { -public: - GoArray(const ConstString &name, uint64_t length, const CompilerType &elem) - : GoElem(KIND_ARRAY, name, elem), m_length(length) {} - - uint64_t GetLength() const { return m_length; } - -private: - uint64_t m_length; - GoArray(const GoArray &) = delete; - const GoArray &operator=(const GoArray &) = delete; -}; - -class GoFunction : public GoType { -public: - GoFunction(const ConstString &name, bool is_variadic) - : GoType(KIND_FUNC, name), m_is_variadic(is_variadic) {} - - bool IsVariadic() const { return m_is_variadic; } - -private: - bool m_is_variadic; - GoFunction(const GoFunction &) = delete; - const GoFunction &operator=(const GoFunction &) = delete; -}; - -class GoStruct : public GoType { -public: - struct Field { - Field(const ConstString &name, const CompilerType &type, uint64_t offset) - : m_name(name), m_type(type), m_byte_offset(offset) {} - ConstString m_name; - CompilerType m_type; - uint64_t m_byte_offset; - }; - - GoStruct(int kind, const ConstString &name, int64_t byte_size) - : GoType(kind == 0 ? KIND_STRUCT : kind, name), m_is_complete(false), - m_byte_size(byte_size) {} - - uint32_t GetNumFields() const { return m_fields.size(); } - - const Field *GetField(uint32_t i) const { - if (i < m_fields.size()) - return &m_fields[i]; - return nullptr; - } - - void AddField(const ConstString &name, const CompilerType &type, - uint64_t offset) { - m_fields.push_back(Field(name, type, offset)); - } - - bool IsComplete() const { return m_is_complete; } - - void SetComplete() { m_is_complete = true; } - - int64_t GetByteSize() const { return m_byte_size; } - -private: - bool m_is_complete; - int64_t m_byte_size; - std::vector m_fields; - - GoStruct(const GoStruct &) = delete; - const GoStruct &operator=(const GoStruct &) = delete; -}; - -GoArray *GoType::GetArray() { - if (m_kind == KIND_ARRAY) { - return static_cast(this); - } - return nullptr; -} - -GoFunction *GoType::GetFunction() { - if (m_kind == KIND_FUNC) { - return static_cast(this); - } - return nullptr; -} - -GoStruct *GoType::GetStruct() { - switch (m_kind) { - case KIND_STRING: - case KIND_STRUCT: - case KIND_SLICE: - return static_cast(this); - } - return nullptr; -} -} // namespace lldb_private -using namespace lldb_private; - -GoASTContext::GoASTContext() - : TypeSystem(eKindGo), m_pointer_byte_size(0), m_int_byte_size(0), - m_types(new TypeMap) {} -GoASTContext::~GoASTContext() {} - -//------------------------------------------------------------------ -// PluginInterface functions -//------------------------------------------------------------------ - -ConstString GoASTContext::GetPluginNameStatic() { return ConstString("go"); } - -ConstString GoASTContext::GetPluginName() { - return GoASTContext::GetPluginNameStatic(); -} - -uint32_t GoASTContext::GetPluginVersion() { return 1; } - -lldb::TypeSystemSP GoASTContext::CreateInstance(lldb::LanguageType language, - Module *module, - Target *target) { - if (language == eLanguageTypeGo) { - ArchSpec arch; - std::shared_ptr go_ast_sp; - if (module) { - arch = module->GetArchitecture(); - go_ast_sp = std::shared_ptr(new GoASTContext); - } else if (target) { - arch = target->GetArchitecture(); - go_ast_sp = std::shared_ptr( - new GoASTContextForExpr(target->shared_from_this())); - } - - if (arch.IsValid()) { - go_ast_sp->SetAddressByteSize(arch.GetAddressByteSize()); - return go_ast_sp; - } - } - return lldb::TypeSystemSP(); -} - -void GoASTContext::EnumerateSupportedLanguages( - std::set &languages_for_types, - std::set &languages_for_expressions) { - static std::vector s_supported_languages_for_types( - {lldb::eLanguageTypeGo}); - - static std::vector s_supported_languages_for_expressions( - {}); - - languages_for_types.insert(s_supported_languages_for_types.begin(), - s_supported_languages_for_types.end()); - languages_for_expressions.insert( - s_supported_languages_for_expressions.begin(), - s_supported_languages_for_expressions.end()); -} - -void GoASTContext::Initialize() { - PluginManager::RegisterPlugin(GetPluginNameStatic(), "AST context plug-in", - CreateInstance, EnumerateSupportedLanguages); -} - -void GoASTContext::Terminate() { - PluginManager::UnregisterPlugin(CreateInstance); -} - -//---------------------------------------------------------------------- -// Tests -//---------------------------------------------------------------------- - -bool GoASTContext::IsArrayType(lldb::opaque_compiler_type_t type, - CompilerType *element_type, uint64_t *size, - bool *is_incomplete) { - if (element_type) - element_type->Clear(); - if (size) - *size = 0; - if (is_incomplete) - *is_incomplete = false; - GoArray *array = static_cast(type)->GetArray(); - if (array) { - if (size) - *size = array->GetLength(); - if (element_type) - *element_type = array->GetElementType(); - return true; - } - return false; -} - -bool GoASTContext::IsVectorType(lldb::opaque_compiler_type_t type, - CompilerType *element_type, uint64_t *size) { - if (element_type) - element_type->Clear(); - if (size) - *size = 0; - return false; -} - -bool GoASTContext::IsAggregateType(lldb::opaque_compiler_type_t type) { - int kind = static_cast(type)->GetGoKind(); - if (kind < GoType::KIND_ARRAY) - return false; - if (kind == GoType::KIND_PTR) - return false; - if (kind == GoType::KIND_CHAN) - return false; - if (kind == GoType::KIND_MAP) - return false; - if (kind == GoType::KIND_STRING) - return false; - if (kind == GoType::KIND_UNSAFEPOINTER) - return false; - return true; -} - -bool GoASTContext::IsBeingDefined(lldb::opaque_compiler_type_t type) { - return false; -} - -bool GoASTContext::IsCharType(lldb::opaque_compiler_type_t type) { - // Go's DWARF doesn't distinguish between rune and int32. - return false; -} - -bool GoASTContext::IsCompleteType(lldb::opaque_compiler_type_t type) { - if (!type) - return false; - GoType *t = static_cast(type); - if (GoStruct *s = t->GetStruct()) - return s->IsComplete(); - if (t->IsTypedef() || t->GetGoKind() == GoType::KIND_PTR) - return t->GetElementType().IsCompleteType(); - return true; -} - -bool GoASTContext::IsConst(lldb::opaque_compiler_type_t type) { return false; } - -bool GoASTContext::IsCStringType(lldb::opaque_compiler_type_t type, - uint32_t &length) { - return false; -} - -bool GoASTContext::IsDefined(lldb::opaque_compiler_type_t type) { - return type != nullptr; -} - -bool GoASTContext::IsFloatingPointType(lldb::opaque_compiler_type_t type, - uint32_t &count, bool &is_complex) { - int kind = static_cast(type)->GetGoKind(); - if (kind >= GoType::KIND_FLOAT32 && kind <= GoType::KIND_COMPLEX128) { - if (kind >= GoType::KIND_COMPLEX64) { - is_complex = true; - count = 2; - } else { - is_complex = false; - count = 1; - } - return true; - } - count = 0; - is_complex = false; - return false; -} - -bool GoASTContext::IsFunctionType(lldb::opaque_compiler_type_t type, - bool *is_variadic_ptr) { - GoFunction *func = static_cast(type)->GetFunction(); - if (func) { - if (is_variadic_ptr) - *is_variadic_ptr = func->IsVariadic(); - return true; - } - if (is_variadic_ptr) - *is_variadic_ptr = false; - return false; -} - -uint32_t GoASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, - CompilerType *base_type_ptr) { - return false; -} - -size_t -GoASTContext::GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) { - return 0; -} - -CompilerType -GoASTContext::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, - const size_t index) { - return CompilerType(); -} - -bool GoASTContext::IsFunctionPointerType(lldb::opaque_compiler_type_t type) { - return IsFunctionType(type); -} - -bool GoASTContext::IsBlockPointerType(lldb::opaque_compiler_type_t type, - CompilerType *function_pointer_type_ptr) { - return false; -} - -bool GoASTContext::IsIntegerType(lldb::opaque_compiler_type_t type, - bool &is_signed) { - is_signed = false; - // TODO: Is bool an integer? - if (type) { - int kind = static_cast(type)->GetGoKind(); - if (kind <= GoType::KIND_UINTPTR) { - is_signed = (kind != GoType::KIND_BOOL) & (kind <= GoType::KIND_INT64); - return true; - } - } - return false; -} - -bool GoASTContext::IsPolymorphicClass(lldb::opaque_compiler_type_t type) { - return false; -} - -bool GoASTContext::IsPossibleDynamicType( - lldb::opaque_compiler_type_t type, - CompilerType *target_type, // Can pass NULL - bool check_cplusplus, bool check_objc) { - if (target_type) - target_type->Clear(); - if (type) - return static_cast(type)->GetGoKind() == GoType::KIND_INTERFACE; - return false; -} - -bool GoASTContext::IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) { - return false; -} - -bool GoASTContext::IsPointerType(lldb::opaque_compiler_type_t type, - CompilerType *pointee_type) { - if (!type) - return false; - GoType *t = static_cast(type); - if (pointee_type) { - *pointee_type = t->GetElementType(); - } - switch (t->GetGoKind()) { - case GoType::KIND_PTR: - case GoType::KIND_UNSAFEPOINTER: - case GoType::KIND_CHAN: - case GoType::KIND_MAP: - // TODO: is function a pointer? - return true; - default: - return false; - } -} - -bool GoASTContext::IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, - CompilerType *pointee_type) { - return IsPointerType(type, pointee_type); -} - -bool GoASTContext::IsReferenceType(lldb::opaque_compiler_type_t type, - CompilerType *pointee_type, - bool *is_rvalue) { - return false; -} - -bool GoASTContext::IsScalarType(lldb::opaque_compiler_type_t type) { - return !IsAggregateType(type); -} - -bool GoASTContext::IsTypedefType(lldb::opaque_compiler_type_t type) { - if (type) - return static_cast(type)->IsTypedef(); - return false; -} - -bool GoASTContext::IsVoidType(lldb::opaque_compiler_type_t type) { - if (!type) - return false; - return static_cast(type)->GetGoKind() == GoType::KIND_LLDB_VOID; -} - -bool GoASTContext::SupportsLanguage(lldb::LanguageType language) { - return language == eLanguageTypeGo; -} - -//---------------------------------------------------------------------- -// Type Completion -//---------------------------------------------------------------------- - -bool GoASTContext::GetCompleteType(lldb::opaque_compiler_type_t type) { - if (!type) - return false; - GoType *t = static_cast(type); - if (t->IsTypedef() || t->GetGoKind() == GoType::KIND_PTR || t->GetArray()) - return t->GetElementType().GetCompleteType(); - if (GoStruct *s = t->GetStruct()) { - if (s->IsComplete()) - return true; - CompilerType compiler_type(this, s); - SymbolFile *symbols = GetSymbolFile(); - return symbols && symbols->CompleteType(compiler_type); - } - return true; -} - -//---------------------------------------------------------------------- -// AST related queries -//---------------------------------------------------------------------- - -uint32_t GoASTContext::GetPointerByteSize() { return m_pointer_byte_size; } - -//---------------------------------------------------------------------- -// Accessors -//---------------------------------------------------------------------- - -ConstString GoASTContext::GetTypeName(lldb::opaque_compiler_type_t type) { - if (type) - return static_cast(type)->GetName(); - return ConstString(); -} - -uint32_t -GoASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type, - CompilerType *pointee_or_element_compiler_type) { - if (pointee_or_element_compiler_type) - pointee_or_element_compiler_type->Clear(); - if (!type) - return 0; - GoType *t = static_cast(type); - if (pointee_or_element_compiler_type) - *pointee_or_element_compiler_type = t->GetElementType(); - int kind = t->GetGoKind(); - if (kind == GoType::KIND_ARRAY) - return eTypeHasChildren | eTypeIsArray; - if (kind < GoType::KIND_ARRAY) { - uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue; - if (kind < GoType::KIND_FLOAT32) { - builtin_type_flags |= eTypeIsInteger | eTypeIsScalar; - if (kind >= GoType::KIND_INT && kind <= GoType::KIND_INT64) - builtin_type_flags |= eTypeIsSigned; - } else { - builtin_type_flags |= eTypeIsFloat; - if (kind < GoType::KIND_COMPLEX64) - builtin_type_flags |= eTypeIsComplex; - else - builtin_type_flags |= eTypeIsScalar; - } - return builtin_type_flags; - } - if (kind == GoType::KIND_STRING) - return eTypeHasValue | eTypeIsBuiltIn; - if (kind == GoType::KIND_FUNC) - return eTypeIsFuncPrototype | eTypeHasValue; - if (IsPointerType(type)) - return eTypeIsPointer | eTypeHasValue | eTypeHasChildren; - if (kind == GoType::KIND_LLDB_VOID) - return 0; - return eTypeHasChildren | eTypeIsStructUnion; -} - -lldb::TypeClass GoASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) { - if (!type) - return eTypeClassInvalid; - int kind = static_cast(type)->GetGoKind(); - if (kind == GoType::KIND_FUNC) - return eTypeClassFunction; - if (IsPointerType(type)) - return eTypeClassPointer; - if (kind < GoType::KIND_COMPLEX64) - return eTypeClassBuiltin; - if (kind <= GoType::KIND_COMPLEX128) - return eTypeClassComplexFloat; - if (kind == GoType::KIND_LLDB_VOID) - return eTypeClassInvalid; - return eTypeClassStruct; -} - -lldb::BasicType -GoASTContext::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) { - ConstString name = GetTypeName(type); - if (name) { - typedef UniqueCStringMap TypeNameToBasicTypeMap; - static TypeNameToBasicTypeMap g_type_map; - static llvm::once_flag g_once_flag; - llvm::call_once(g_once_flag, []() { - // "void" - g_type_map.Append(ConstString("void"), eBasicTypeVoid); - // "int" - g_type_map.Append(ConstString("int"), eBasicTypeInt); - g_type_map.Append(ConstString("uint"), eBasicTypeUnsignedInt); - - // Miscellaneous - g_type_map.Append(ConstString("bool"), eBasicTypeBool); - - // Others. Should these map to C types? - g_type_map.Append(ConstString("byte"), eBasicTypeOther); - g_type_map.Append(ConstString("uint8"), eBasicTypeOther); - g_type_map.Append(ConstString("uint16"), eBasicTypeOther); - g_type_map.Append(ConstString("uint32"), eBasicTypeOther); - g_type_map.Append(ConstString("uint64"), eBasicTypeOther); - g_type_map.Append(ConstString("int8"), eBasicTypeOther); - g_type_map.Append(ConstString("int16"), eBasicTypeOther); - g_type_map.Append(ConstString("int32"), eBasicTypeOther); - g_type_map.Append(ConstString("int64"), eBasicTypeOther); - g_type_map.Append(ConstString("float32"), eBasicTypeOther); - g_type_map.Append(ConstString("float64"), eBasicTypeOther); - g_type_map.Append(ConstString("uintptr"), eBasicTypeOther); - - g_type_map.Sort(); - }); - - return g_type_map.Find(name, eBasicTypeInvalid); - } - return eBasicTypeInvalid; -} - -lldb::LanguageType -GoASTContext::GetMinimumLanguage(lldb::opaque_compiler_type_t type) { - return lldb::eLanguageTypeGo; -} - -unsigned GoASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type) { - return 0; -} - -//---------------------------------------------------------------------- -// Creating related types -//---------------------------------------------------------------------- - -CompilerType -GoASTContext::GetArrayElementType(lldb::opaque_compiler_type_t type, - uint64_t *stride) { - GoArray *array = static_cast(type)->GetArray(); - if (array) { - if (stride) { - *stride = array->GetElementType().GetByteSize(nullptr); - } - return array->GetElementType(); - } - return CompilerType(); -} - -CompilerType GoASTContext::GetCanonicalType(lldb::opaque_compiler_type_t type) { - GoType *t = static_cast(type); - if (t->IsTypedef()) - return t->GetElementType(); - return CompilerType(this, type); -} - -CompilerType -GoASTContext::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) { - return CompilerType(this, type); -} - -// Returns -1 if this isn't a function of if the function doesn't have a -// prototype Returns a value >= 0 if there is a prototype. -int GoASTContext::GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) { - return GetNumberOfFunctionArguments(type); -} - -CompilerType -GoASTContext::GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, - size_t idx) { - return GetFunctionArgumentAtIndex(type, idx); -} - -CompilerType -GoASTContext::GetFunctionReturnType(lldb::opaque_compiler_type_t type) { - CompilerType result; - if (type) { - GoType *t = static_cast(type); - if (t->GetGoKind() == GoType::KIND_FUNC) - result = t->GetElementType(); - } - return result; -} - -size_t GoASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) { - return 0; -} - -TypeMemberFunctionImpl -GoASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, - size_t idx) { - return TypeMemberFunctionImpl(); -} - -CompilerType -GoASTContext::GetNonReferenceType(lldb::opaque_compiler_type_t type) { - return CompilerType(this, type); -} - -CompilerType GoASTContext::GetPointeeType(lldb::opaque_compiler_type_t type) { - if (!type) - return CompilerType(); - return static_cast(type)->GetElementType(); -} - -CompilerType GoASTContext::GetPointerType(lldb::opaque_compiler_type_t type) { - if (!type) - return CompilerType(); - ConstString type_name = GetTypeName(type); - ConstString pointer_name(std::string("*") + type_name.GetCString()); - GoType *pointer = (*m_types)[pointer_name].get(); - if (pointer == nullptr) { - pointer = - new GoElem(GoType::KIND_PTR, pointer_name, CompilerType(this, type)); - (*m_types)[pointer_name].reset(pointer); - } - return CompilerType(this, pointer); -} - -// If the current object represents a typedef type, get the underlying type -CompilerType GoASTContext::GetTypedefedType(lldb::opaque_compiler_type_t type) { - if (IsTypedefType(type)) - return static_cast(type)->GetElementType(); - return CompilerType(); -} - -//---------------------------------------------------------------------- -// Create related types using the current type's AST -//---------------------------------------------------------------------- -CompilerType GoASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type) { - return CompilerType(); -} - -CompilerType -GoASTContext::GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, - size_t bit_size) { - return CompilerType(); -} - -//---------------------------------------------------------------------- -// Exploring the type -//---------------------------------------------------------------------- - -uint64_t GoASTContext::GetBitSize(lldb::opaque_compiler_type_t type, - ExecutionContextScope *exe_scope) { - if (!type) - return 0; - if (!GetCompleteType(type)) - return 0; - GoType *t = static_cast(type); - GoArray *array = nullptr; - switch (t->GetGoKind()) { - case GoType::KIND_BOOL: - case GoType::KIND_INT8: - case GoType::KIND_UINT8: - return 8; - case GoType::KIND_INT16: - case GoType::KIND_UINT16: - return 16; - case GoType::KIND_INT32: - case GoType::KIND_UINT32: - case GoType::KIND_FLOAT32: - return 32; - case GoType::KIND_INT64: - case GoType::KIND_UINT64: - case GoType::KIND_FLOAT64: - case GoType::KIND_COMPLEX64: - return 64; - case GoType::KIND_COMPLEX128: - return 128; - case GoType::KIND_INT: - case GoType::KIND_UINT: - return m_int_byte_size * 8; - case GoType::KIND_UINTPTR: - case GoType::KIND_FUNC: // I assume this is a pointer? - case GoType::KIND_CHAN: - case GoType::KIND_PTR: - case GoType::KIND_UNSAFEPOINTER: - case GoType::KIND_MAP: - return m_pointer_byte_size * 8; - case GoType::KIND_ARRAY: - array = t->GetArray(); - return array->GetLength() * array->GetElementType().GetBitSize(exe_scope); - case GoType::KIND_INTERFACE: - return t->GetElementType().GetBitSize(exe_scope); - case GoType::KIND_SLICE: - case GoType::KIND_STRING: - case GoType::KIND_STRUCT: - return t->GetStruct()->GetByteSize() * 8; - default: - assert(false); - } - return 0; -} - -lldb::Encoding GoASTContext::GetEncoding(lldb::opaque_compiler_type_t type, - uint64_t &count) { - count = 1; - bool is_signed; - if (IsIntegerType(type, is_signed)) - return is_signed ? lldb::eEncodingSint : eEncodingUint; - bool is_complex; - uint32_t complex_count; - if (IsFloatingPointType(type, complex_count, is_complex)) { - count = complex_count; - return eEncodingIEEE754; - } - if (IsPointerType(type)) - return eEncodingUint; - return eEncodingInvalid; -} - -lldb::Format GoASTContext::GetFormat(lldb::opaque_compiler_type_t type) { - if (!type) - return eFormatDefault; - switch (static_cast(type)->GetGoKind()) { - case GoType::KIND_BOOL: - return eFormatBoolean; - case GoType::KIND_INT: - case GoType::KIND_INT8: - case GoType::KIND_INT16: - case GoType::KIND_INT32: - case GoType::KIND_INT64: - return eFormatDecimal; - case GoType::KIND_UINT: - case GoType::KIND_UINT8: - case GoType::KIND_UINT16: - case GoType::KIND_UINT32: - case GoType::KIND_UINT64: - return eFormatUnsigned; - case GoType::KIND_FLOAT32: - case GoType::KIND_FLOAT64: - return eFormatFloat; - case GoType::KIND_COMPLEX64: - case GoType::KIND_COMPLEX128: - return eFormatComplexFloat; - case GoType::KIND_UINTPTR: - case GoType::KIND_CHAN: - case GoType::KIND_PTR: - case GoType::KIND_MAP: - case GoType::KIND_UNSAFEPOINTER: - return eFormatHex; - case GoType::KIND_STRING: - return eFormatCString; - case GoType::KIND_ARRAY: - case GoType::KIND_INTERFACE: - case GoType::KIND_SLICE: - case GoType::KIND_STRUCT: - default: - // Don't know how to display this. - return eFormatBytes; - } -} - -size_t GoASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type) { - return 0; -} - -uint32_t GoASTContext::GetNumChildren(lldb::opaque_compiler_type_t type, - bool omit_empty_base_classes) { - if (!type || !GetCompleteType(type)) - return 0; - GoType *t = static_cast(type); - if (t->GetGoKind() == GoType::KIND_PTR) { - CompilerType elem = t->GetElementType(); - if (elem.IsAggregateType()) - return elem.GetNumChildren(omit_empty_base_classes); - return 1; - } else if (GoArray *array = t->GetArray()) { - return array->GetLength(); - } else if (t->IsTypedef()) { - return t->GetElementType().GetNumChildren(omit_empty_base_classes); - } - - return GetNumFields(type); -} - -uint32_t GoASTContext::GetNumFields(lldb::opaque_compiler_type_t type) { - if (!type || !GetCompleteType(type)) - return 0; - GoType *t = static_cast(type); - if (t->IsTypedef()) - return t->GetElementType().GetNumFields(); - GoStruct *s = t->GetStruct(); - if (s) - return s->GetNumFields(); - return 0; -} - -CompilerType GoASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type, - size_t idx, std::string &name, - uint64_t *bit_offset_ptr, - uint32_t *bitfield_bit_size_ptr, - bool *is_bitfield_ptr) { - if (bit_offset_ptr) - *bit_offset_ptr = 0; - if (bitfield_bit_size_ptr) - *bitfield_bit_size_ptr = 0; - if (is_bitfield_ptr) - *is_bitfield_ptr = false; - - if (!type || !GetCompleteType(type)) - return CompilerType(); - - GoType *t = static_cast(type); - if (t->IsTypedef()) - return t->GetElementType().GetFieldAtIndex( - idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr); - - GoStruct *s = t->GetStruct(); - if (s) { - const auto *field = s->GetField(idx); - if (field) { - name = field->m_name.GetStringRef(); - if (bit_offset_ptr) - *bit_offset_ptr = field->m_byte_offset * 8; - return field->m_type; - } - } - return CompilerType(); -} - -CompilerType GoASTContext::GetChildCompilerTypeAtIndex( - lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, - bool transparent_pointers, bool omit_empty_base_classes, - bool ignore_array_bounds, std::string &child_name, - uint32_t &child_byte_size, int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class, bool &child_is_deref_of_parent, - ValueObject *valobj, uint64_t &language_flags) { - child_name.clear(); - child_byte_size = 0; - child_byte_offset = 0; - child_bitfield_bit_size = 0; - child_bitfield_bit_offset = 0; - child_is_base_class = false; - child_is_deref_of_parent = false; - language_flags = 0; - - if (!type || !GetCompleteType(type)) - return CompilerType(); - - GoType *t = static_cast(type); - if (t->GetStruct()) { - uint64_t bit_offset; - CompilerType ret = - GetFieldAtIndex(type, idx, child_name, &bit_offset, nullptr, nullptr); - child_byte_size = ret.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr); - child_byte_offset = bit_offset / 8; - return ret; - } else if (t->GetGoKind() == GoType::KIND_PTR) { - CompilerType pointee = t->GetElementType(); - if (!pointee.IsValid() || pointee.IsVoidType()) - return CompilerType(); - if (transparent_pointers && pointee.IsAggregateType()) { - bool tmp_child_is_deref_of_parent = false; - return pointee.GetChildCompilerTypeAtIndex( - exe_ctx, idx, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name, child_byte_size, child_byte_offset, - child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class, tmp_child_is_deref_of_parent, valobj, - language_flags); - } else { - child_is_deref_of_parent = true; - const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; - if (parent_name) { - child_name.assign(1, '*'); - child_name += parent_name; - } - - // We have a pointer to an simple type - if (idx == 0 && pointee.GetCompleteType()) { - child_byte_size = pointee.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); - child_byte_offset = 0; - return pointee; - } - } - } else if (GoArray *a = t->GetArray()) { - if (ignore_array_bounds || idx < a->GetLength()) { - CompilerType element_type = a->GetElementType(); - if (element_type.GetCompleteType()) { - char element_name[64]; - ::snprintf(element_name, sizeof(element_name), "[%zu]", idx); - child_name.assign(element_name); - child_byte_size = element_type.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); - child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; - return element_type; - } - } - } else if (t->IsTypedef()) { - return t->GetElementType().GetChildCompilerTypeAtIndex( - exe_ctx, idx, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name, child_byte_size, child_byte_offset, - child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, - child_is_deref_of_parent, valobj, language_flags); - } - return CompilerType(); -} - -// Lookup a child given a name. This function will match base class names and -// member member names in "clang_type" only, not descendants. -uint32_t -GoASTContext::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, - const char *name, - bool omit_empty_base_classes) { - if (!type || !GetCompleteType(type)) - return UINT_MAX; - - GoType *t = static_cast(type); - GoStruct *s = t->GetStruct(); - if (s) { - for (uint32_t i = 0; i < s->GetNumFields(); ++i) { - const GoStruct::Field *f = s->GetField(i); - if (f->m_name.GetStringRef() == name) - return i; - } - } else if (t->GetGoKind() == GoType::KIND_PTR || t->IsTypedef()) { - return t->GetElementType().GetIndexOfChildWithName(name, - omit_empty_base_classes); - } - return UINT_MAX; -} - -// Lookup a child member given a name. This function will match member names -// only and will descend into "clang_type" children in search for the first -// member in this class, or any base class that matches "name". -// TODO: Return all matches for a given name by returning a -// vector> -// so we catch all names that match a given child name, not just the first. -size_t GoASTContext::GetIndexOfChildMemberWithName( - lldb::opaque_compiler_type_t type, const char *name, - bool omit_empty_base_classes, std::vector &child_indexes) { - uint32_t index = GetIndexOfChildWithName(type, name, omit_empty_base_classes); - if (index == UINT_MAX) - return 0; - child_indexes.push_back(index); - return 1; -} - -// Converts "s" to a floating point value and place resulting floating point -// bytes in the "dst" buffer. -size_t -GoASTContext::ConvertStringToFloatValue(lldb::opaque_compiler_type_t type, - const char *s, uint8_t *dst, - size_t dst_size) { - assert(false); - return 0; -} -//---------------------------------------------------------------------- -// Dumping types -//---------------------------------------------------------------------- -#define DEPTH_INCREMENT 2 - -void GoASTContext::DumpValue(lldb::opaque_compiler_type_t type, - ExecutionContext *exe_ctx, Stream *s, - lldb::Format format, const DataExtractor &data, - lldb::offset_t data_byte_offset, - size_t data_byte_size, uint32_t bitfield_bit_size, - uint32_t bitfield_bit_offset, bool show_types, - bool show_summary, bool verbose, uint32_t depth) { - if (IsTypedefType(type)) - type = GetTypedefedType(type).GetOpaqueQualType(); - if (!type) - return; - GoType *t = static_cast(type); - - if (GoStruct *st = t->GetStruct()) { - if (GetCompleteType(type)) { - uint32_t field_idx = 0; - for (auto *field = st->GetField(field_idx); field != nullptr; - field_idx++) { - // Print the starting squiggly bracket (if this is the first member) or - // comma (for member 2 and beyond) for the struct/union/class member. - if (field_idx == 0) - s->PutChar('{'); - else - s->PutChar(','); - - // Indent - s->Printf("\n%*s", depth + DEPTH_INCREMENT, ""); - - // Print the member type if requested - if (show_types) { - ConstString field_type_name = field->m_type.GetTypeName(); - s->Printf("(%s) ", field_type_name.AsCString()); - } - // Print the member name and equal sign - s->Printf("%s = ", field->m_name.AsCString()); - - // Dump the value of the member - CompilerType field_type = field->m_type; - field_type.DumpValue( - exe_ctx, - s, // Stream to dump to - field_type - .GetFormat(), // The format with which to display the member - data, // Data buffer containing all bytes for this type - data_byte_offset + field->m_byte_offset, // Offset into "data" where - // to grab value from - field->m_type.GetByteSize( - exe_ctx->GetBestExecutionContextScope()), // Size of this type - // in bytes - 0, // Bitfield bit size - 0, // Bitfield bit offset - show_types, // Boolean indicating if we should show the variable - // types - show_summary, // Boolean indicating if we should show a summary for - // the current type - verbose, // Verbose output? - depth + DEPTH_INCREMENT); // Scope depth for any types that have - // children - } - - // Indent the trailing squiggly bracket - if (field_idx > 0) - s->Printf("\n%*s}", depth, ""); - } - } - - if (GoArray *a = t->GetArray()) { - CompilerType element_clang_type = a->GetElementType(); - lldb::Format element_format = element_clang_type.GetFormat(); - uint32_t element_byte_size = - element_clang_type.GetByteSize(exe_ctx->GetBestExecutionContextScope()); - - uint64_t element_idx; - for (element_idx = 0; element_idx < a->GetLength(); ++element_idx) { - // Print the starting squiggly bracket (if this is the first member) or - // comman (for member 2 and beyong) for the struct/union/class member. - if (element_idx == 0) - s->PutChar('{'); - else - s->PutChar(','); - - // Indent and print the index - s->Printf("\n%*s[%" PRIu64 "] ", depth + DEPTH_INCREMENT, "", - element_idx); - - // Figure out the field offset within the current struct/union/class type - uint64_t element_offset = element_idx * element_byte_size; - - // Dump the value of the member - element_clang_type.DumpValue( - exe_ctx, - s, // Stream to dump to - element_format, // The format with which to display the element - data, // Data buffer containing all bytes for this type - data_byte_offset + - element_offset, // Offset into "data" where to grab value from - element_byte_size, // Size of this type in bytes - 0, // Bitfield bit size - 0, // Bitfield bit offset - show_types, // Boolean indicating if we should show the variable types - show_summary, // Boolean indicating if we should show a summary for - // the current type - verbose, // Verbose output? - depth + - DEPTH_INCREMENT); // Scope depth for any types that have children - } - - // Indent the trailing squiggly bracket - if (element_idx > 0) - s->Printf("\n%*s}", depth, ""); - } - - if (show_summary) - DumpSummary(type, exe_ctx, s, data, data_byte_offset, data_byte_size); -} - -bool GoASTContext::DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s, - lldb::Format format, const DataExtractor &data, - lldb::offset_t byte_offset, size_t byte_size, - uint32_t bitfield_bit_size, - uint32_t bitfield_bit_offset, - ExecutionContextScope *exe_scope) { - if (!type) - return false; - if (IsAggregateType(type)) { - return false; - } else { - GoType *t = static_cast(type); - if (t->IsTypedef()) { - CompilerType typedef_compiler_type = t->GetElementType(); - if (format == eFormatDefault) - format = typedef_compiler_type.GetFormat(); - uint64_t typedef_byte_size = typedef_compiler_type.GetByteSize(exe_scope); - - return typedef_compiler_type.DumpTypeValue( - s, - format, // The format with which to display the element - data, // Data buffer containing all bytes for this type - byte_offset, // Offset into "data" where to grab value from - typedef_byte_size, // Size of this type in bytes - bitfield_bit_size, // Size in bits of a bitfield value, if zero don't - // treat as a bitfield - bitfield_bit_offset, // Offset in bits of a bitfield value if - // bitfield_bit_size != 0 - exe_scope); - } - - uint32_t item_count = 1; - // A few formats, we might need to modify our size and count for depending - // on how we are trying to display the value... - switch (format) { - default: - case eFormatBoolean: - case eFormatBinary: - case eFormatComplex: - case eFormatCString: // NULL terminated C strings - case eFormatDecimal: - case eFormatEnum: - case eFormatHex: - case eFormatHexUppercase: - case eFormatFloat: - case eFormatOctal: - case eFormatOSType: - case eFormatUnsigned: - case eFormatPointer: - case eFormatVectorOfChar: - case eFormatVectorOfSInt8: - case eFormatVectorOfUInt8: - case eFormatVectorOfSInt16: - case eFormatVectorOfUInt16: - case eFormatVectorOfSInt32: - case eFormatVectorOfUInt32: - case eFormatVectorOfSInt64: - case eFormatVectorOfUInt64: - case eFormatVectorOfFloat32: - case eFormatVectorOfFloat64: - case eFormatVectorOfUInt128: - break; - - case eFormatChar: - case eFormatCharPrintable: - case eFormatCharArray: - case eFormatBytes: - case eFormatBytesWithASCII: - item_count = byte_size; - byte_size = 1; - break; - - case eFormatUnicode16: - item_count = byte_size / 2; - byte_size = 2; - break; - - case eFormatUnicode32: - item_count = byte_size / 4; - byte_size = 4; - break; - } - return DumpDataExtractor(data, s, byte_offset, format, byte_size, - item_count, UINT32_MAX, LLDB_INVALID_ADDRESS, - bitfield_bit_size, bitfield_bit_offset, exe_scope); - } - return 0; -} - -void GoASTContext::DumpSummary(lldb::opaque_compiler_type_t type, - ExecutionContext *exe_ctx, Stream *s, - const DataExtractor &data, - lldb::offset_t data_offset, - size_t data_byte_size) { - if (type && GoType::KIND_STRING == static_cast(type)->GetGoKind()) { - // TODO(ribrdb): read length and data - } -} - -void GoASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type) { - // Dump to stdout - StreamFile s(stdout, false); - DumpTypeDescription(type, &s); -} - -void GoASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, - Stream *s) { - if (!type) - return; - ConstString name = GetTypeName(type); - GoType *t = static_cast(type); - - if (GoStruct *st = t->GetStruct()) { - if (GetCompleteType(type)) { - if (NULL == strchr(name.AsCString(), '{')) - s->Printf("type %s ", name.AsCString()); - s->PutCString("struct {"); - if (st->GetNumFields() == 0) { - s->PutChar('}'); - return; - } - s->IndentMore(); - uint32_t field_idx = 0; - for (auto *field = st->GetField(field_idx); field != nullptr; - field_idx++) { - s->PutChar('\n'); - s->Indent(); - s->Printf("%s %s", field->m_name.AsCString(), - field->m_type.GetTypeName().AsCString()); - } - s->IndentLess(); - s->PutChar('\n'); - s->Indent("}"); - return; - } - } - - s->PutCString(name.AsCString()); -} - -CompilerType GoASTContext::CreateArrayType(const ConstString &name, - const CompilerType &element_type, - uint64_t length) { - GoType *type = new GoArray(name, length, element_type); - (*m_types)[name].reset(type); - return CompilerType(this, type); -} - -CompilerType GoASTContext::CreateBaseType(int go_kind, - const lldb_private::ConstString &name, - uint64_t byte_size) { - if (go_kind == GoType::KIND_UINT || go_kind == GoType::KIND_INT) - m_int_byte_size = byte_size; - GoType *type = new GoType(go_kind, name); - (*m_types)[name].reset(type); - return CompilerType(this, type); -} - -CompilerType GoASTContext::CreateTypedefType(int kind, const ConstString &name, - CompilerType impl) { - GoType *type = new GoElem(kind, name, impl); - (*m_types)[name].reset(type); - return CompilerType(this, type); -} - -CompilerType -GoASTContext::CreateVoidType(const lldb_private::ConstString &name) { - GoType *type = new GoType(GoType::KIND_LLDB_VOID, name); - (*m_types)[name].reset(type); - return CompilerType(this, type); -} - -CompilerType -GoASTContext::CreateStructType(int kind, const lldb_private::ConstString &name, - uint32_t byte_size) { - GoType *type = new GoStruct(kind, name, byte_size); - (*m_types)[name].reset(type); - return CompilerType(this, type); -} - -void GoASTContext::AddFieldToStruct( - const lldb_private::CompilerType &struct_type, - const lldb_private::ConstString &name, - const lldb_private::CompilerType &field_type, uint32_t byte_offset) { - if (!struct_type) - return; - GoASTContext *ast = - llvm::dyn_cast_or_null(struct_type.GetTypeSystem()); - if (!ast) - return; - GoType *type = static_cast(struct_type.GetOpaqueQualType()); - if (GoStruct *s = type->GetStruct()) - s->AddField(name, field_type, byte_offset); -} - -void GoASTContext::CompleteStructType( - const lldb_private::CompilerType &struct_type) { - if (!struct_type) - return; - GoASTContext *ast = - llvm::dyn_cast_or_null(struct_type.GetTypeSystem()); - if (!ast) - return; - GoType *type = static_cast(struct_type.GetOpaqueQualType()); - if (GoStruct *s = type->GetStruct()) - s->SetComplete(); -} - -CompilerType -GoASTContext::CreateFunctionType(const lldb_private::ConstString &name, - CompilerType *params, size_t params_count, - bool is_variadic) { - GoType *type = new GoFunction(name, is_variadic); - (*m_types)[name].reset(type); - return CompilerType(this, type); -} - -bool GoASTContext::IsGoString(const lldb_private::CompilerType &type) { - if (!type.IsValid() || - !llvm::dyn_cast_or_null(type.GetTypeSystem())) - return false; - return GoType::KIND_STRING == - static_cast(type.GetOpaqueQualType())->GetGoKind(); -} - -bool GoASTContext::IsGoSlice(const lldb_private::CompilerType &type) { - if (!type.IsValid() || - !llvm::dyn_cast_or_null(type.GetTypeSystem())) - return false; - return GoType::KIND_SLICE == - static_cast(type.GetOpaqueQualType())->GetGoKind(); -} - -bool GoASTContext::IsGoInterface(const lldb_private::CompilerType &type) { - if (!type.IsValid() || - !llvm::dyn_cast_or_null(type.GetTypeSystem())) - return false; - return GoType::KIND_INTERFACE == - static_cast(type.GetOpaqueQualType())->GetGoKind(); -} - -bool GoASTContext::IsPointerKind(uint8_t kind) { - return (kind & GoType::KIND_MASK) == GoType::KIND_PTR; -} - -bool GoASTContext::IsDirectIface(uint8_t kind) { - return (kind & GoType::KIND_DIRECT_IFACE) == GoType::KIND_DIRECT_IFACE; -} - -DWARFASTParser *GoASTContext::GetDWARFParser() { - if (!m_dwarf_ast_parser_ap) - m_dwarf_ast_parser_ap.reset(new DWARFASTParserGo(*this)); - return m_dwarf_ast_parser_ap.get(); -} - -UserExpression *GoASTContextForExpr::GetUserExpression( - llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, - Expression::ResultType desired_type, - const EvaluateExpressionOptions &options) { - TargetSP target = m_target_wp.lock(); - if (target) - return new GoUserExpression(*target, expr, prefix, language, desired_type, - options); - return nullptr; -} Index: lldb/trunk/tools/lldb-test/SystemInitializerTest.cpp =================================================================== --- lldb/trunk/tools/lldb-test/SystemInitializerTest.cpp +++ lldb/trunk/tools/lldb-test/SystemInitializerTest.cpp @@ -14,7 +14,6 @@ #include "lldb/Initialization/SystemInitializerCommon.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Symbol/ClangASTContext.h" -#include "lldb/Symbol/GoASTContext.h" #include "lldb/Symbol/JavaASTContext.h" #include "lldb/Symbol/OCamlASTContext.h" #include "lldb/Utility/Timer.h" @@ -48,13 +47,11 @@ #include "Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.h" #include "Plugins/JITLoader/GDB/JITLoaderGDB.h" #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" -#include "Plugins/Language/Go/GoLanguage.h" #include "Plugins/Language/Java/JavaLanguage.h" #include "Plugins/Language/OCaml/OCamlLanguage.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" #include "Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h" #include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h" -#include "Plugins/LanguageRuntime/Go/GoLanguageRuntime.h" #include "Plugins/LanguageRuntime/Java/JavaLanguageRuntime.h" #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h" #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h" @@ -63,7 +60,6 @@ #include "Plugins/ObjectFile/ELF/ObjectFileELF.h" #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h" -#include "Plugins/OperatingSystem/Go/OperatingSystemGo.h" #include "Plugins/Platform/Android/PlatformAndroid.h" #include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h" #include "Plugins/Platform/Kalimba/PlatformKalimba.h" @@ -129,7 +125,6 @@ ScriptInterpreterNone::Initialize(); - OperatingSystemGo::Initialize(); platform_freebsd::PlatformFreeBSD::Initialize(); platform_linux::PlatformLinux::Initialize(); @@ -152,7 +147,6 @@ llvm::InitializeAllDisassemblers(); ClangASTContext::Initialize(); - GoASTContext::Initialize(); JavaASTContext::Initialize(); OCamlASTContext::Initialize(); @@ -198,11 +192,9 @@ AppleObjCRuntimeV1::Initialize(); SystemRuntimeMacOSX::Initialize(); RenderScriptRuntime::Initialize(); - GoLanguageRuntime::Initialize(); JavaLanguageRuntime::Initialize(); CPlusPlusLanguage::Initialize(); - GoLanguage::Initialize(); JavaLanguage::Initialize(); ObjCLanguage::Initialize(); ObjCPlusPlusLanguage::Initialize(); @@ -261,7 +253,6 @@ PluginManager::Terminate(); ClangASTContext::Terminate(); - GoASTContext::Terminate(); JavaASTContext::Terminate(); OCamlASTContext::Terminate(); @@ -305,7 +296,6 @@ JavaLanguageRuntime::Terminate(); CPlusPlusLanguage::Terminate(); - GoLanguage::Terminate(); JavaLanguage::Terminate(); ObjCLanguage::Terminate(); ObjCPlusPlusLanguage::Terminate(); @@ -337,7 +327,6 @@ DynamicLoaderStatic::Terminate(); DynamicLoaderWindowsDYLD::Terminate(); - OperatingSystemGo::Terminate(); platform_freebsd::PlatformFreeBSD::Terminate(); platform_linux::PlatformLinux::Terminate(); Index: lldb/trunk/unittests/Expression/CMakeLists.txt =================================================================== --- lldb/trunk/unittests/Expression/CMakeLists.txt +++ lldb/trunk/unittests/Expression/CMakeLists.txt @@ -1,11 +1,9 @@ add_lldb_unittest(ExpressionTests ClangParserTest.cpp - GoParserTest.cpp LINK_LIBS lldbCore lldbPluginExpressionParserClang - lldbPluginExpressionParserGo lldbUtility lldbUtilityHelpers ) Index: lldb/trunk/unittests/Expression/GoParserTest.cpp =================================================================== --- lldb/trunk/unittests/Expression/GoParserTest.cpp +++ lldb/trunk/unittests/Expression/GoParserTest.cpp @@ -1,273 +0,0 @@ -//===-- GoParserTest.cpp ------------------------------------------*- C++ -//-*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include - -#include "gtest/gtest.h" - -#include "Plugins/ExpressionParser/Go/GoParser.h" -#include "lldb/Utility/Status.h" - -using namespace lldb_private; - -namespace { -struct ASTPrinter { - ASTPrinter(GoASTNode *n) { (*this)(n); } - - void operator()(GoASTNode *n) { - if (n == nullptr) { - m_stream << "nil "; - return; - } - m_stream << "(" << n->GetKindName() << " "; - n->WalkChildren(*this); - if (auto *nn = llvm::dyn_cast(n)) - m_stream << nn->GetDefine() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << nn->GetValue().m_value.str() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << GoLexer::LookupToken(nn->GetOp()).str() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << nn->GetName().m_value.str() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << GoLexer::LookupToken(nn->GetTok()).str() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << (nn->GetEllipsis() ? "..." : "") << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << nn->GetDir() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << GoLexer::LookupToken(nn->GetTok()).str() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << GoLexer::LookupToken(nn->GetTok()).str() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << nn->GetDefine() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << nn->GetSlice3() << " "; - if (auto *nn = llvm::dyn_cast(n)) - m_stream << GoLexer::LookupToken(nn->GetOp()).str() << " "; - m_stream << ") "; - } - - const std::string str() const { return m_stream.str(); } - std::stringstream m_stream; -}; - -testing::AssertionResult CheckStatement(const char *_s, const char *c_expr, - const char *sexpr, const char *code) { - GoParser parser(code); - std::unique_ptr stmt(parser.Statement()); - if (parser.Failed() || !stmt) { - Status err; - parser.GetError(err); - return testing::AssertionFailure() << "Error parsing " << c_expr << "\n\t" - << err.AsCString(); - } - std::string actual_sexpr = ASTPrinter(stmt.get()).str(); - if (actual_sexpr == sexpr) - return testing::AssertionSuccess(); - return testing::AssertionFailure() << "Parsing: " << c_expr - << "\nExpected: " << sexpr - << "\nGot: " << actual_sexpr; -} -} // namespace - -#define EXPECT_PARSE(s, c) EXPECT_PRED_FORMAT2(CheckStatement, s, c) - -TEST(GoParserTest, ParseBasicLiterals) { - EXPECT_PARSE("(ExprStmt (BasicLit 0 ) ) ", "0"); - EXPECT_PARSE("(ExprStmt (BasicLit 42 ) ) ", "42"); - EXPECT_PARSE("(ExprStmt (BasicLit 0600 ) ) ", "0600"); - EXPECT_PARSE("(ExprStmt (BasicLit 0xBadFace ) ) ", "0xBadFace"); - EXPECT_PARSE( - "(ExprStmt (BasicLit 170141183460469231731687303715884105727 ) ) ", - "170141183460469231731687303715884105727"); - - EXPECT_PARSE("(ExprStmt (BasicLit 0. ) ) ", "0."); - EXPECT_PARSE("(ExprStmt (BasicLit 72.40 ) ) ", "72.40"); - EXPECT_PARSE("(ExprStmt (BasicLit 072.40 ) ) ", "072.40"); - EXPECT_PARSE("(ExprStmt (BasicLit 2.71828 ) ) ", "2.71828"); - EXPECT_PARSE("(ExprStmt (BasicLit 1.e+0 ) ) ", "1.e+0"); - EXPECT_PARSE("(ExprStmt (BasicLit 6.67428e-11 ) ) ", "6.67428e-11"); - EXPECT_PARSE("(ExprStmt (BasicLit 1E6 ) ) ", "1E6"); - EXPECT_PARSE("(ExprStmt (BasicLit .12345E+6 ) ) ", ".12345E+6"); - - EXPECT_PARSE("(ExprStmt (BasicLit 0i ) ) ", "0i"); - EXPECT_PARSE("(ExprStmt (BasicLit 011i ) ) ", "011i"); - EXPECT_PARSE("(ExprStmt (BasicLit 0.i ) ) ", "0.i"); - EXPECT_PARSE("(ExprStmt (BasicLit 2.71828i ) ) ", "2.71828i"); - EXPECT_PARSE("(ExprStmt (BasicLit 6.67428e-11i ) ) ", "6.67428e-11i"); - EXPECT_PARSE("(ExprStmt (BasicLit 1E6i ) ) ", "1E6i"); - EXPECT_PARSE("(ExprStmt (BasicLit .12345E+6i ) ) ", ".12345E+6i"); - - EXPECT_PARSE("(ExprStmt (BasicLit 'a' ) ) ", "'a'"); - EXPECT_PARSE("(ExprStmt (BasicLit '本' ) ) ", "'本'"); - EXPECT_PARSE("(ExprStmt (BasicLit \"abc\" ) ) ", "\"abc\""); - EXPECT_PARSE("(ExprStmt (BasicLit `abc` ) ) ", "`abc`"); - EXPECT_PARSE("(ExprStmt (BasicLit `ab\nc` ) ) ", "`ab\nc`"); -} - -TEST(GoParserTest, ParseOperand) { - EXPECT_PARSE("(ExprStmt (Ident a ) ) ", "a"); - EXPECT_PARSE("(ExprStmt (Ident _x9 ) ) ", "_x9"); - EXPECT_PARSE("(ExprStmt (Ident ThisVariableIsExported ) ) ", - "ThisVariableIsExported"); - EXPECT_PARSE("(ExprStmt (Ident αβ ) ) ", "αβ"); - - EXPECT_PARSE("(ExprStmt (SelectorExpr (Ident math ) (Ident Sin ) ) ) ", - "math.Sin"); -} - -TEST(GoParserTest, ParseCompositeLiterals) { - EXPECT_PARSE("(ExprStmt (CompositeLit (Ident Point3D ) ) ) ", "Point3D{}"); - EXPECT_PARSE("(ExprStmt (CompositeLit (Ident Line ) (Ident origin ) " - "(CompositeLit (Ident Point3D ) (KeyValueExpr " - "(Ident y ) (UnaryExpr (BasicLit 4 ) - ) ) (KeyValueExpr (Ident " - "z ) (BasicLit 12.3 ) ) ) ) ) ", - "Line{origin, Point3D{y: -4, z: 12.3}}"); - EXPECT_PARSE("(ExprStmt (CompositeLit (ArrayType (BasicLit 10 ) (Ident " - "string ) ) ) ) ", - "[10]string{}"); - EXPECT_PARSE("(ExprStmt (CompositeLit (ArrayType (BasicLit 6 ) (Ident int ) " - ") (BasicLit 1 ) (BasicLit 2 ) " - "(BasicLit 3 ) (BasicLit 5 ) ) ) ", - "[6]int {1, 2, 3, 5}"); - EXPECT_PARSE("(ExprStmt (CompositeLit (ArrayType nil (Ident int ) ) " - "(BasicLit 2 ) (BasicLit 3 ) (BasicLit 5 ) " - "(BasicLit 7 ) (BasicLit 9 ) (BasicLit 2147483647 ) ) ) ", - "[]int{2, 3, 5, 7, 9, 2147483647}"); - EXPECT_PARSE("(ExprStmt (CompositeLit (ArrayType (BasicLit 128 ) (Ident bool " - ") ) (KeyValueExpr (BasicLit 'a' ) " - "(Ident true ) ) (KeyValueExpr (BasicLit 'e' ) (Ident true ) ) " - "(KeyValueExpr (BasicLit 'i' ) (Ident " - "true ) ) (KeyValueExpr (BasicLit 'o' ) (Ident true ) ) " - "(KeyValueExpr (BasicLit 'u' ) (Ident true ) ) " - "(KeyValueExpr (BasicLit 'y' ) (Ident true ) ) ) ) ", - "[128]bool{'a': true, 'e': true, 'i': true, 'o': true, 'u': " - "true, 'y': true}"); - EXPECT_PARSE( - "(ExprStmt (CompositeLit (ArrayType (BasicLit 10 ) (Ident float32 ) ) " - "(UnaryExpr (BasicLit 1 ) - ) " - "(KeyValueExpr (BasicLit 4 ) (UnaryExpr (BasicLit 0.1 ) - ) ) (UnaryExpr " - "(BasicLit 0.1 ) - ) " - "(KeyValueExpr (BasicLit 9 ) (UnaryExpr (BasicLit 1 ) - ) ) ) ) ", - "[10]float32{-1, 4: -0.1, -0.1, 9: -1}"); -} - -TEST(GoParserTest, ParseEllipsisArray) { - EXPECT_PARSE("(ExprStmt (CompositeLit (ArrayType (Ellipsis nil ) (Ident " - "string ) ) (BasicLit `Sat` ) (BasicLit `Sun` ) ) ) ", - "[...]string {`Sat`, `Sun`}"); - EXPECT_PARSE("(ExprStmt (CompositeLit (ArrayType (Ellipsis nil ) (Ident " - "Point ) ) (CompositeLit nil (BasicLit 1.5 " - ") (UnaryExpr (BasicLit 3.5 ) - ) ) (CompositeLit nil (BasicLit " - "0 ) (BasicLit 0 ) ) ) ) ", - "[...]Point{{1.5, -3.5}, {0, 0}}"); -} - -TEST(GoParserTest, ParseMap) { - EXPECT_PARSE("(ExprStmt (CompositeLit (MapType (Ident string ) (Ident " - "float32 ) ) (KeyValueExpr (BasicLit `C0` ) " - "(BasicLit 16.35 ) ) (KeyValueExpr (BasicLit `D0` ) (BasicLit " - "18.35 ) ) ) ) ", - "map[string]float32{`C0`: 16.35, `D0`: 18.35, }"); -} - -TEST(GoParserTest, UnaryExpr) { - EXPECT_PARSE("(ExprStmt (UnaryExpr (Ident x ) + ) ) ", "+x"); - EXPECT_PARSE("(ExprStmt (UnaryExpr (Ident x ) - ) ) ", "-x"); - EXPECT_PARSE("(ExprStmt (UnaryExpr (Ident x ) ! ) ) ", "!x"); - EXPECT_PARSE("(ExprStmt (UnaryExpr (Ident x ) ^ ) ) ", "^x"); - EXPECT_PARSE("(ExprStmt (UnaryExpr (Ident x ) & ) ) ", "&x"); - EXPECT_PARSE("(ExprStmt (UnaryExpr (Ident x ) <- ) ) ", "<-x"); - EXPECT_PARSE("(ExprStmt (StarExpr (Ident x ) ) ) ", "*x"); -} - -TEST(GoParserTest, BinaryExpr) { - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) || ) ) ", "a || b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) && ) ) ", "a && b"); - - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) == ) ) ", "a == b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) != ) ) ", "a != b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) < ) ) ", "a < b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) <= ) ) ", "a <= b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) > ) ) ", "a > b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) >= ) ) ", "a >= b"); - - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) + ) ) ", "a + b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) - ) ) ", "a - b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) | ) ) ", "a | b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) ^ ) ) ", "a ^ b"); - - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) * ) ) ", "a * b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) / ) ) ", "a / b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) % ) ) ", "a % b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) << ) ) ", "a << b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) >> ) ) ", "a >> b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) & ) ) ", "a & b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (Ident b ) &^ ) ) ", "a &^ b"); - - EXPECT_PARSE("(ExprStmt (BinaryExpr (BasicLit 23 ) (BinaryExpr (BasicLit 3 ) " - "(IndexExpr (Ident x ) (Ident i ) ) * ) + ) ) ", - "23 + 3*x[i]"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident a ) (UnaryExpr (UnaryExpr (Ident " - "a ) + ) + ) + ) ) ", - "a + + + a"); - EXPECT_PARSE( - "(ExprStmt (BinaryExpr (UnaryExpr (Ident a ) ^ ) (Ident b ) >> ) ) ", - "^a >> b"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (CallExpr (Ident f ) ) (CallExpr (Ident " - "g ) ) || ) ) ", - "f() || g()"); - EXPECT_PARSE( - "(ExprStmt (BinaryExpr (BinaryExpr (Ident x ) (BinaryExpr (Ident y ) " - "(BasicLit 1 ) + ) == ) " - "(BinaryExpr (UnaryExpr (Ident chanPtr ) <- ) (BasicLit 0 ) > ) && ) ) ", - "x == y+1 && <-chanPtr > 0"); -} - -TEST(GoParserTest, PrimaryExpr) { - EXPECT_PARSE( - "(ExprStmt (BinaryExpr (Ident x ) (CallExpr (Ident f ) ) <= ) ) ", - "x <= f()"); - EXPECT_PARSE("(ExprStmt (BinaryExpr (Ident s ) (BasicLit `.txt` ) + ) ) ", - "(s + `.txt`)"); - EXPECT_PARSE( - "(ExprStmt (CallExpr (Ident f ) (BasicLit 3.1415 ) (Ident true ) ) ) ", - "f(3.1415, true)"); - EXPECT_PARSE( - "(ExprStmt (CallExpr (Ident f ) (BasicLit 3.1415 ) (Ident a ) ... ) ) ", - "f(3.1415, a...)"); - EXPECT_PARSE("(ExprStmt (IndexExpr (Ident m ) (BasicLit '1' ) ) ) ", - "m['1']"); - EXPECT_PARSE("(ExprStmt (SliceExpr (Ident s ) (Ident i ) (BinaryExpr (Ident " - "j ) (BasicLit 1 ) + ) nil 0 ) ) ", - "s[i : j + 1]"); - EXPECT_PARSE("(ExprStmt (SelectorExpr (Ident obj ) (Ident color ) ) ) ", - "obj.color"); - EXPECT_PARSE("(ExprStmt (CallExpr (SelectorExpr (IndexExpr (SelectorExpr " - "(Ident f ) (Ident p ) ) (Ident i ) ) " - "(Ident x ) ) ) ) ", - "f.p[i].x()"); -} - -TEST(GoParserTest, Conversions) { - EXPECT_PARSE( - "(ExprStmt (StarExpr (CallExpr (Ident Point ) (Ident p ) ) ) ) ", - "*Point(p)"); - EXPECT_PARSE( - "(ExprStmt (CallExpr (StarExpr (Ident Point ) ) (Ident p ) ) ) ", - "(*Point)(p)"); - EXPECT_PARSE("(ExprStmt (UnaryExpr (CallExpr (ChanType (Ident int ) 0 ) " - "(Ident c ) ) <- ) ) ", - "<-chan int(c)"); - EXPECT_PARSE("(ExprStmt (TypeAssertExpr (Ident y ) (SelectorExpr (Ident io ) " - "(Ident Reader ) ) ) ) ", - "y.(io.Reader)"); -} Index: lldb/trunk/unittests/Language/Highlighting/CMakeLists.txt =================================================================== --- lldb/trunk/unittests/Language/Highlighting/CMakeLists.txt +++ lldb/trunk/unittests/Language/Highlighting/CMakeLists.txt @@ -7,5 +7,4 @@ lldbPluginObjCPlusPlusLanguage lldbPluginJavaLanguage lldbPluginOCamlLanguage - lldbPluginGoLanguage ) Index: lldb/trunk/unittests/Language/Highlighting/HighlighterTest.cpp =================================================================== --- lldb/trunk/unittests/Language/Highlighting/HighlighterTest.cpp +++ lldb/trunk/unittests/Language/Highlighting/HighlighterTest.cpp @@ -12,7 +12,6 @@ #include "lldb/Core/Highlighter.h" #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" -#include "Plugins/Language/Go/GoLanguage.h" #include "Plugins/Language/Java/JavaLanguage.h" #include "Plugins/Language/OCaml/OCamlLanguage.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" @@ -32,7 +31,6 @@ // The HighlighterManager uses the language plugins under the hood, so we // have to initialize them here for our test process. CPlusPlusLanguage::Initialize(); - GoLanguage::Initialize(); JavaLanguage::Initialize(); ObjCLanguage::Initialize(); ObjCPlusPlusLanguage::Initialize(); @@ -41,7 +39,6 @@ void HighlighterTest::TearDownTestCase() { CPlusPlusLanguage::Terminate(); - GoLanguage::Terminate(); JavaLanguage::Terminate(); ObjCLanguage::Terminate(); ObjCPlusPlusLanguage::Terminate(); Index: lldb/trunk/unittests/Symbol/TestClangASTContext.cpp =================================================================== --- lldb/trunk/unittests/Symbol/TestClangASTContext.cpp +++ lldb/trunk/unittests/Symbol/TestClangASTContext.cpp @@ -18,7 +18,6 @@ #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ClangUtil.h" #include "lldb/Symbol/Declaration.h" -#include "lldb/Symbol/GoASTContext.h" using namespace clang; using namespace lldb; @@ -239,11 +238,6 @@ // Default constructed type should fail EXPECT_FALSE(ClangUtil::IsClangType(CompilerType())); - - // Go type should fail - GoASTContext go_ast; - CompilerType go_type(&go_ast, bool_ctype); - EXPECT_FALSE(ClangUtil::IsClangType(go_type)); } TEST_F(TestClangASTContext, TestRemoveFastQualifiers) {