diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
| commit | f73363f1dd94996356cefbf24388f561891acf0b (patch) | |
| tree | e3c31248bdb36eaec5fd833490d4278162dba2a0 /source/Plugins/ExpressionParser/Go | |
| parent | 160ee69dd7ae18978f4068116777639ea98dc951 (diff) | |
Notes
Diffstat (limited to 'source/Plugins/ExpressionParser/Go')
| -rw-r--r-- | source/Plugins/ExpressionParser/Go/GoParser.cpp | 10 | ||||
| -rw-r--r-- | source/Plugins/ExpressionParser/Go/GoUserExpression.cpp | 20 | ||||
| -rw-r--r-- | source/Plugins/ExpressionParser/Go/GoUserExpression.h | 14 |
3 files changed, 21 insertions, 23 deletions
diff --git a/source/Plugins/ExpressionParser/Go/GoParser.cpp b/source/Plugins/ExpressionParser/Go/GoParser.cpp index 538bd05e25f8..9c845d02bca0 100644 --- a/source/Plugins/ExpressionParser/Go/GoParser.cpp +++ b/source/Plugins/ExpressionParser/Go/GoParser.cpp @@ -67,7 +67,9 @@ private: size_t m_pos; }; -GoParser::GoParser(const char *src) : m_lexer(src), m_pos(0), m_failed(false) {} +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); @@ -437,8 +439,10 @@ GoASTExpr *GoParser::CompositeLit() { if (!type) return r.error(); GoASTCompositeLit *lit = LiteralValue(); - if (!lit) + if (!lit) { + delete type; return r.error(); + } lit->SetType(type); return lit; } @@ -546,6 +550,7 @@ GoASTExpr *GoParser::Arguments(GoASTExpr *e) { GoASTExpr *GoParser::Conversion() { Rule r("Conversion", this); if (GoASTExpr *t = Type2()) { + std::unique_ptr<GoASTExpr> owner(t); if (match(GoLexer::OP_LPAREN)) { GoASTExpr *v = Expression(); if (!v) @@ -555,6 +560,7 @@ GoASTExpr *GoParser::Conversion() { return r.error(); GoASTCallExpr *call = new GoASTCallExpr(false); call->SetFun(t); + owner.release(); call->AddArgs(v); return call; } diff --git a/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp b/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp index f4b8cfbe03d4..3a10a1dc767a 100644 --- a/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp +++ b/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp @@ -171,12 +171,11 @@ private: VariableSP FindGlobalVariable(TargetSP target, llvm::Twine name) { ConstString fullname(name.str()); VariableList variable_list; - const bool append = true; if (!target) { return nullptr; } - const uint32_t match_count = target->GetImages().FindGlobalVariables( - fullname, append, 1, variable_list); + const uint32_t match_count = + target->GetImages().FindGlobalVariables(fullname, 1, variable_list); if (match_count == 1) { return variable_list.GetVariableAtIndex(0); } @@ -272,7 +271,8 @@ GoUserExpression::DoExecute(DiagnosticManager &diagnostic_manager, PersistentExpressionState *pv = target->GetPersistentExpressionStateForLanguage(eLanguageTypeGo); if (pv != nullptr) { - result->SetName(pv->GetNextPersistentVariableName()); + result->SetName(pv->GetNextPersistentVariableName( + *target, pv->GetPersistentVariablePrefix())); pv->AddVariable(result); } return lldb::eExpressionCompleted; @@ -400,8 +400,7 @@ ValueObjectSP GoUserExpression::GoInterpreter::VisitIdent(const GoASTIdent *e) { 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'. + // 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); @@ -651,15 +650,6 @@ ValueObjectSP GoUserExpression::GoInterpreter::VisitCallExpr( GoPersistentExpressionState::GoPersistentExpressionState() : PersistentExpressionState(eKindGo) {} -ConstString GoPersistentExpressionState::GetNextPersistentVariableName() { - char name_cstr[256]; - // We can't use the same variable format as clang. - ::snprintf(name_cstr, sizeof(name_cstr), "$go%u", - m_next_persistent_variable_id++); - ConstString name(name_cstr); - return name; -} - void GoPersistentExpressionState::RemovePersistentVariable( lldb::ExpressionVariableSP variable) { RemoveVariable(variable); diff --git a/source/Plugins/ExpressionParser/Go/GoUserExpression.h b/source/Plugins/ExpressionParser/Go/GoUserExpression.h index 03ceb76b8431..e2839da9bfdd 100644 --- a/source/Plugins/ExpressionParser/Go/GoUserExpression.h +++ b/source/Plugins/ExpressionParser/Go/GoUserExpression.h @@ -29,8 +29,10 @@ class GoPersistentExpressionState : public PersistentExpressionState { public: GoPersistentExpressionState(); - ConstString GetNextPersistentVariableName() override; - + llvm::StringRef + GetPersistentVariablePrefix(bool is_error) const override { + return "$go"; + } void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override; lldb::addr_t LookupSymbol(const ConstString &name) override { @@ -48,12 +50,12 @@ private: //---------------------------------------------------------------------- /// @class GoUserExpression GoUserExpression.h -/// "lldb/Expression/GoUserExpression.h" -/// @brief Encapsulates a single expression for use with Go +/// "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. +/// and as a backend for the expr command. GoUserExpression encapsulates the +/// objects needed to parse and interpret an expression. //---------------------------------------------------------------------- class GoUserExpression : public UserExpression { public: |
