summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ExpressionParser/Go
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser/Go')
-rw-r--r--lldb/source/Plugins/ExpressionParser/Go/GoAST.h4405
-rw-r--r--lldb/source/Plugins/ExpressionParser/Go/GoLexer.cpp650
-rw-r--r--lldb/source/Plugins/ExpressionParser/Go/GoLexer.h322
-rw-r--r--lldb/source/Plugins/ExpressionParser/Go/GoParser.cpp1717
-rw-r--r--lldb/source/Plugins/ExpressionParser/Go/GoParser.h272
-rw-r--r--lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp1154
-rw-r--r--lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h108
-rw-r--r--lldb/source/Plugins/ExpressionParser/Go/gen_go_ast.py150
8 files changed, 3649 insertions, 5129 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoAST.h b/lldb/source/Plugins/ExpressionParser/Go/GoAST.h
index 89836a38acb..d24e6c54871 100644
--- a/lldb/source/Plugins/ExpressionParser/Go/GoAST.h
+++ b/lldb/source/Plugins/ExpressionParser/Go/GoAST.h
@@ -13,3214 +13,1965 @@
#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"
-#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
- {
- 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;
- }
+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 <typename V> 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;
+};
- virtual const char *GetKindName() const = 0;
+class GoASTDecl : public GoASTNode {
+public:
+ template <typename R, typename V> R Visit(V *v) const;
- template <typename V> void WalkChildren(V &v);
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() >= eBadDecl && n->GetKind() <= eGenDecl;
+ }
- protected:
- explicit GoASTNode(NodeKind kind) : m_kind(kind) { }
+protected:
+ explicit GoASTDecl(NodeKind kind) : GoASTNode(kind) {}
- private:
- const NodeKind m_kind;
-
- GoASTNode(const GoASTNode &) = delete;
- const GoASTNode &operator=(const GoASTNode &) = delete;
+private:
+ GoASTDecl(const GoASTDecl &) = delete;
+ const GoASTDecl &operator=(const GoASTDecl &) = delete;
};
+class GoASTExpr : public GoASTNode {
+public:
+ template <typename R, typename V> R Visit(V *v) const;
-class GoASTDecl : public GoASTNode
-{
- public:
- template <typename R, typename V> R Visit(V *v) const;
-
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() >= eBadDecl && n->GetKind() <= eGenDecl;
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() >= eArrayType && n->GetKind() <= eUnaryExpr;
+ }
- protected:
- explicit GoASTDecl(NodeKind kind) : GoASTNode(kind) { }
- private:
+protected:
+ explicit GoASTExpr(NodeKind kind) : GoASTNode(kind) {}
- GoASTDecl(const GoASTDecl &) = delete;
- const GoASTDecl &operator=(const GoASTDecl &) = delete;
+private:
+ GoASTExpr(const GoASTExpr &) = delete;
+ const GoASTExpr &operator=(const GoASTExpr &) = delete;
};
-class GoASTExpr : public GoASTNode
-{
- public:
- template <typename R, typename V> R Visit(V *v) const;
+class GoASTSpec : public GoASTNode {
+public:
+ template <typename R, typename V> R Visit(V *v) const;
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() >= eArrayType && n->GetKind() <= eUnaryExpr;
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() >= eImportSpec && n->GetKind() <= eValueSpec;
+ }
- protected:
- explicit GoASTExpr(NodeKind kind) : GoASTNode(kind) { }
- private:
+protected:
+ explicit GoASTSpec(NodeKind kind) : GoASTNode(kind) {}
- GoASTExpr(const GoASTExpr &) = delete;
- const GoASTExpr &operator=(const GoASTExpr &) = delete;
+private:
+ GoASTSpec(const GoASTSpec &) = delete;
+ const GoASTSpec &operator=(const GoASTSpec &) = delete;
};
-class GoASTSpec : public GoASTNode
-{
- public:
- template <typename R, typename V> R Visit(V *v) const;
+class GoASTStmt : public GoASTNode {
+public:
+ template <typename R, typename V> R Visit(V *v) const;
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() >= eImportSpec && n->GetKind() <= eValueSpec;
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() >= eAssignStmt && n->GetKind() <= eTypeSwitchStmt;
+ }
- protected:
- explicit GoASTSpec(NodeKind kind) : GoASTNode(kind) { }
- private:
+protected:
+ explicit GoASTStmt(NodeKind kind) : GoASTNode(kind) {}
- GoASTSpec(const GoASTSpec &) = delete;
- const GoASTSpec &operator=(const GoASTSpec &) = delete;
+private:
+ GoASTStmt(const GoASTStmt &) = delete;
+ const GoASTStmt &operator=(const GoASTStmt &) = delete;
};
-class GoASTStmt : public GoASTNode
-{
- public:
- template <typename R, typename V> R Visit(V *v) const;
+class GoASTArrayType : public GoASTExpr {
+public:
+ GoASTArrayType(GoASTExpr *len, GoASTExpr *elt)
+ : GoASTExpr(eArrayType), m_len_up(len), m_elt_up(elt) {}
+ ~GoASTArrayType() override = default;
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() >= eAssignStmt && n->GetKind() <= eTypeSwitchStmt;
- }
+ const char *GetKindName() const override { return "ArrayType"; }
- protected:
- explicit GoASTStmt(NodeKind kind) : GoASTNode(kind) { }
- private:
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eArrayType; }
- GoASTStmt(const GoASTStmt &) = delete;
- const GoASTStmt &operator=(const GoASTStmt &) = delete;
-};
+ 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); }
-class GoASTArrayType : public GoASTExpr
-{
- public:
- GoASTArrayType(GoASTExpr *len, GoASTExpr *elt) : GoASTExpr(eArrayType), m_len_up(len), m_elt_up(elt) {}
- ~GoASTArrayType() override = default;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_len_up;
+ std::unique_ptr<GoASTExpr> m_elt_up;
- const char *
- GetKindName() const override
- {
- return "ArrayType";
- }
+ GoASTArrayType(const GoASTArrayType &) = delete;
+ const GoASTArrayType &operator=(const GoASTArrayType &) = delete;
+};
- 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);
- }
+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<GoASTExpr>(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<GoASTExpr>(rhs));
+ }
+
+ bool GetDefine() const { return m_define; }
+ void SetDefine(bool define) { m_define = define; }
+
+private:
+ friend class GoASTNode;
+ std::vector<std::unique_ptr<GoASTExpr>> m_lhs;
+ std::vector<std::unique_ptr<GoASTExpr>> m_rhs;
+ bool m_define;
+
+ GoASTAssignStmt(const GoASTAssignStmt &) = delete;
+ const GoASTAssignStmt &operator=(const GoASTAssignStmt &) = delete;
+};
- const GoASTExpr *
- GetElt() const
- {
- return m_elt_up.get();
- }
- void
- SetElt(GoASTExpr *elt)
- {
- m_elt_up.reset(elt);
- }
+class GoASTBadDecl : public GoASTDecl {
+public:
+ GoASTBadDecl() : GoASTDecl(eBadDecl) {}
+ ~GoASTBadDecl() override = default;
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTExpr> m_len_up;
- std::unique_ptr<GoASTExpr> m_elt_up;
+ const char *GetKindName() const override { return "BadDecl"; }
- GoASTArrayType(const GoASTArrayType &) = delete;
- const GoASTArrayType &operator=(const GoASTArrayType &) = delete;
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eBadDecl; }
+
+ GoASTBadDecl(const GoASTBadDecl &) = delete;
+ const GoASTBadDecl &operator=(const GoASTBadDecl &) = delete;
};
-class GoASTAssignStmt : public GoASTStmt
-{
- public:
- explicit GoASTAssignStmt(bool define) : GoASTStmt(eAssignStmt), m_define(define) {}
- ~GoASTAssignStmt() override = default;
+class GoASTBadExpr : public GoASTExpr {
+public:
+ GoASTBadExpr() : GoASTExpr(eBadExpr) {}
+ ~GoASTBadExpr() override = default;
- const char *
- GetKindName() const override
- {
- return "AssignStmt";
- }
+ const char *GetKindName() const override { return "BadExpr"; }
- 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<GoASTExpr>(lhs));
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eBadExpr; }
- 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<GoASTExpr>(rhs));
- }
+ GoASTBadExpr(const GoASTBadExpr &) = delete;
+ const GoASTBadExpr &operator=(const GoASTBadExpr &) = delete;
+};
- bool
- GetDefine() const
- {
- return m_define;
- }
- void
- SetDefine(bool define)
- {
- m_define = define;
- }
+class GoASTBadStmt : public GoASTStmt {
+public:
+ GoASTBadStmt() : GoASTStmt(eBadStmt) {}
+ ~GoASTBadStmt() override = default;
- private:
- friend class GoASTNode;
- std::vector<std::unique_ptr<GoASTExpr> > m_lhs;
- std::vector<std::unique_ptr<GoASTExpr> > m_rhs;
- bool m_define;
+ const char *GetKindName() const override { return "BadStmt"; }
- GoASTAssignStmt(const GoASTAssignStmt &) = delete;
- const GoASTAssignStmt &operator=(const GoASTAssignStmt &) = delete;
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eBadStmt; }
+
+ GoASTBadStmt(const GoASTBadStmt &) = delete;
+ const GoASTBadStmt &operator=(const GoASTBadStmt &) = delete;
};
-class GoASTBadDecl : public GoASTDecl
-{
- public:
- GoASTBadDecl() : GoASTDecl(eBadDecl) {}
- ~GoASTBadDecl() override = default;
+class GoASTBasicLit : public GoASTExpr {
+public:
+ explicit GoASTBasicLit(Token value) : GoASTExpr(eBasicLit), m_value(value) {}
+ ~GoASTBasicLit() override = default;
- const char *
- GetKindName() const override
- {
- return "BadDecl";
- }
+ const char *GetKindName() const override { return "BasicLit"; }
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() == eBadDecl;
- }
-
- GoASTBadDecl(const GoASTBadDecl &) = delete;
- const GoASTBadDecl &operator=(const GoASTBadDecl &) = delete;
-};
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eBasicLit; }
-class GoASTBadExpr : public GoASTExpr
-{
- public:
- GoASTBadExpr() : GoASTExpr(eBadExpr) {}
- ~GoASTBadExpr() override = default;
+ Token GetValue() const { return m_value; }
+ void SetValue(Token value) { m_value = value; }
- const char *
- GetKindName() const override
- {
- return "BadExpr";
- }
+private:
+ friend class GoASTNode;
+ Token m_value;
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() == eBadExpr;
- }
-
- GoASTBadExpr(const GoASTBadExpr &) = delete;
- const GoASTBadExpr &operator=(const GoASTBadExpr &) = delete;
+ GoASTBasicLit(const GoASTBasicLit &) = delete;
+ const GoASTBasicLit &operator=(const GoASTBasicLit &) = delete;
};
-class GoASTBadStmt : public GoASTStmt
-{
- public:
- GoASTBadStmt() : GoASTStmt(eBadStmt) {}
- ~GoASTBadStmt() override = default;
+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 "BadStmt";
- }
+ const char *GetKindName() const override { return "BinaryExpr"; }
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() == eBadStmt;
- }
-
- GoASTBadStmt(const GoASTBadStmt &) = delete;
- const GoASTBadStmt &operator=(const GoASTBadStmt &) = delete;
-};
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eBinaryExpr;
+ }
-class GoASTBasicLit : public GoASTExpr
-{
- public:
- explicit GoASTBasicLit(Token value) : GoASTExpr(eBasicLit), m_value(value) {}
- ~GoASTBasicLit() override = default;
+ const GoASTExpr *GetX() const { return m_x_up.get(); }
+ void SetX(GoASTExpr *x) { m_x_up.reset(x); }
- const char *
- GetKindName() const override
- {
- return "BasicLit";
- }
+ const GoASTExpr *GetY() const { return m_y_up.get(); }
+ void SetY(GoASTExpr *y) { m_y_up.reset(y); }
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() == eBasicLit;
- }
-
- Token
- GetValue() const
- {
- return m_value;
- }
- void
- SetValue(Token value)
- {
- m_value = value;
- }
+ TokenType GetOp() const { return m_op; }
+ void SetOp(TokenType op) { m_op = op; }
- private:
- friend class GoASTNode;
- Token m_value;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_x_up;
+ std::unique_ptr<GoASTExpr> m_y_up;
+ TokenType m_op;
- GoASTBasicLit(const GoASTBasicLit &) = delete;
- const GoASTBasicLit &operator=(const GoASTBasicLit &) = delete;
+ GoASTBinaryExpr(const GoASTBinaryExpr &) = delete;
+ const GoASTBinaryExpr &operator=(const GoASTBinaryExpr &) = 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";
- }
+class GoASTBlockStmt : public GoASTStmt {
+public:
+ GoASTBlockStmt() : GoASTStmt(eBlockStmt) {}
+ ~GoASTBlockStmt() override = default;
- 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 char *GetKindName() const override { return "BlockStmt"; }
- const GoASTExpr *
- GetY() const
- {
- return m_y_up.get();
- }
- void
- SetY(GoASTExpr *y)
- {
- m_y_up.reset(y);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eBlockStmt; }
- TokenType
- GetOp() const
- {
- return m_op;
- }
- void
- SetOp(TokenType op)
- {
- m_op = op;
- }
+ 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<GoASTStmt>(list));
+ }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTExpr> m_x_up;
- std::unique_ptr<GoASTExpr> m_y_up;
- TokenType m_op;
+private:
+ friend class GoASTNode;
+ std::vector<std::unique_ptr<GoASTStmt>> m_list;
- GoASTBinaryExpr(const GoASTBinaryExpr &) = delete;
- const GoASTBinaryExpr &operator=(const GoASTBinaryExpr &) = delete;
+ GoASTBlockStmt(const GoASTBlockStmt &) = delete;
+ const GoASTBlockStmt &operator=(const GoASTBlockStmt &) = delete;
};
-class GoASTBlockStmt : public GoASTStmt
-{
- public:
- GoASTBlockStmt() : GoASTStmt(eBlockStmt) {}
- ~GoASTBlockStmt() override = default;
+class GoASTIdent : public GoASTExpr {
+public:
+ explicit GoASTIdent(Token name) : GoASTExpr(eIdent), m_name(name) {}
+ ~GoASTIdent() override = default;
- const char *
- GetKindName() const override
- {
- return "BlockStmt";
- }
+ const char *GetKindName() const override { return "Ident"; }
- 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<GoASTStmt>(list));
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eIdent; }
- private:
- friend class GoASTNode;
- std::vector<std::unique_ptr<GoASTStmt> > m_list;
+ Token GetName() const { return m_name; }
+ void SetName(Token name) { m_name = name; }
- GoASTBlockStmt(const GoASTBlockStmt &) = delete;
- const GoASTBlockStmt &operator=(const GoASTBlockStmt &) = delete;
+private:
+ friend class GoASTNode;
+ Token m_name;
+
+ GoASTIdent(const GoASTIdent &) = delete;
+ const GoASTIdent &operator=(const GoASTIdent &) = delete;
};
-class GoASTIdent : public GoASTExpr
-{
- public:
- explicit GoASTIdent(Token name) : GoASTExpr(eIdent), m_name(name) {}
- ~GoASTIdent() override = default;
+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 "Ident";
- }
+ const char *GetKindName() const override { return "BranchStmt"; }
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() == eIdent;
- }
-
- Token
- GetName() const
- {
- return m_name;
- }
- void
- SetName(Token name)
- {
- m_name = name;
- }
+ 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); }
- private:
- friend class GoASTNode;
- Token m_name;
+ TokenType GetTok() const { return m_tok; }
+ void SetTok(TokenType tok) { m_tok = tok; }
- GoASTIdent(const GoASTIdent &) = delete;
- const GoASTIdent &operator=(const GoASTIdent &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTIdent> m_label_up;
+ TokenType m_tok;
+
+ GoASTBranchStmt(const GoASTBranchStmt &) = delete;
+ const GoASTBranchStmt &operator=(const GoASTBranchStmt &) = delete;
};
-class GoASTBranchStmt : public GoASTStmt
-{
- public:
- GoASTBranchStmt(GoASTIdent *label, TokenType tok) : GoASTStmt(eBranchStmt), m_label_up(label), m_tok(tok) {}
- ~GoASTBranchStmt() override = default;
+class GoASTCallExpr : public GoASTExpr {
+public:
+ explicit GoASTCallExpr(bool ellipsis)
+ : GoASTExpr(eCallExpr), m_ellipsis(ellipsis) {}
+ ~GoASTCallExpr() override = default;
- const char *
- GetKindName() const override
- {
- return "BranchStmt";
- }
+ const char *GetKindName() const override { return "CallExpr"; }
- 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eCallExpr; }
- TokenType
- GetTok() const
- {
- return m_tok;
- }
- void
- SetTok(TokenType tok)
- {
- m_tok = tok;
- }
+ 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<GoASTExpr>(args));
+ }
+
+ bool GetEllipsis() const { return m_ellipsis; }
+ void SetEllipsis(bool ellipsis) { m_ellipsis = ellipsis; }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTIdent> m_label_up;
- TokenType m_tok;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_fun_up;
+ std::vector<std::unique_ptr<GoASTExpr>> m_args;
+ bool m_ellipsis;
- GoASTBranchStmt(const GoASTBranchStmt &) = delete;
- const GoASTBranchStmt &operator=(const GoASTBranchStmt &) = delete;
+ GoASTCallExpr(const GoASTCallExpr &) = delete;
+ const GoASTCallExpr &operator=(const GoASTCallExpr &) = delete;
};
-class GoASTCallExpr : public GoASTExpr
-{
- public:
- explicit GoASTCallExpr(bool ellipsis) : GoASTExpr(eCallExpr), m_ellipsis(ellipsis) {}
- ~GoASTCallExpr() override = default;
+class GoASTCaseClause : public GoASTStmt {
+public:
+ GoASTCaseClause() : GoASTStmt(eCaseClause) {}
+ ~GoASTCaseClause() override = default;
- const char *
- GetKindName() const override
- {
- return "CallExpr";
- }
+ const char *GetKindName() const override { return "CaseClause"; }
- 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eCaseClause;
+ }
- 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<GoASTExpr>(args));
- }
+ 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<GoASTExpr>(list));
+ }
- bool
- GetEllipsis() const
- {
- return m_ellipsis;
- }
- void
- SetEllipsis(bool ellipsis)
- {
- m_ellipsis = ellipsis;
- }
+ 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<GoASTStmt>(body));
+ }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTExpr> m_fun_up;
- std::vector<std::unique_ptr<GoASTExpr> > m_args;
- bool m_ellipsis;
+private:
+ friend class GoASTNode;
+ std::vector<std::unique_ptr<GoASTExpr>> m_list;
+ std::vector<std::unique_ptr<GoASTStmt>> m_body;
- GoASTCallExpr(const GoASTCallExpr &) = delete;
- const GoASTCallExpr &operator=(const GoASTCallExpr &) = delete;
+ GoASTCaseClause(const GoASTCaseClause &) = delete;
+ const GoASTCaseClause &operator=(const GoASTCaseClause &) = delete;
};
-class GoASTCaseClause : public GoASTStmt
-{
- public:
- GoASTCaseClause() : GoASTStmt(eCaseClause) {}
- ~GoASTCaseClause() override = default;
+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 "CaseClause";
- }
+ const char *GetKindName() const override { return "ChanType"; }
- 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<GoASTExpr>(list));
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eChanType; }
- 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<GoASTStmt>(body));
- }
+ 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;
- std::vector<std::unique_ptr<GoASTExpr> > m_list;
- std::vector<std::unique_ptr<GoASTStmt> > m_body;
+private:
+ friend class GoASTNode;
+ ChanDir m_dir;
+ std::unique_ptr<GoASTExpr> m_value_up;
- GoASTCaseClause(const GoASTCaseClause &) = delete;
- const GoASTCaseClause &operator=(const GoASTCaseClause &) = delete;
+ GoASTChanType(const GoASTChanType &) = delete;
+ const GoASTChanType &operator=(const GoASTChanType &) = delete;
};
-class GoASTChanType : public GoASTExpr
-{
- public:
- GoASTChanType(ChanDir dir, GoASTExpr *value) : GoASTExpr(eChanType), m_dir(dir), m_value_up(value) {}
- ~GoASTChanType() override = default;
+class GoASTCommClause : public GoASTStmt {
+public:
+ GoASTCommClause() : GoASTStmt(eCommClause) {}
+ ~GoASTCommClause() override = default;
- const char *
- GetKindName() const override
- {
- return "ChanType";
- }
+ const char *GetKindName() const override { return "CommClause"; }
- static bool
- classof(const GoASTNode *n)
- {
- return n->GetKind() == eChanType;
- }
-
- ChanDir
- GetDir() const
- {
- return m_dir;
- }
- void
- SetDir(ChanDir dir)
- {
- m_dir = dir;
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eCommClause;
+ }
- const GoASTExpr *
- GetValue() const
- {
- return m_value_up.get();
- }
- void
- SetValue(GoASTExpr *value)
- {
- m_value_up.reset(value);
- }
+ const GoASTStmt *GetComm() const { return m_comm_up.get(); }
+ void SetComm(GoASTStmt *comm) { m_comm_up.reset(comm); }
- private:
- friend class GoASTNode;
- ChanDir m_dir;
- std::unique_ptr<GoASTExpr> m_value_up;
+ 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<GoASTStmt>(body));
+ }
- GoASTChanType(const GoASTChanType &) = delete;
- const GoASTChanType &operator=(const GoASTChanType &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTStmt> m_comm_up;
+ std::vector<std::unique_ptr<GoASTStmt>> m_body;
+
+ GoASTCommClause(const GoASTCommClause &) = delete;
+ const GoASTCommClause &operator=(const GoASTCommClause &) = delete;
};
-class GoASTCommClause : public GoASTStmt
-{
- public:
- GoASTCommClause() : GoASTStmt(eCommClause) {}
- ~GoASTCommClause() override = default;
+class GoASTCompositeLit : public GoASTExpr {
+public:
+ GoASTCompositeLit() : GoASTExpr(eCompositeLit) {}
+ ~GoASTCompositeLit() override = default;
- const char *
- GetKindName() const override
- {
- return "CommClause";
- }
+ const char *GetKindName() const override { return "CompositeLit"; }
- 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eCompositeLit;
+ }
- 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<GoASTStmt>(body));
- }
+ 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<GoASTExpr>(elts));
+ }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTStmt> m_comm_up;
- std::vector<std::unique_ptr<GoASTStmt> > m_body;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_type_up;
+ std::vector<std::unique_ptr<GoASTExpr>> m_elts;
- GoASTCommClause(const GoASTCommClause &) = delete;
- const GoASTCommClause &operator=(const GoASTCommClause &) = delete;
+ GoASTCompositeLit(const GoASTCompositeLit &) = delete;
+ const GoASTCompositeLit &operator=(const GoASTCompositeLit &) = delete;
};
-class GoASTCompositeLit : public GoASTExpr
-{
- public:
- GoASTCompositeLit() : GoASTExpr(eCompositeLit) {}
- ~GoASTCompositeLit() override = default;
+class GoASTDeclStmt : public GoASTStmt {
+public:
+ explicit GoASTDeclStmt(GoASTDecl *decl)
+ : GoASTStmt(eDeclStmt), m_decl_up(decl) {}
+ ~GoASTDeclStmt() override = default;
- const char *
- GetKindName() const override
- {
- return "CompositeLit";
- }
+ const char *GetKindName() const override { return "DeclStmt"; }
- 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eDeclStmt; }
- 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<GoASTExpr>(elts));
- }
+ 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<GoASTExpr> m_type_up;
- std::vector<std::unique_ptr<GoASTExpr> > m_elts;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTDecl> m_decl_up;
- GoASTCompositeLit(const GoASTCompositeLit &) = delete;
- const GoASTCompositeLit &operator=(const GoASTCompositeLit &) = delete;
+ GoASTDeclStmt(const GoASTDeclStmt &) = delete;
+ const GoASTDeclStmt &operator=(const GoASTDeclStmt &) = delete;
};
-class GoASTDeclStmt : public GoASTStmt
-{
- public:
- explicit GoASTDeclStmt(GoASTDecl *decl) : GoASTStmt(eDeclStmt), m_decl_up(decl) {}
- ~GoASTDeclStmt() override = default;
+class GoASTDeferStmt : public GoASTStmt {
+public:
+ explicit GoASTDeferStmt(GoASTCallExpr *call)
+ : GoASTStmt(eDeferStmt), m_call_up(call) {}
+ ~GoASTDeferStmt() override = default;
- const char *
- GetKindName() const override
- {
- return "DeclStmt";
- }
+ const char *GetKindName() const override { return "DeferStmt"; }
- 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);
- }
+ 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<GoASTDecl> m_decl_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTCallExpr> m_call_up;
- GoASTDeclStmt(const GoASTDeclStmt &) = delete;
- const GoASTDeclStmt &operator=(const GoASTDeclStmt &) = delete;
+ GoASTDeferStmt(const GoASTDeferStmt &) = delete;
+ const GoASTDeferStmt &operator=(const GoASTDeferStmt &) = delete;
};
-class GoASTDeferStmt : public GoASTStmt
-{
- public:
- explicit GoASTDeferStmt(GoASTCallExpr *call) : GoASTStmt(eDeferStmt), m_call_up(call) {}
- ~GoASTDeferStmt() override = default;
+class GoASTEllipsis : public GoASTExpr {
+public:
+ explicit GoASTEllipsis(GoASTExpr *elt)
+ : GoASTExpr(eEllipsis), m_elt_up(elt) {}
+ ~GoASTEllipsis() override = default;
- const char *
- GetKindName() const override
- {
- return "DeferStmt";
- }
+ const char *GetKindName() const override { return "Ellipsis"; }
- 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eEllipsis; }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTCallExpr> m_call_up;
+ const GoASTExpr *GetElt() const { return m_elt_up.get(); }
+ void SetElt(GoASTExpr *elt) { m_elt_up.reset(elt); }
- GoASTDeferStmt(const GoASTDeferStmt &) = delete;
- const GoASTDeferStmt &operator=(const GoASTDeferStmt &) = delete;
-};
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_elt_up;
-class GoASTEllipsis : public GoASTExpr
-{
- public:
- explicit GoASTEllipsis(GoASTExpr *elt) : GoASTExpr(eEllipsis), m_elt_up(elt) {}
- ~GoASTEllipsis() override = default;
+ GoASTEllipsis(const GoASTEllipsis &) = delete;
+ const GoASTEllipsis &operator=(const GoASTEllipsis &) = delete;
+};
- const char *
- GetKindName() const override
- {
- return "Ellipsis";
- }
+class GoASTEmptyStmt : public GoASTStmt {
+public:
+ GoASTEmptyStmt() : GoASTStmt(eEmptyStmt) {}
+ ~GoASTEmptyStmt() override = default;
- 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);
- }
+ const char *GetKindName() const override { return "EmptyStmt"; }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTExpr> m_elt_up;
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eEmptyStmt; }
- GoASTEllipsis(const GoASTEllipsis &) = delete;
- const GoASTEllipsis &operator=(const GoASTEllipsis &) = delete;
+ GoASTEmptyStmt(const GoASTEmptyStmt &) = delete;
+ const GoASTEmptyStmt &operator=(const GoASTEmptyStmt &) = 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;
-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"; }
- const char *
- GetKindName() const override
- {
- return "ExprStmt";
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eExprStmt; }
- 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);
- }
+ 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<GoASTExpr> m_x_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_x_up;
- GoASTExprStmt(const GoASTExprStmt &) = delete;
- const GoASTExprStmt &operator=(const GoASTExprStmt &) = delete;
+ GoASTExprStmt(const GoASTExprStmt &) = delete;
+ const GoASTExprStmt &operator=(const GoASTExprStmt &) = delete;
};
-class GoASTField : public GoASTNode
-{
- public:
- GoASTField() : GoASTNode(eField) {}
- ~GoASTField() override = default;
+class GoASTField : public GoASTNode {
+public:
+ GoASTField() : GoASTNode(eField) {}
+ ~GoASTField() override = default;
- const char *
- GetKindName() const override
- {
- return "Field";
- }
+ 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<GoASTIdent>(names));
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eField; }
- const GoASTExpr *
- GetType() const
- {
- return m_type_up.get();
- }
- void
- SetType(GoASTExpr *type)
- {
- m_type_up.reset(type);
- }
+ 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<GoASTIdent>(names));
+ }
- const GoASTBasicLit *
- GetTag() const
- {
- return m_tag_up.get();
- }
- void
- SetTag(GoASTBasicLit *tag)
- {
- m_tag_up.reset(tag);
- }
+ 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<std::unique_ptr<GoASTIdent> > m_names;
- std::unique_ptr<GoASTExpr> m_type_up;
- std::unique_ptr<GoASTBasicLit> m_tag_up;
+private:
+ friend class GoASTNode;
+ std::vector<std::unique_ptr<GoASTIdent>> m_names;
+ std::unique_ptr<GoASTExpr> m_type_up;
+ std::unique_ptr<GoASTBasicLit> m_tag_up;
- GoASTField(const GoASTField &) = delete;
- const GoASTField &operator=(const GoASTField &) = delete;
+ GoASTField(const GoASTField &) = delete;
+ const GoASTField &operator=(const GoASTField &) = delete;
};
-class GoASTFieldList : public GoASTNode
-{
- public:
- GoASTFieldList() : GoASTNode(eFieldList) {}
- ~GoASTFieldList() override = default;
+class GoASTFieldList : public GoASTNode {
+public:
+ GoASTFieldList() : GoASTNode(eFieldList) {}
+ ~GoASTFieldList() override = default;
- const char *
- GetKindName() const override
- {
- return "FieldList";
- }
+ 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<GoASTField>(list));
- }
+ 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<GoASTField>(list));
+ }
- private:
- friend class GoASTNode;
- std::vector<std::unique_ptr<GoASTField> > m_list;
+private:
+ friend class GoASTNode;
+ std::vector<std::unique_ptr<GoASTField>> m_list;
- GoASTFieldList(const GoASTFieldList &) = delete;
- const GoASTFieldList &operator=(const GoASTFieldList &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eForStmt; }
- const GoASTExpr *
- GetCond() const
- {
- return m_cond_up.get();
- }
- void
- SetCond(GoASTExpr *cond)
- {
- m_cond_up.reset(cond);
- }
+ const GoASTStmt *GetInit() const { return m_init_up.get(); }
+ void SetInit(GoASTStmt *init) { m_init_up.reset(init); }
- const GoASTStmt *
- GetPost() const
- {
- return m_post_up.get();
- }
- void
- SetPost(GoASTStmt *post)
- {
- m_post_up.reset(post);
- }
+ 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 *GetPost() const { return m_post_up.get(); }
+ void SetPost(GoASTStmt *post) { m_post_up.reset(post); }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTStmt> m_init_up;
- std::unique_ptr<GoASTExpr> m_cond_up;
- std::unique_ptr<GoASTStmt> m_post_up;
- std::unique_ptr<GoASTBlockStmt> m_body_up;
+ const GoASTBlockStmt *GetBody() const { return m_body_up.get(); }
+ void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); }
- GoASTForStmt(const GoASTForStmt &) = delete;
- const GoASTForStmt &operator=(const GoASTForStmt &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTStmt> m_init_up;
+ std::unique_ptr<GoASTExpr> m_cond_up;
+ std::unique_ptr<GoASTStmt> m_post_up;
+ std::unique_ptr<GoASTBlockStmt> 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eFuncType; }
- const GoASTFieldList *
- GetResults() const
- {
- return m_results_up.get();
- }
- void
- SetResults(GoASTFieldList *results)
- {
- m_results_up.reset(results);
- }
+ 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<GoASTFieldList> m_params_up;
- std::unique_ptr<GoASTFieldList> m_results_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTFieldList> m_params_up;
+ std::unique_ptr<GoASTFieldList> m_results_up;
- GoASTFuncType(const GoASTFuncType &) = delete;
- const GoASTFuncType &operator=(const GoASTFuncType &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eFuncDecl; }
- const GoASTIdent *
- GetName() const
- {
- return m_name_up.get();
- }
- void
- SetName(GoASTIdent *name)
- {
- m_name_up.reset(name);
- }
+ const GoASTFieldList *GetRecv() const { return m_recv_up.get(); }
+ void SetRecv(GoASTFieldList *recv) { m_recv_up.reset(recv); }
- const GoASTFuncType *
- GetType() const
- {
- return m_type_up.get();
- }
- void
- SetType(GoASTFuncType *type)
- {
- m_type_up.reset(type);
- }
+ const GoASTIdent *GetName() const { return m_name_up.get(); }
+ void SetName(GoASTIdent *name) { m_name_up.reset(name); }
- const GoASTBlockStmt *
- GetBody() const
- {
- return m_body_up.get();
- }
- void
- SetBody(GoASTBlockStmt *body)
- {
- m_body_up.reset(body);
- }
+ const GoASTFuncType *GetType() const { return m_type_up.get(); }
+ void SetType(GoASTFuncType *type) { m_type_up.reset(type); }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTFieldList> m_recv_up;
- std::unique_ptr<GoASTIdent> m_name_up;
- std::unique_ptr<GoASTFuncType> m_type_up;
- std::unique_ptr<GoASTBlockStmt> m_body_up;
+ const GoASTBlockStmt *GetBody() const { return m_body_up.get(); }
+ void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); }
- GoASTFuncDecl(const GoASTFuncDecl &) = delete;
- const GoASTFuncDecl &operator=(const GoASTFuncDecl &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTFieldList> m_recv_up;
+ std::unique_ptr<GoASTIdent> m_name_up;
+ std::unique_ptr<GoASTFuncType> m_type_up;
+ std::unique_ptr<GoASTBlockStmt> 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eFuncLit; }
- const GoASTBlockStmt *
- GetBody() const
- {
- return m_body_up.get();
- }
- void
- SetBody(GoASTBlockStmt *body)
- {
- m_body_up.reset(body);
- }
+ 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<GoASTFuncType> m_type_up;
- std::unique_ptr<GoASTBlockStmt> m_body_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTFuncType> m_type_up;
+ std::unique_ptr<GoASTBlockStmt> m_body_up;
- GoASTFuncLit(const GoASTFuncLit &) = delete;
- const GoASTFuncLit &operator=(const GoASTFuncLit &) = delete;
+ 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;
+class GoASTGenDecl : public GoASTDecl {
+public:
+ explicit GoASTGenDecl(TokenType tok) : GoASTDecl(eGenDecl), m_tok(tok) {}
+ ~GoASTGenDecl() override = default;
- const char *
- GetKindName() const override
- {
- return "GenDecl";
- }
+ 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;
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eGenDecl; }
- 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<GoASTSpec>(specs));
- }
+ 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<GoASTSpec>(specs));
+ }
- private:
- friend class GoASTNode;
- TokenType m_tok;
- std::vector<std::unique_ptr<GoASTSpec> > m_specs;
+private:
+ friend class GoASTNode;
+ TokenType m_tok;
+ std::vector<std::unique_ptr<GoASTSpec>> m_specs;
- GoASTGenDecl(const GoASTGenDecl &) = delete;
- const GoASTGenDecl &operator=(const GoASTGenDecl &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eGoStmt; }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTCallExpr> m_call_up;
+ const GoASTCallExpr *GetCall() const { return m_call_up.get(); }
+ void SetCall(GoASTCallExpr *call) { m_call_up.reset(call); }
- GoASTGoStmt(const GoASTGoStmt &) = delete;
- const GoASTGoStmt &operator=(const GoASTGoStmt &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTCallExpr> 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eIfStmt; }
- const GoASTExpr *
- GetCond() const
- {
- return m_cond_up.get();
- }
- void
- SetCond(GoASTExpr *cond)
- {
- m_cond_up.reset(cond);
- }
+ const GoASTStmt *GetInit() const { return m_init_up.get(); }
+ void SetInit(GoASTStmt *init) { m_init_up.reset(init); }
- const GoASTBlockStmt *
- GetBody() const
- {
- return m_body_up.get();
- }
- void
- SetBody(GoASTBlockStmt *body)
- {
- m_body_up.reset(body);
- }
+ const GoASTExpr *GetCond() const { return m_cond_up.get(); }
+ void SetCond(GoASTExpr *cond) { m_cond_up.reset(cond); }
- const GoASTStmt *
- GetEls() const
- {
- return m_els_up.get();
- }
- void
- SetEls(GoASTStmt *els)
- {
- m_els_up.reset(els);
- }
+ 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<GoASTStmt> m_init_up;
- std::unique_ptr<GoASTExpr> m_cond_up;
- std::unique_ptr<GoASTBlockStmt> m_body_up;
- std::unique_ptr<GoASTStmt> m_els_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTStmt> m_init_up;
+ std::unique_ptr<GoASTExpr> m_cond_up;
+ std::unique_ptr<GoASTBlockStmt> m_body_up;
+ std::unique_ptr<GoASTStmt> m_els_up;
- GoASTIfStmt(const GoASTIfStmt &) = delete;
- const GoASTIfStmt &operator=(const GoASTIfStmt &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eImportSpec;
+ }
- const GoASTBasicLit *
- GetPath() const
- {
- return m_path_up.get();
- }
- void
- SetPath(GoASTBasicLit *path)
- {
- m_path_up.reset(path);
- }
+ const GoASTIdent *GetName() const { return m_name_up.get(); }
+ void SetName(GoASTIdent *name) { m_name_up.reset(name); }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTIdent> m_name_up;
- std::unique_ptr<GoASTBasicLit> m_path_up;
+ const GoASTBasicLit *GetPath() const { return m_path_up.get(); }
+ void SetPath(GoASTBasicLit *path) { m_path_up.reset(path); }
- GoASTImportSpec(const GoASTImportSpec &) = delete;
- const GoASTImportSpec &operator=(const GoASTImportSpec &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTIdent> m_name_up;
+ std::unique_ptr<GoASTBasicLit> 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eIncDecStmt;
+ }
- TokenType
- GetTok() const
- {
- return m_tok;
- }
- void
- SetTok(TokenType tok)
- {
- m_tok = tok;
- }
+ 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<GoASTExpr> m_x_up;
- TokenType m_tok;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_x_up;
+ TokenType m_tok;
- GoASTIncDecStmt(const GoASTIncDecStmt &) = delete;
- const GoASTIncDecStmt &operator=(const GoASTIncDecStmt &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eIndexExpr; }
- const GoASTExpr *
- GetIndex() const
- {
- return m_index_up.get();
- }
- void
- SetIndex(GoASTExpr *index)
- {
- m_index_up.reset(index);
- }
+ 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<GoASTExpr> m_x_up;
- std::unique_ptr<GoASTExpr> m_index_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_x_up;
+ std::unique_ptr<GoASTExpr> m_index_up;
- GoASTIndexExpr(const GoASTIndexExpr &) = delete;
- const GoASTIndexExpr &operator=(const GoASTIndexExpr &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ 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<GoASTFieldList> m_methods_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTFieldList> m_methods_up;
- GoASTInterfaceType(const GoASTInterfaceType &) = delete;
- const GoASTInterfaceType &operator=(const GoASTInterfaceType &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eKeyValueExpr;
+ }
- const GoASTExpr *
- GetValue() const
- {
- return m_value_up.get();
- }
- void
- SetValue(GoASTExpr *value)
- {
- m_value_up.reset(value);
- }
+ 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<GoASTExpr> m_key_up;
- std::unique_ptr<GoASTExpr> m_value_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_key_up;
+ std::unique_ptr<GoASTExpr> m_value_up;
- GoASTKeyValueExpr(const GoASTKeyValueExpr &) = delete;
- const GoASTKeyValueExpr &operator=(const GoASTKeyValueExpr &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eLabeledStmt;
+ }
- const GoASTStmt *
- GetStmt() const
- {
- return m_stmt_up.get();
- }
- void
- SetStmt(GoASTStmt *stmt)
- {
- m_stmt_up.reset(stmt);
- }
+ const GoASTIdent *GetLabel() const { return m_label_up.get(); }
+ void SetLabel(GoASTIdent *label) { m_label_up.reset(label); }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTIdent> m_label_up;
- std::unique_ptr<GoASTStmt> m_stmt_up;
+ const GoASTStmt *GetStmt() const { return m_stmt_up.get(); }
+ void SetStmt(GoASTStmt *stmt) { m_stmt_up.reset(stmt); }
- GoASTLabeledStmt(const GoASTLabeledStmt &) = delete;
- const GoASTLabeledStmt &operator=(const GoASTLabeledStmt &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTIdent> m_label_up;
+ std::unique_ptr<GoASTStmt> 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eMapType; }
- const GoASTExpr *
- GetValue() const
- {
- return m_value_up.get();
- }
- void
- SetValue(GoASTExpr *value)
- {
- m_value_up.reset(value);
- }
+ 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<GoASTExpr> m_key_up;
- std::unique_ptr<GoASTExpr> m_value_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_key_up;
+ std::unique_ptr<GoASTExpr> m_value_up;
- GoASTMapType(const GoASTMapType &) = delete;
- const GoASTMapType &operator=(const GoASTMapType &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eParenExpr; }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTExpr> m_x_up;
+ const GoASTExpr *GetX() const { return m_x_up.get(); }
+ void SetX(GoASTExpr *x) { m_x_up.reset(x); }
- GoASTParenExpr(const GoASTParenExpr &) = delete;
- const GoASTParenExpr &operator=(const GoASTParenExpr &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eRangeStmt; }
- const GoASTExpr *
- GetValue() const
- {
- return m_value_up.get();
- }
- void
- SetValue(GoASTExpr *value)
- {
- m_value_up.reset(value);
- }
+ const GoASTExpr *GetKey() const { return m_key_up.get(); }
+ void SetKey(GoASTExpr *key) { m_key_up.reset(key); }
- bool
- GetDefine() const
- {
- return m_define;
- }
- void
- SetDefine(bool define)
- {
- m_define = define;
- }
+ const GoASTExpr *GetValue() const { return m_value_up.get(); }
+ void SetValue(GoASTExpr *value) { m_value_up.reset(value); }
- const GoASTExpr *
- GetX() const
- {
- return m_x_up.get();
- }
- void
- SetX(GoASTExpr *x)
- {
- m_x_up.reset(x);
- }
+ bool GetDefine() const { return m_define; }
+ void SetDefine(bool define) { m_define = define; }
- const GoASTBlockStmt *
- GetBody() const
- {
- return m_body_up.get();
- }
- void
- SetBody(GoASTBlockStmt *body)
- {
- m_body_up.reset(body);
- }
+ 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<GoASTExpr> m_key_up;
- std::unique_ptr<GoASTExpr> m_value_up;
- bool m_define;
- std::unique_ptr<GoASTExpr> m_x_up;
- std::unique_ptr<GoASTBlockStmt> m_body_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_key_up;
+ std::unique_ptr<GoASTExpr> m_value_up;
+ bool m_define;
+ std::unique_ptr<GoASTExpr> m_x_up;
+ std::unique_ptr<GoASTBlockStmt> m_body_up;
- GoASTRangeStmt(const GoASTRangeStmt &) = delete;
- const GoASTRangeStmt &operator=(const GoASTRangeStmt &) = delete;
+ GoASTRangeStmt(const GoASTRangeStmt &) = delete;
+ const GoASTRangeStmt &operator=(const GoASTRangeStmt &) = delete;
};
-class GoASTReturnStmt : public GoASTStmt
-{
- public:
- GoASTReturnStmt() : GoASTStmt(eReturnStmt) {}
- ~GoASTReturnStmt() override = default;
+class GoASTReturnStmt : public GoASTStmt {
+public:
+ GoASTReturnStmt() : GoASTStmt(eReturnStmt) {}
+ ~GoASTReturnStmt() override = default;
- const char *
- GetKindName() const override
- {
- return "ReturnStmt";
- }
+ 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<GoASTExpr>(results));
- }
+ 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<GoASTExpr>(results));
+ }
- private:
- friend class GoASTNode;
- std::vector<std::unique_ptr<GoASTExpr> > m_results;
+private:
+ friend class GoASTNode;
+ std::vector<std::unique_ptr<GoASTExpr>> m_results;
- GoASTReturnStmt(const GoASTReturnStmt &) = delete;
- const GoASTReturnStmt &operator=(const GoASTReturnStmt &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eSelectStmt;
+ }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTBlockStmt> m_body_up;
+ const GoASTBlockStmt *GetBody() const { return m_body_up.get(); }
+ void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); }
- GoASTSelectStmt(const GoASTSelectStmt &) = delete;
- const GoASTSelectStmt &operator=(const GoASTSelectStmt &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTBlockStmt> 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eSelectorExpr;
+ }
- const GoASTIdent *
- GetSel() const
- {
- return m_sel_up.get();
- }
- void
- SetSel(GoASTIdent *sel)
- {
- m_sel_up.reset(sel);
- }
+ 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<GoASTExpr> m_x_up;
- std::unique_ptr<GoASTIdent> m_sel_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_x_up;
+ std::unique_ptr<GoASTIdent> m_sel_up;
- GoASTSelectorExpr(const GoASTSelectorExpr &) = delete;
- const GoASTSelectorExpr &operator=(const GoASTSelectorExpr &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eSendStmt; }
- const GoASTExpr *
- GetValue() const
- {
- return m_value_up.get();
- }
- void
- SetValue(GoASTExpr *value)
- {
- m_value_up.reset(value);
- }
+ 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<GoASTExpr> m_chan_up;
- std::unique_ptr<GoASTExpr> m_value_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_chan_up;
+ std::unique_ptr<GoASTExpr> m_value_up;
- GoASTSendStmt(const GoASTSendStmt &) = delete;
- const GoASTSendStmt &operator=(const GoASTSendStmt &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eSliceExpr; }
- const GoASTExpr *
- GetLow() const
- {
- return m_low_up.get();
- }
- void
- SetLow(GoASTExpr *low)
- {
- m_low_up.reset(low);
- }
+ const GoASTExpr *GetX() const { return m_x_up.get(); }
+ void SetX(GoASTExpr *x) { m_x_up.reset(x); }
- const GoASTExpr *
- GetHigh() const
- {
- return m_high_up.get();
- }
- void
- SetHigh(GoASTExpr *high)
- {
- m_high_up.reset(high);
- }
+ const GoASTExpr *GetLow() const { return m_low_up.get(); }
+ void SetLow(GoASTExpr *low) { m_low_up.reset(low); }
- const GoASTExpr *
- GetMax() const
- {
- return m_max_up.get();
- }
- void
- SetMax(GoASTExpr *max)
- {
- m_max_up.reset(max);
- }
+ const GoASTExpr *GetHigh() const { return m_high_up.get(); }
+ void SetHigh(GoASTExpr *high) { m_high_up.reset(high); }
- bool
- GetSlice3() const
- {
- return m_slice3;
- }
- void
- SetSlice3(bool slice3)
- {
- m_slice3 = slice3;
- }
+ const GoASTExpr *GetMax() const { return m_max_up.get(); }
+ void SetMax(GoASTExpr *max) { m_max_up.reset(max); }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTExpr> m_x_up;
- std::unique_ptr<GoASTExpr> m_low_up;
- std::unique_ptr<GoASTExpr> m_high_up;
- std::unique_ptr<GoASTExpr> m_max_up;
- bool m_slice3;
+ bool GetSlice3() const { return m_slice3; }
+ void SetSlice3(bool slice3) { m_slice3 = slice3; }
- GoASTSliceExpr(const GoASTSliceExpr &) = delete;
- const GoASTSliceExpr &operator=(const GoASTSliceExpr &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_x_up;
+ std::unique_ptr<GoASTExpr> m_low_up;
+ std::unique_ptr<GoASTExpr> m_high_up;
+ std::unique_ptr<GoASTExpr> 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;
+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";
- }
+ 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);
- }
+ 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<GoASTExpr> m_x_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_x_up;
- GoASTStarExpr(const GoASTStarExpr &) = delete;
- const GoASTStarExpr &operator=(const GoASTStarExpr &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ 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<GoASTFieldList> m_fields_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTFieldList> m_fields_up;
- GoASTStructType(const GoASTStructType &) = delete;
- const GoASTStructType &operator=(const GoASTStructType &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eSwitchStmt;
+ }
- const GoASTExpr *
- GetTag() const
- {
- return m_tag_up.get();
- }
- void
- SetTag(GoASTExpr *tag)
- {
- m_tag_up.reset(tag);
- }
+ const GoASTStmt *GetInit() const { return m_init_up.get(); }
+ void SetInit(GoASTStmt *init) { m_init_up.reset(init); }
- const GoASTBlockStmt *
- GetBody() const
- {
- return m_body_up.get();
- }
- void
- SetBody(GoASTBlockStmt *body)
- {
- m_body_up.reset(body);
- }
+ 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<GoASTStmt> m_init_up;
- std::unique_ptr<GoASTExpr> m_tag_up;
- std::unique_ptr<GoASTBlockStmt> m_body_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTStmt> m_init_up;
+ std::unique_ptr<GoASTExpr> m_tag_up;
+ std::unique_ptr<GoASTBlockStmt> m_body_up;
- GoASTSwitchStmt(const GoASTSwitchStmt &) = delete;
- const GoASTSwitchStmt &operator=(const GoASTSwitchStmt &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eTypeAssertExpr;
+ }
- const GoASTExpr *
- GetType() const
- {
- return m_type_up.get();
- }
- void
- SetType(GoASTExpr *type)
- {
- m_type_up.reset(type);
- }
+ 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<GoASTExpr> m_x_up;
- std::unique_ptr<GoASTExpr> m_type_up;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTExpr> m_x_up;
+ std::unique_ptr<GoASTExpr> m_type_up;
- GoASTTypeAssertExpr(const GoASTTypeAssertExpr &) = delete;
- const GoASTTypeAssertExpr &operator=(const GoASTTypeAssertExpr &) = delete;
+ 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eTypeSpec; }
- const GoASTExpr *
- GetType() const
- {
- return m_type_up.get();
- }
- void
- SetType(GoASTExpr *type)
- {
- m_type_up.reset(type);
- }
+ const GoASTIdent *GetName() const { return m_name_up.get(); }
+ void SetName(GoASTIdent *name) { m_name_up.reset(name); }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTIdent> m_name_up;
- std::unique_ptr<GoASTExpr> m_type_up;
+ const GoASTExpr *GetType() const { return m_type_up.get(); }
+ void SetType(GoASTExpr *type) { m_type_up.reset(type); }
- GoASTTypeSpec(const GoASTTypeSpec &) = delete;
- const GoASTTypeSpec &operator=(const GoASTTypeSpec &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTIdent> m_name_up;
+ std::unique_ptr<GoASTExpr> 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;
+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";
- }
+ 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);
- }
+ static bool classof(const GoASTNode *n) {
+ return n->GetKind() == eTypeSwitchStmt;
+ }
- const GoASTStmt *
- GetAssign() const
- {
- return m_assign_up.get();
- }
- void
- SetAssign(GoASTStmt *assign)
- {
- m_assign_up.reset(assign);
- }
+ const GoASTStmt *GetInit() const { return m_init_up.get(); }
+ void SetInit(GoASTStmt *init) { m_init_up.reset(init); }
- const GoASTBlockStmt *
- GetBody() const
- {
- return m_body_up.get();
- }
- void
- SetBody(GoASTBlockStmt *body)
- {
- m_body_up.reset(body);
- }
+ const GoASTStmt *GetAssign() const { return m_assign_up.get(); }
+ void SetAssign(GoASTStmt *assign) { m_assign_up.reset(assign); }
- private:
- friend class GoASTNode;
- std::unique_ptr<GoASTStmt> m_init_up;
- std::unique_ptr<GoASTStmt> m_assign_up;
- std::unique_ptr<GoASTBlockStmt> m_body_up;
+ const GoASTBlockStmt *GetBody() const { return m_body_up.get(); }
+ void SetBody(GoASTBlockStmt *body) { m_body_up.reset(body); }
- GoASTTypeSwitchStmt(const GoASTTypeSwitchStmt &) = delete;
- const GoASTTypeSwitchStmt &operator=(const GoASTTypeSwitchStmt &) = delete;
+private:
+ friend class GoASTNode;
+ std::unique_ptr<GoASTStmt> m_init_up;
+ std::unique_ptr<GoASTStmt> m_assign_up;
+ std::unique_ptr<GoASTBlockStmt> 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;
+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";
- }
+ 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;
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eUnaryExpr; }
- const GoASTExpr *
- GetX() const
- {
- return m_x_up.get();
- }
- void
- SetX(GoASTExpr *x)
- {
- m_x_up.reset(x);
- }
+ 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<GoASTExpr> m_x_up;
+private:
+ friend class GoASTNode;
+ TokenType m_op;
+ std::unique_ptr<GoASTExpr> m_x_up;
- GoASTUnaryExpr(const GoASTUnaryExpr &) = delete;
- const GoASTUnaryExpr &operator=(const GoASTUnaryExpr &) = delete;
+ GoASTUnaryExpr(const GoASTUnaryExpr &) = delete;
+ const GoASTUnaryExpr &operator=(const GoASTUnaryExpr &) = delete;
};
-class GoASTValueSpec : public GoASTSpec
-{
- public:
- GoASTValueSpec() : GoASTSpec(eValueSpec) {}
- ~GoASTValueSpec() override = default;
+class GoASTValueSpec : public GoASTSpec {
+public:
+ GoASTValueSpec() : GoASTSpec(eValueSpec) {}
+ ~GoASTValueSpec() override = default;
- const char *
- GetKindName() const override
- {
- return "ValueSpec";
- }
+ 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<GoASTIdent>(names));
- }
+ static bool classof(const GoASTNode *n) { return n->GetKind() == eValueSpec; }
- const GoASTExpr *
- GetType() const
- {
- return m_type_up.get();
- }
- void
- SetType(GoASTExpr *type)
- {
- m_type_up.reset(type);
- }
+ 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<GoASTIdent>(names));
+ }
- 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<GoASTExpr>(values));
- }
+ const GoASTExpr *GetType() const { return m_type_up.get(); }
+ void SetType(GoASTExpr *type) { m_type_up.reset(type); }
- private:
- friend class GoASTNode;
- std::vector<std::unique_ptr<GoASTIdent> > m_names;
- std::unique_ptr<GoASTExpr> m_type_up;
- std::vector<std::unique_ptr<GoASTExpr> > m_values;
+ 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<GoASTExpr>(values));
+ }
- GoASTValueSpec(const GoASTValueSpec &) = delete;
- const GoASTValueSpec &operator=(const GoASTValueSpec &) = delete;
-};
+private:
+ friend class GoASTNode;
+ std::vector<std::unique_ptr<GoASTIdent>> m_names;
+ std::unique_ptr<GoASTExpr> m_type_up;
+ std::vector<std::unique_ptr<GoASTExpr>> m_values;
+ GoASTValueSpec(const GoASTValueSpec &) = delete;
+ const GoASTValueSpec &operator=(const GoASTValueSpec &) = delete;
+};
-template <typename R, typename V>
-R GoASTDecl::Visit(V* v) const
-{
- switch(GetKind())
- {
- case eBadDecl:
- return v->VisitBadDecl(llvm::cast<const GoASTBadDecl>(this));
- case eFuncDecl:
- return v->VisitFuncDecl(llvm::cast<const GoASTFuncDecl>(this));
- case eGenDecl:
- return v->VisitGenDecl(llvm::cast<const GoASTGenDecl>(this));
- default:
- assert(false && "Invalid kind");
- }
+template <typename R, typename V> R GoASTDecl::Visit(V *v) const {
+ switch (GetKind()) {
+ case eBadDecl:
+ return v->VisitBadDecl(llvm::cast<const GoASTBadDecl>(this));
+ case eFuncDecl:
+ return v->VisitFuncDecl(llvm::cast<const GoASTFuncDecl>(this));
+ case eGenDecl:
+ return v->VisitGenDecl(llvm::cast<const GoASTGenDecl>(this));
+ default:
+ assert(false && "Invalid kind");
+ }
}
-template <typename R, typename V>
-R GoASTExpr::Visit(V* v) const
-{
- switch(GetKind())
- {
- case eArrayType:
- return v->VisitArrayType(llvm::cast<const GoASTArrayType>(this));
- case eBadExpr:
- return v->VisitBadExpr(llvm::cast<const GoASTBadExpr>(this));
- case eBasicLit:
- return v->VisitBasicLit(llvm::cast<const GoASTBasicLit>(this));
- case eBinaryExpr:
- return v->VisitBinaryExpr(llvm::cast<const GoASTBinaryExpr>(this));
- case eIdent:
- return v->VisitIdent(llvm::cast<const GoASTIdent>(this));
- case eCallExpr:
- return v->VisitCallExpr(llvm::cast<const GoASTCallExpr>(this));
- case eChanType:
- return v->VisitChanType(llvm::cast<const GoASTChanType>(this));
- case eCompositeLit:
- return v->VisitCompositeLit(llvm::cast<const GoASTCompositeLit>(this));
- case eEllipsis:
- return v->VisitEllipsis(llvm::cast<const GoASTEllipsis>(this));
- case eFuncType:
- return v->VisitFuncType(llvm::cast<const GoASTFuncType>(this));
- case eFuncLit:
- return v->VisitFuncLit(llvm::cast<const GoASTFuncLit>(this));
- case eIndexExpr:
- return v->VisitIndexExpr(llvm::cast<const GoASTIndexExpr>(this));
- case eInterfaceType:
- return v->VisitInterfaceType(llvm::cast<const GoASTInterfaceType>(this));
- case eKeyValueExpr:
- return v->VisitKeyValueExpr(llvm::cast<const GoASTKeyValueExpr>(this));
- case eMapType:
- return v->VisitMapType(llvm::cast<const GoASTMapType>(this));
- case eParenExpr:
- return v->VisitParenExpr(llvm::cast<const GoASTParenExpr>(this));
- case eSelectorExpr:
- return v->VisitSelectorExpr(llvm::cast<const GoASTSelectorExpr>(this));
- case eSliceExpr:
- return v->VisitSliceExpr(llvm::cast<const GoASTSliceExpr>(this));
- case eStarExpr:
- return v->VisitStarExpr(llvm::cast<const GoASTStarExpr>(this));
- case eStructType:
- return v->VisitStructType(llvm::cast<const GoASTStructType>(this));
- case eTypeAssertExpr:
- return v->VisitTypeAssertExpr(llvm::cast<const GoASTTypeAssertExpr>(this));
- case eUnaryExpr:
- return v->VisitUnaryExpr(llvm::cast<const GoASTUnaryExpr>(this));
- default:
- assert(false && "Invalid kind");
- return R();
- }
+template <typename R, typename V> R GoASTExpr::Visit(V *v) const {
+ switch (GetKind()) {
+ case eArrayType:
+ return v->VisitArrayType(llvm::cast<const GoASTArrayType>(this));
+ case eBadExpr:
+ return v->VisitBadExpr(llvm::cast<const GoASTBadExpr>(this));
+ case eBasicLit:
+ return v->VisitBasicLit(llvm::cast<const GoASTBasicLit>(this));
+ case eBinaryExpr:
+ return v->VisitBinaryExpr(llvm::cast<const GoASTBinaryExpr>(this));
+ case eIdent:
+ return v->VisitIdent(llvm::cast<const GoASTIdent>(this));
+ case eCallExpr:
+ return v->VisitCallExpr(llvm::cast<const GoASTCallExpr>(this));
+ case eChanType:
+ return v->VisitChanType(llvm::cast<const GoASTChanType>(this));
+ case eCompositeLit:
+ return v->VisitCompositeLit(llvm::cast<const GoASTCompositeLit>(this));
+ case eEllipsis:
+ return v->VisitEllipsis(llvm::cast<const GoASTEllipsis>(this));
+ case eFuncType:
+ return v->VisitFuncType(llvm::cast<const GoASTFuncType>(this));
+ case eFuncLit:
+ return v->VisitFuncLit(llvm::cast<const GoASTFuncLit>(this));
+ case eIndexExpr:
+ return v->VisitIndexExpr(llvm::cast<const GoASTIndexExpr>(this));
+ case eInterfaceType:
+ return v->VisitInterfaceType(llvm::cast<const GoASTInterfaceType>(this));
+ case eKeyValueExpr:
+ return v->VisitKeyValueExpr(llvm::cast<const GoASTKeyValueExpr>(this));
+ case eMapType:
+ return v->VisitMapType(llvm::cast<const GoASTMapType>(this));
+ case eParenExpr:
+ return v->VisitParenExpr(llvm::cast<const GoASTParenExpr>(this));
+ case eSelectorExpr:
+ return v->VisitSelectorExpr(llvm::cast<const GoASTSelectorExpr>(this));
+ case eSliceExpr:
+ return v->VisitSliceExpr(llvm::cast<const GoASTSliceExpr>(this));
+ case eStarExpr:
+ return v->VisitStarExpr(llvm::cast<const GoASTStarExpr>(this));
+ case eStructType:
+ return v->VisitStructType(llvm::cast<const GoASTStructType>(this));
+ case eTypeAssertExpr:
+ return v->VisitTypeAssertExpr(llvm::cast<const GoASTTypeAssertExpr>(this));
+ case eUnaryExpr:
+ return v->VisitUnaryExpr(llvm::cast<const GoASTUnaryExpr>(this));
+ default:
+ assert(false && "Invalid kind");
+ return R();
+ }
}
-template <typename R, typename V>
-R GoASTSpec::Visit(V* v) const
-{
- switch(GetKind())
- {
- case eImportSpec:
- return v->VisitImportSpec(llvm::cast<const GoASTImportSpec>(this));
- case eTypeSpec:
- return v->VisitTypeSpec(llvm::cast<const GoASTTypeSpec>(this));
- case eValueSpec:
- return v->VisitValueSpec(llvm::cast<const GoASTValueSpec>(this));
- default:
- assert(false && "Invalid kind");
- }
+template <typename R, typename V> R GoASTSpec::Visit(V *v) const {
+ switch (GetKind()) {
+ case eImportSpec:
+ return v->VisitImportSpec(llvm::cast<const GoASTImportSpec>(this));
+ case eTypeSpec:
+ return v->VisitTypeSpec(llvm::cast<const GoASTTypeSpec>(this));
+ case eValueSpec:
+ return v->VisitValueSpec(llvm::cast<const GoASTValueSpec>(this));
+ default:
+ assert(false && "Invalid kind");
+ }
}
-template <typename R, typename V>
-R GoASTStmt::Visit(V* v) const
-{
- switch(GetKind())
- {
- case eAssignStmt:
- return v->VisitAssignStmt(llvm::cast<const GoASTAssignStmt>(this));
- case eBadStmt:
- return v->VisitBadStmt(llvm::cast<const GoASTBadStmt>(this));
- case eBlockStmt:
- return v->VisitBlockStmt(llvm::cast<const GoASTBlockStmt>(this));
- case eBranchStmt:
- return v->VisitBranchStmt(llvm::cast<const GoASTBranchStmt>(this));
- case eCaseClause:
- return v->VisitCaseClause(llvm::cast<const GoASTCaseClause>(this));
- case eCommClause:
- return v->VisitCommClause(llvm::cast<const GoASTCommClause>(this));
- case eDeclStmt:
- return v->VisitDeclStmt(llvm::cast<const GoASTDeclStmt>(this));
- case eDeferStmt:
- return v->VisitDeferStmt(llvm::cast<const GoASTDeferStmt>(this));
- case eEmptyStmt:
- return v->VisitEmptyStmt(llvm::cast<const GoASTEmptyStmt>(this));
- case eExprStmt:
- return v->VisitExprStmt(llvm::cast<const GoASTExprStmt>(this));
- case eForStmt:
- return v->VisitForStmt(llvm::cast<const GoASTForStmt>(this));
- case eGoStmt:
- return v->VisitGoStmt(llvm::cast<const GoASTGoStmt>(this));
- case eIfStmt:
- return v->VisitIfStmt(llvm::cast<const GoASTIfStmt>(this));
- case eIncDecStmt:
- return v->VisitIncDecStmt(llvm::cast<const GoASTIncDecStmt>(this));
- case eLabeledStmt:
- return v->VisitLabeledStmt(llvm::cast<const GoASTLabeledStmt>(this));
- case eRangeStmt:
- return v->VisitRangeStmt(llvm::cast<const GoASTRangeStmt>(this));
- case eReturnStmt:
- return v->VisitReturnStmt(llvm::cast<const GoASTReturnStmt>(this));
- case eSelectStmt:
- return v->VisitSelectStmt(llvm::cast<const GoASTSelectStmt>(this));
- case eSendStmt:
- return v->VisitSendStmt(llvm::cast<const GoASTSendStmt>(this));
- case eSwitchStmt:
- return v->VisitSwitchStmt(llvm::cast<const GoASTSwitchStmt>(this));
- case eTypeSwitchStmt:
- return v->VisitTypeSwitchStmt(llvm::cast<const GoASTTypeSwitchStmt>(this));
- default:
- assert(false && "Invalid kind");
- }
+template <typename R, typename V> R GoASTStmt::Visit(V *v) const {
+ switch (GetKind()) {
+ case eAssignStmt:
+ return v->VisitAssignStmt(llvm::cast<const GoASTAssignStmt>(this));
+ case eBadStmt:
+ return v->VisitBadStmt(llvm::cast<const GoASTBadStmt>(this));
+ case eBlockStmt:
+ return v->VisitBlockStmt(llvm::cast<const GoASTBlockStmt>(this));
+ case eBranchStmt:
+ return v->VisitBranchStmt(llvm::cast<const GoASTBranchStmt>(this));
+ case eCaseClause:
+ return v->VisitCaseClause(llvm::cast<const GoASTCaseClause>(this));
+ case eCommClause:
+ return v->VisitCommClause(llvm::cast<const GoASTCommClause>(this));
+ case eDeclStmt:
+ return v->VisitDeclStmt(llvm::cast<const GoASTDeclStmt>(this));
+ case eDeferStmt:
+ return v->VisitDeferStmt(llvm::cast<const GoASTDeferStmt>(this));
+ case eEmptyStmt:
+ return v->VisitEmptyStmt(llvm::cast<const GoASTEmptyStmt>(this));
+ case eExprStmt:
+ return v->VisitExprStmt(llvm::cast<const GoASTExprStmt>(this));
+ case eForStmt:
+ return v->VisitForStmt(llvm::cast<const GoASTForStmt>(this));
+ case eGoStmt:
+ return v->VisitGoStmt(llvm::cast<const GoASTGoStmt>(this));
+ case eIfStmt:
+ return v->VisitIfStmt(llvm::cast<const GoASTIfStmt>(this));
+ case eIncDecStmt:
+ return v->VisitIncDecStmt(llvm::cast<const GoASTIncDecStmt>(this));
+ case eLabeledStmt:
+ return v->VisitLabeledStmt(llvm::cast<const GoASTLabeledStmt>(this));
+ case eRangeStmt:
+ return v->VisitRangeStmt(llvm::cast<const GoASTRangeStmt>(this));
+ case eReturnStmt:
+ return v->VisitReturnStmt(llvm::cast<const GoASTReturnStmt>(this));
+ case eSelectStmt:
+ return v->VisitSelectStmt(llvm::cast<const GoASTSelectStmt>(this));
+ case eSendStmt:
+ return v->VisitSendStmt(llvm::cast<const GoASTSendStmt>(this));
+ case eSwitchStmt:
+ return v->VisitSwitchStmt(llvm::cast<const GoASTSwitchStmt>(this));
+ case eTypeSwitchStmt:
+ return v->VisitTypeSwitchStmt(llvm::cast<const GoASTTypeSwitchStmt>(this));
+ default:
+ assert(false && "Invalid kind");
+ }
}
-template <typename V>
-void GoASTNode::WalkChildren(V &v)
-{
- switch (m_kind)
- {
-
-
- case eArrayType:
- {
- GoASTArrayType *n = llvm::cast<GoASTArrayType>(this);
- (void)n;
- v(n->m_len_up.get());
- v(n->m_elt_up.get());
- return;
- }
- case eAssignStmt:
- {
- GoASTAssignStmt *n = llvm::cast<GoASTAssignStmt>(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<GoASTBasicLit>(this);
- (void)n;
- return;
- }
- case eBinaryExpr:
- {
- GoASTBinaryExpr *n = llvm::cast<GoASTBinaryExpr>(this);
- (void)n;
- v(n->m_x_up.get());
- v(n->m_y_up.get());
- return;
- }
- case eBlockStmt:
- {
- GoASTBlockStmt *n = llvm::cast<GoASTBlockStmt>(this);
- (void)n;
- for (auto& e : n->m_list) { v(e.get()); }
- return;
- }
- case eIdent:
- {
- GoASTIdent *n = llvm::cast<GoASTIdent>(this);
- (void)n;
- return;
- }
- case eBranchStmt:
- {
- GoASTBranchStmt *n = llvm::cast<GoASTBranchStmt>(this);
- (void)n;
- v(n->m_label_up.get());
- return;
- }
- case eCallExpr:
- {
- GoASTCallExpr *n = llvm::cast<GoASTCallExpr>(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<GoASTCaseClause>(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<GoASTChanType>(this);
- (void)n;
- v(n->m_value_up.get());
- return;
- }
- case eCommClause:
- {
- GoASTCommClause *n = llvm::cast<GoASTCommClause>(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<GoASTCompositeLit>(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<GoASTDeclStmt>(this);
- (void)n;
- v(n->m_decl_up.get());
- return;
- }
- case eDeferStmt:
- {
- GoASTDeferStmt *n = llvm::cast<GoASTDeferStmt>(this);
- (void)n;
- v(n->m_call_up.get());
- return;
- }
- case eEllipsis:
- {
- GoASTEllipsis *n = llvm::cast<GoASTEllipsis>(this);
- (void)n;
- v(n->m_elt_up.get());
- return;
- }
- case eExprStmt:
- {
- GoASTExprStmt *n = llvm::cast<GoASTExprStmt>(this);
- (void)n;
- v(n->m_x_up.get());
- return;
- }
- case eField:
- {
- GoASTField *n = llvm::cast<GoASTField>(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<GoASTFieldList>(this);
- (void)n;
- for (auto& e : n->m_list) { v(e.get()); }
- return;
- }
- case eForStmt:
- {
- GoASTForStmt *n = llvm::cast<GoASTForStmt>(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<GoASTFuncType>(this);
- (void)n;
- v(n->m_params_up.get());
- v(n->m_results_up.get());
- return;
- }
- case eFuncDecl:
- {
- GoASTFuncDecl *n = llvm::cast<GoASTFuncDecl>(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<GoASTFuncLit>(this);
- (void)n;
- v(n->m_type_up.get());
- v(n->m_body_up.get());
- return;
- }
- case eGenDecl:
- {
- GoASTGenDecl *n = llvm::cast<GoASTGenDecl>(this);
- (void)n;
- for (auto& e : n->m_specs) { v(e.get()); }
- return;
- }
- case eGoStmt:
- {
- GoASTGoStmt *n = llvm::cast<GoASTGoStmt>(this);
- (void)n;
- v(n->m_call_up.get());
- return;
- }
- case eIfStmt:
- {
- GoASTIfStmt *n = llvm::cast<GoASTIfStmt>(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<GoASTImportSpec>(this);
- (void)n;
- v(n->m_name_up.get());
- v(n->m_path_up.get());
- return;
- }
- case eIncDecStmt:
- {
- GoASTIncDecStmt *n = llvm::cast<GoASTIncDecStmt>(this);
- (void)n;
- v(n->m_x_up.get());
- return;
- }
- case eIndexExpr:
- {
- GoASTIndexExpr *n = llvm::cast<GoASTIndexExpr>(this);
- (void)n;
- v(n->m_x_up.get());
- v(n->m_index_up.get());
- return;
- }
- case eInterfaceType:
- {
- GoASTInterfaceType *n = llvm::cast<GoASTInterfaceType>(this);
- (void)n;
- v(n->m_methods_up.get());
- return;
- }
- case eKeyValueExpr:
- {
- GoASTKeyValueExpr *n = llvm::cast<GoASTKeyValueExpr>(this);
- (void)n;
- v(n->m_key_up.get());
- v(n->m_value_up.get());
- return;
- }
- case eLabeledStmt:
- {
- GoASTLabeledStmt *n = llvm::cast<GoASTLabeledStmt>(this);
- (void)n;
- v(n->m_label_up.get());
- v(n->m_stmt_up.get());
- return;
- }
- case eMapType:
- {
- GoASTMapType *n = llvm::cast<GoASTMapType>(this);
- (void)n;
- v(n->m_key_up.get());
- v(n->m_value_up.get());
- return;
- }
- case eParenExpr:
- {
- GoASTParenExpr *n = llvm::cast<GoASTParenExpr>(this);
- (void)n;
- v(n->m_x_up.get());
- return;
- }
- case eRangeStmt:
- {
- GoASTRangeStmt *n = llvm::cast<GoASTRangeStmt>(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<GoASTReturnStmt>(this);
- (void)n;
- for (auto& e : n->m_results) { v(e.get()); }
- return;
- }
- case eSelectStmt:
- {
- GoASTSelectStmt *n = llvm::cast<GoASTSelectStmt>(this);
- (void)n;
- v(n->m_body_up.get());
- return;
- }
- case eSelectorExpr:
- {
- GoASTSelectorExpr *n = llvm::cast<GoASTSelectorExpr>(this);
- (void)n;
- v(n->m_x_up.get());
- v(n->m_sel_up.get());
- return;
- }
- case eSendStmt:
- {
- GoASTSendStmt *n = llvm::cast<GoASTSendStmt>(this);
- (void)n;
- v(n->m_chan_up.get());
- v(n->m_value_up.get());
- return;
- }
- case eSliceExpr:
- {
- GoASTSliceExpr *n = llvm::cast<GoASTSliceExpr>(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<GoASTStarExpr>(this);
- (void)n;
- v(n->m_x_up.get());
- return;
- }
- case eStructType:
- {
- GoASTStructType *n = llvm::cast<GoASTStructType>(this);
- (void)n;
- v(n->m_fields_up.get());
- return;
- }
- case eSwitchStmt:
- {
- GoASTSwitchStmt *n = llvm::cast<GoASTSwitchStmt>(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<GoASTTypeAssertExpr>(this);
- (void)n;
- v(n->m_x_up.get());
- v(n->m_type_up.get());
- return;
- }
- case eTypeSpec:
- {
- GoASTTypeSpec *n = llvm::cast<GoASTTypeSpec>(this);
- (void)n;
- v(n->m_name_up.get());
- v(n->m_type_up.get());
- return;
- }
- case eTypeSwitchStmt:
- {
- GoASTTypeSwitchStmt *n = llvm::cast<GoASTTypeSwitchStmt>(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<GoASTUnaryExpr>(this);
- (void)n;
- v(n->m_x_up.get());
- return;
- }
- case eValueSpec:
- {
- GoASTValueSpec *n = llvm::cast<GoASTValueSpec>(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;
- }
+template <typename V> void GoASTNode::WalkChildren(V &v) {
+ switch (m_kind) {
+
+ case eArrayType: {
+ GoASTArrayType *n = llvm::cast<GoASTArrayType>(this);
+ (void)n;
+ v(n->m_len_up.get());
+ v(n->m_elt_up.get());
+ return;
+ }
+ case eAssignStmt: {
+ GoASTAssignStmt *n = llvm::cast<GoASTAssignStmt>(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<GoASTBasicLit>(this);
+ (void)n;
+ return;
+ }
+ case eBinaryExpr: {
+ GoASTBinaryExpr *n = llvm::cast<GoASTBinaryExpr>(this);
+ (void)n;
+ v(n->m_x_up.get());
+ v(n->m_y_up.get());
+ return;
+ }
+ case eBlockStmt: {
+ GoASTBlockStmt *n = llvm::cast<GoASTBlockStmt>(this);
+ (void)n;
+ for (auto &e : n->m_list) {
+ v(e.get());
+ }
+ return;
+ }
+ case eIdent: {
+ GoASTIdent *n = llvm::cast<GoASTIdent>(this);
+ (void)n;
+ return;
+ }
+ case eBranchStmt: {
+ GoASTBranchStmt *n = llvm::cast<GoASTBranchStmt>(this);
+ (void)n;
+ v(n->m_label_up.get());
+ return;
+ }
+ case eCallExpr: {
+ GoASTCallExpr *n = llvm::cast<GoASTCallExpr>(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<GoASTCaseClause>(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<GoASTChanType>(this);
+ (void)n;
+ v(n->m_value_up.get());
+ return;
+ }
+ case eCommClause: {
+ GoASTCommClause *n = llvm::cast<GoASTCommClause>(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<GoASTCompositeLit>(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<GoASTDeclStmt>(this);
+ (void)n;
+ v(n->m_decl_up.get());
+ return;
+ }
+ case eDeferStmt: {
+ GoASTDeferStmt *n = llvm::cast<GoASTDeferStmt>(this);
+ (void)n;
+ v(n->m_call_up.get());
+ return;
+ }
+ case eEllipsis: {
+ GoASTEllipsis *n = llvm::cast<GoASTEllipsis>(this);
+ (void)n;
+ v(n->m_elt_up.get());
+ return;
+ }
+ case eExprStmt: {
+ GoASTExprStmt *n = llvm::cast<GoASTExprStmt>(this);
+ (void)n;
+ v(n->m_x_up.get());
+ return;
+ }
+ case eField: {
+ GoASTField *n = llvm::cast<GoASTField>(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<GoASTFieldList>(this);
+ (void)n;
+ for (auto &e : n->m_list) {
+ v(e.get());
+ }
+ return;
+ }
+ case eForStmt: {
+ GoASTForStmt *n = llvm::cast<GoASTForStmt>(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<GoASTFuncType>(this);
+ (void)n;
+ v(n->m_params_up.get());
+ v(n->m_results_up.get());
+ return;
+ }
+ case eFuncDecl: {
+ GoASTFuncDecl *n = llvm::cast<GoASTFuncDecl>(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<GoASTFuncLit>(this);
+ (void)n;
+ v(n->m_type_up.get());
+ v(n->m_body_up.get());
+ return;
+ }
+ case eGenDecl: {
+ GoASTGenDecl *n = llvm::cast<GoASTGenDecl>(this);
+ (void)n;
+ for (auto &e : n->m_specs) {
+ v(e.get());
+ }
+ return;
+ }
+ case eGoStmt: {
+ GoASTGoStmt *n = llvm::cast<GoASTGoStmt>(this);
+ (void)n;
+ v(n->m_call_up.get());
+ return;
+ }
+ case eIfStmt: {
+ GoASTIfStmt *n = llvm::cast<GoASTIfStmt>(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<GoASTImportSpec>(this);
+ (void)n;
+ v(n->m_name_up.get());
+ v(n->m_path_up.get());
+ return;
+ }
+ case eIncDecStmt: {
+ GoASTIncDecStmt *n = llvm::cast<GoASTIncDecStmt>(this);
+ (void)n;
+ v(n->m_x_up.get());
+ return;
+ }
+ case eIndexExpr: {
+ GoASTIndexExpr *n = llvm::cast<GoASTIndexExpr>(this);
+ (void)n;
+ v(n->m_x_up.get());
+ v(n->m_index_up.get());
+ return;
+ }
+ case eInterfaceType: {
+ GoASTInterfaceType *n = llvm::cast<GoASTInterfaceType>(this);
+ (void)n;
+ v(n->m_methods_up.get());
+ return;
+ }
+ case eKeyValueExpr: {
+ GoASTKeyValueExpr *n = llvm::cast<GoASTKeyValueExpr>(this);
+ (void)n;
+ v(n->m_key_up.get());
+ v(n->m_value_up.get());
+ return;
+ }
+ case eLabeledStmt: {
+ GoASTLabeledStmt *n = llvm::cast<GoASTLabeledStmt>(this);
+ (void)n;
+ v(n->m_label_up.get());
+ v(n->m_stmt_up.get());
+ return;
+ }
+ case eMapType: {
+ GoASTMapType *n = llvm::cast<GoASTMapType>(this);
+ (void)n;
+ v(n->m_key_up.get());
+ v(n->m_value_up.get());
+ return;
+ }
+ case eParenExpr: {
+ GoASTParenExpr *n = llvm::cast<GoASTParenExpr>(this);
+ (void)n;
+ v(n->m_x_up.get());
+ return;
+ }
+ case eRangeStmt: {
+ GoASTRangeStmt *n = llvm::cast<GoASTRangeStmt>(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<GoASTReturnStmt>(this);
+ (void)n;
+ for (auto &e : n->m_results) {
+ v(e.get());
+ }
+ return;
+ }
+ case eSelectStmt: {
+ GoASTSelectStmt *n = llvm::cast<GoASTSelectStmt>(this);
+ (void)n;
+ v(n->m_body_up.get());
+ return;
+ }
+ case eSelectorExpr: {
+ GoASTSelectorExpr *n = llvm::cast<GoASTSelectorExpr>(this);
+ (void)n;
+ v(n->m_x_up.get());
+ v(n->m_sel_up.get());
+ return;
+ }
+ case eSendStmt: {
+ GoASTSendStmt *n = llvm::cast<GoASTSendStmt>(this);
+ (void)n;
+ v(n->m_chan_up.get());
+ v(n->m_value_up.get());
+ return;
+ }
+ case eSliceExpr: {
+ GoASTSliceExpr *n = llvm::cast<GoASTSliceExpr>(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<GoASTStarExpr>(this);
+ (void)n;
+ v(n->m_x_up.get());
+ return;
+ }
+ case eStructType: {
+ GoASTStructType *n = llvm::cast<GoASTStructType>(this);
+ (void)n;
+ v(n->m_fields_up.get());
+ return;
+ }
+ case eSwitchStmt: {
+ GoASTSwitchStmt *n = llvm::cast<GoASTSwitchStmt>(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<GoASTTypeAssertExpr>(this);
+ (void)n;
+ v(n->m_x_up.get());
+ v(n->m_type_up.get());
+ return;
+ }
+ case eTypeSpec: {
+ GoASTTypeSpec *n = llvm::cast<GoASTTypeSpec>(this);
+ (void)n;
+ v(n->m_name_up.get());
+ v(n->m_type_up.get());
+ return;
+ }
+ case eTypeSwitchStmt: {
+ GoASTTypeSwitchStmt *n = llvm::cast<GoASTTypeSwitchStmt>(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<GoASTUnaryExpr>(this);
+ (void)n;
+ v(n->m_x_up.get());
+ return;
+ }
+ case eValueSpec: {
+ GoASTValueSpec *n = llvm::cast<GoASTValueSpec>(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
+} // namespace lldb_private
#endif
-
diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoLexer.cpp b/lldb/source/Plugins/ExpressionParser/Go/GoLexer.cpp
index 6de0f5619ca..63e267eaadc 100644
--- a/lldb/source/Plugins/ExpressionParser/Go/GoLexer.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Go/GoLexer.cpp
@@ -15,388 +15,336 @@ using namespace lldb_private;
llvm::StringMap<GoLexer::TokenType> *GoLexer::m_keywords;
-GoLexer::GoLexer(const char *src) : m_src(src), m_end(src + strlen(src)), m_last_token(TOK_INVALID, "")
-{
-}
+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::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;
- }
- }
+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;
+ }
}
- 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 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;
+ }
+ 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;
+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;
- }
+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();
+ }
+ 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 TOK_INVALID;
+ }
+ return t;
}
-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::DoIdent()
-{
- const char *start = m_src++;
- while (m_src < m_end && IsLetterOrDigit(*m_src))
- {
+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;
}
- 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::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;
- }
+GoLexer::TokenType GoLexer::DoString() {
+ if (*m_src == '`') {
+ while (++m_src < m_end) {
+ if (*m_src == '`') {
+ ++m_src;
+ return LIT_STRING;
+ }
}
return TOK_INVALID;
-}
-
-GoLexer::TokenType
-GoLexer::DoString()
-{
- if (*m_src == '`')
- {
- while (++m_src < m_end)
- {
- if (*m_src == '`')
- {
- ++m_src;
- return LIT_STRING;
- }
- }
+ }
+ 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;
}
- 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;
+ }
+ 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;
+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::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::TokenType> *
-GoLexer::InitKeywords()
-{
- auto &result = *new llvm::StringMap<TokenType>(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;
+llvm::StringMap<GoLexer::TokenType> *GoLexer::InitKeywords() {
+ auto &result = *new llvm::StringMap<TokenType>(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;
}
diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoLexer.h b/lldb/source/Plugins/ExpressionParser/Go/GoLexer.h
index e8e1635bab7..f0b5b336fbe 100644
--- a/lldb/source/Plugins/ExpressionParser/Go/GoLexer.h
+++ b/lldb/source/Plugins/ExpressionParser/Go/GoLexer.h
@@ -10,190 +10,170 @@
#ifndef liblldb_GoLexer_h
#define liblldb_GoLexer_h
-#include "llvm/ADT/StringRef.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;
+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();
+ bool SkipWhitespace();
+ bool SkipComment();
- TokenType InternalLex(bool newline);
+ TokenType InternalLex(bool newline);
- TokenType DoOperator();
+ TokenType DoOperator();
- TokenType DoIdent();
+ TokenType DoIdent();
- TokenType DoNumber();
+ TokenType DoNumber();
- TokenType DoRune();
+ TokenType DoRune();
- TokenType DoString();
+ TokenType DoString();
- static llvm::StringMap<TokenType> *InitKeywords();
+ static llvm::StringMap<TokenType> *InitKeywords();
- static llvm::StringMap<TokenType> *m_keywords;
+ static llvm::StringMap<TokenType> *m_keywords;
- const char *m_src;
- const char *m_end;
- Token m_last_token;
+ const char *m_src;
+ const char *m_end;
+ Token m_last_token;
};
} // namespace lldb_private
diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoParser.cpp b/lldb/source/Plugins/ExpressionParser/Go/GoParser.cpp
index 0f136f7e61d..327b9df43db 100644
--- a/lldb/source/Plugins/ExpressionParser/Go/GoParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Go/GoParser.cpp
@@ -11,1025 +11,870 @@
#include "GoParser.h"
+#include "Plugins/ExpressionParser/Go/GoAST.h"
#include "lldb/Core/Error.h"
#include "llvm/ADT/SmallString.h"
-#include "Plugins/ExpressionParser/Go/GoAST.h"
using namespace lldb_private;
using namespace lldb;
-namespace
-{
-llvm::StringRef
-DescribeToken(GoLexer::TokenType t)
-{
- switch (t)
- {
- case GoLexer::TOK_EOF:
- return "<eof>";
- 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 {
+llvm::StringRef DescribeToken(GoLexer::TokenType t) {
+ switch (t) {
+ case GoLexer::TOK_EOF:
+ return "<eof>";
+ 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;
+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;
+private:
+ llvm::StringRef m_name;
+ GoParser *m_parser;
+ size_t m_pos;
};
-GoParser::GoParser(const char *src) : m_lexer(src), m_pos(0), 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;
- }
+GoParser::GoParser(const char *src) : m_lexer(src), m_pos(0), 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;
+ default:
+ break;
+ }
+ GoASTExpr *expr = Expression();
+ if (expr == nullptr)
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();
+ 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<std::unique_ptr<GoASTExpr>> lhs;
+ for (GoASTExpr *l = MoreExpressionList(); l; l = MoreExpressionList())
+ lhs.push_back(std::unique_ptr<GoASTExpr>(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<GoASTAssignStmt> 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;
-}
-
-GoASTStmt *
-GoParser::Assignment(lldb_private::GoASTExpr *e)
-{
- Rule r("Assignment", this);
- std::vector<std::unique_ptr<GoASTExpr>> lhs;
- for (GoASTExpr *l = MoreExpressionList(); l; l = MoreExpressionList())
- lhs.push_back(std::unique_ptr<GoASTExpr>(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();
+ if (Semicolon())
+ return new GoASTEmptyStmt;
+ return nullptr;
+}
+
+GoASTStmt *GoParser::GoStmt() {
+ if (match(GoLexer::KEYWORD_GO)) {
+ if (GoASTCallExpr *e =
+ llvm::dyn_cast_or_null<GoASTCallExpr>(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<GoASTReturnStmt> 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);
}
- // We don't want to own e until we know this is an assignment.
- std::unique_ptr<GoASTAssignStmt> 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<GoASTCallExpr>(Expression()))
- {
- return FinishStmt(new GoASTGoStmt(e));
- }
- m_last = "call expression";
- m_failed = true;
- return new GoASTBadStmt();
+ return syntaxerror();
+ }
+ default:
+ return PrimaryExpr();
+ }
+}
+
+GoASTExpr *GoParser::OrExpr() {
+ std::unique_ptr<GoASTExpr> 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 nullptr;
-}
-
-GoASTStmt *
-GoParser::ReturnStmt()
-{
- if (match(GoLexer::KEYWORD_RETURN))
- {
- std::unique_ptr<GoASTReturnStmt> r(new GoASTReturnStmt());
- for (GoASTExpr *e = Expression(); e; e = MoreExpressionList())
- r->AddResults(e);
- return FinishStmt(r.release());
+ return l.release();
+ }
+ return nullptr;
+}
+
+GoASTExpr *GoParser::AndExpr() {
+ std::unique_ptr<GoASTExpr> 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 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));
+ return l.release();
+ }
+ return nullptr;
+}
+
+GoASTExpr *GoParser::RelExpr() {
+ std::unique_ptr<GoASTExpr> 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();
}
- if ((tok = match(GoLexer::KEYWORD_FALLTHROUGH)))
- return FinishStmt(new GoASTBranchStmt(nullptr, tok->m_type));
-
- return nullptr;
+ return l.release();
+ }
+ return nullptr;
+}
+
+GoASTExpr *GoParser::AddExpr() {
+ std::unique_ptr<GoASTExpr> 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<GoASTExpr> 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;
}
-GoASTIdent *
-GoParser::Identifier()
-{
- if (auto *tok = match(GoLexer::TOK_IDENTIFIER))
- return new GoASTIdent(*tok);
+GoASTExpr *GoParser::PrimaryExpr() {
+ GoASTExpr *l;
+ GoASTExpr *r;
+ (l = Conversion()) || (l = Operand());
+ if (!l)
return nullptr;
-}
-
-GoASTExpr *
-GoParser::MoreExpressionList()
-{
- if (match(GoLexer::OP_COMMA))
- {
- auto *e = Expression();
- if (!e)
- return syntaxerror();
- return e;
- }
+ 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);
}
-GoASTIdent *
-GoParser::MoreIdentifierList()
-{
- if (match(GoLexer::OP_COMMA))
- {
- auto *i = Identifier();
- if (!i)
- return syntaxerror();
- return i;
- }
+GoASTBlockStmt *GoParser::Block() {
+ if (!match(GoLexer::OP_LBRACE))
return nullptr;
+ std::unique_ptr<GoASTBlockStmt> 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::Expression()
-{
- Rule r("Expression", this);
- if (GoASTExpr *ret = OrExpr())
- return ret;
+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)
+ return r.error();
+ lit->SetType(type);
+ return lit;
}
-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<GoASTExpr> 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();
- }
+GoASTCompositeLit *GoParser::LiteralValue() {
+ if (!match(GoLexer::OP_LBRACE))
return nullptr;
-}
-
-GoASTExpr *
-GoParser::AndExpr()
-{
- std::unique_ptr<GoASTExpr> 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();
- }
+ std::unique_ptr<GoASTCompositeLit> 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::RelExpr()
-{
- std::unique_ptr<GoASTExpr> 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();
- }
+GoASTExpr *GoParser::Element() {
+ GoASTExpr *key;
+ if (!((key = Expression()) || (key = LiteralValue())))
return nullptr;
-}
-
-GoASTExpr *
-GoParser::AddExpr()
-{
- std::unique_ptr<GoASTExpr> 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<GoASTExpr> 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)
+ 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<GoASTExpr> 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;
- while ((r = Selector(l)) || (r = IndexOrSlice(l)) || (r = TypeAssertion(l)) || (r = Arguments(l)))
- {
- l = r;
+ return new GoASTTypeAssertExpr(e, t);
}
- return l;
+ return syntaxerror();
+ }
+ return r.error();
}
-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;
+GoASTExpr *GoParser::Arguments(GoASTExpr *e) {
+ if (match(GoLexer::OP_LPAREN)) {
+ std::unique_ptr<GoASTCallExpr> call(new GoASTCallExpr(false));
+ GoASTExpr *arg;
+ // ( ExpressionList | Type [ "," ExpressionList ] )
+ for ((arg = Expression()) || (arg = Type()); arg;
+ arg = MoreExpressionList()) {
+ call->AddArgs(arg);
}
- // MethodExpr should be handled by Selector
- if (GoASTExpr *e = CompositeLit())
- return e;
- if (GoASTExpr *n = Name())
- return n;
- return FunctionLit();
-}
+ if (match(GoLexer::OP_DOTS))
+ call->SetEllipsis(true);
-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);
-}
+ // Eat trailing comma
+ match(GoLexer::OP_COMMA);
-GoASTBlockStmt *
-GoParser::Block()
-{
- if (!match(GoLexer::OP_LBRACE))
- return nullptr;
- std::unique_ptr<GoASTBlockStmt> block(new GoASTBlockStmt);
- for (auto *s = Statement(); s; s = Statement())
- block->AddList(s);
- if (!match(GoLexer::OP_RBRACE))
+ 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()) {
+ if (match(GoLexer::OP_LPAREN)) {
+ GoASTExpr *v = Expression();
+ if (!v)
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)
+ match(GoLexer::OP_COMMA);
+ if (!mustMatch(GoLexer::OP_RPAREN))
return r.error();
- GoASTCompositeLit *lit = LiteralValue();
- if (!lit)
- return r.error();
- lit->SetType(type);
- return lit;
+ GoASTCallExpr *call = new GoASTCallExpr(false);
+ call->SetFun(t);
+ 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;
+ }
}
-GoASTCompositeLit *
-GoParser::LiteralValue()
-{
- if (!match(GoLexer::OP_LBRACE))
- return nullptr;
- std::unique_ptr<GoASTCompositeLit> lit(new GoASTCompositeLit);
- for (GoASTExpr *e = Element(); e; e = Element())
- {
- lit->AddElts(e);
- if (!match(GoLexer::OP_COMMA))
- break;
+GoASTExpr *GoParser::ArrayOrSliceType(bool allowEllipsis) {
+ Rule r("ArrayType", this);
+ if (match(GoLexer::OP_LBRACK)) {
+ std::unique_ptr<GoASTExpr> len;
+ if (allowEllipsis && match(GoLexer::OP_DOTS)) {
+ len.reset(new GoASTEllipsis(nullptr));
+ } else {
+ len.reset(Expression());
}
- 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();
+ 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::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::StructType() {
+ if (!(match(GoLexer::KEYWORD_STRUCT) && mustMatch(GoLexer::OP_LBRACE)))
+ return nullptr;
+ std::unique_ptr<GoASTFieldList> fields(new GoASTFieldList);
+ while (auto *field = FieldDecl())
+ fields->AddList(field);
+ if (!mustMatch(GoLexer::OP_RBRACE))
+ return nullptr;
+ return new GoASTStructType(fields.release());
}
-GoASTExpr *
-GoParser::IndexOrSlice(GoASTExpr *e)
-{
- Rule r("IndexOrSlice", this);
- if (match(GoLexer::OP_LBRACK))
- {
- std::unique_ptr<GoASTExpr> 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();
-}
+GoASTField *GoParser::FieldDecl() {
+ std::unique_ptr<GoASTField> f(new GoASTField);
+ GoASTExpr *t = FieldNamesAndType(f.get());
+ if (!t)
+ t = AnonymousFieldType();
+ if (!t)
+ return nullptr;
-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();
+ if (auto *tok = match(GoLexer::LIT_STRING))
+ f->SetTag(new GoASTBasicLit(*tok));
+ if (!Semicolon())
+ return syntaxerror();
+ return f.release();
}
-GoASTExpr *
-GoParser::Arguments(GoASTExpr *e)
-{
- if (match(GoLexer::OP_LPAREN))
- {
- std::unique_ptr<GoASTCallExpr> 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();
- }
+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::Conversion()
-{
- Rule r("Conversion", this);
- if (GoASTExpr *t = Type2())
- {
- 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);
- call->AddArgs(v);
- return call;
- }
- }
- 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::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::FunctionType() {
+ if (!match(GoLexer::KEYWORD_FUNC))
+ return nullptr;
+ return Signature();
}
-GoASTExpr *
-GoParser::ArrayOrSliceType(bool allowEllipsis)
-{
- Rule r("ArrayType", this);
- if (match(GoLexer::OP_LBRACK))
- {
- std::unique_ptr<GoASTExpr> 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);
+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 r.error();
-}
-
-GoASTExpr *
-GoParser::StructType()
-{
- if (!(match(GoLexer::KEYWORD_STRUCT) && mustMatch(GoLexer::OP_LBRACE)))
- return nullptr;
- std::unique_ptr<GoASTFieldList> fields(new GoASTFieldList);
- while (auto *field = FieldDecl())
- fields->AddList(field);
- if (!mustMatch(GoLexer::OP_RBRACE))
- return nullptr;
- return new GoASTStructType(fields.release());
+ }
+ return new GoASTFuncType(params, result);
}
-GoASTField *
-GoParser::FieldDecl()
-{
- std::unique_ptr<GoASTField> 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);
+GoASTFieldList *GoParser::Params() {
+ if (!match(GoLexer::OP_LPAREN))
+ return nullptr;
+ std::unique_ptr<GoASTFieldList> 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<GoASTField> 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::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<GoASTFieldList> l(new GoASTFieldList);
- while (GoASTField *p = ParamDecl())
- {
- l->AddList(p);
- if (!match(GoLexer::OP_COMMA))
- break;
+GoASTExpr *GoParser::InterfaceType() {
+ if (!match(GoLexer::KEYWORD_INTERFACE) || !mustMatch(GoLexer::OP_LBRACE))
+ return nullptr;
+ std::unique_ptr<GoASTFieldList> methods(new GoASTFieldList);
+ while (true) {
+ Rule r("MethodSpec", this);
+ // ( identifier Signature | TypeName ) ;
+ std::unique_ptr<GoASTIdent> id(Identifier());
+ if (!id)
+ break;
+ GoASTExpr *type = Signature();
+ if (!type) {
+ r.error();
+ id.reset();
+ type = Name();
}
- if (!mustMatch(GoLexer::OP_RPAREN))
- return nullptr;
- return l.release();
-}
-
-GoASTField *
-GoParser::ParamDecl()
-{
- std::unique_ptr<GoASTField> field(new GoASTField);
- GoASTIdent *id = Identifier();
+ if (!Semicolon())
+ return syntaxerror();
+ auto *f = new GoASTField;
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();
- }
+ f->AddNames(id.release());
+ f->SetType(type);
+ methods->AddList(f);
+ }
+ if (!mustMatch(GoLexer::OP_RBRACE))
return nullptr;
+ return new GoASTInterfaceType(methods.release());
}
-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<GoASTFieldList> methods(new GoASTFieldList);
- while (true)
- {
- Rule r("MethodSpec", this);
- // ( identifier Signature | TypeName ) ;
- std::unique_ptr<GoASTIdent> 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<GoASTExpr> 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<GoASTExpr> t(Type());
- if (!t || !match(GoLexer::OP_RPAREN))
- return syntaxerror();
- return t.release();
- }
+GoASTExpr *GoParser::MapType() {
+ if (!(match(GoLexer::KEYWORD_MAP) && mustMatch(GoLexer::OP_LBRACK)))
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;
- }
+ std::unique_ptr<GoASTExpr> 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::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);
- }
+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();
}
-llvm::StringRef
-GoParser::CopyString(llvm::StringRef s)
-{
- return m_strings.insert(std::make_pair(s, 'x')).first->getKey();
+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);
}
-void
-GoParser::GetError(Error &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 = "<eof>";
- else
- got = m_lexer.GetString(len);
- error.SetErrorStringWithFormat("Syntax error: expected %s before '%s'.", want.str().c_str(), got.str().c_str());
+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<GoASTExpr> 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(Error &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 = "<eof>";
+ else
+ got = m_lexer.GetString(len);
+ error.SetErrorStringWithFormat("Syntax error: expected %s before '%s'.",
+ want.str().c_str(), got.str().c_str());
}
diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoParser.h b/lldb/source/Plugins/ExpressionParser/Go/GoParser.h
index 9ceb670ccd1..bd128558022 100644
--- a/lldb/source/Plugins/ExpressionParser/Go/GoParser.h
+++ b/lldb/source/Plugins/ExpressionParser/Go/GoParser.h
@@ -1,4 +1,5 @@
-//===-- GoParser.h -----------------------------------------------*- C++ -*-===//
+//===-- GoParser.h -----------------------------------------------*- C++
+//-*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,155 +11,134 @@
#ifndef liblldb_GoParser_h
#define liblldb_GoParser_h
-#include "lldb/lldb-private.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(Error &error);
-
- private:
- class Rule;
- friend class Rule;
-
- std::nullptr_t
- syntaxerror()
- {
- m_failed = true;
- return nullptr;
+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(Error &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());
}
- 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<GoLexer::Token> m_tokens;
- size_t m_pos;
- llvm::StringRef m_error;
- llvm::StringRef m_last;
- GoLexer::TokenType m_last_tok;
- llvm::StringMap<uint8_t> m_strings;
- bool m_failed;
+ 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<GoLexer::Token> m_tokens;
+ size_t m_pos;
+ llvm::StringRef m_error;
+ llvm::StringRef m_last;
+ GoLexer::TokenType m_last_tok;
+ llvm::StringMap<uint8_t> m_strings;
+ bool m_failed;
};
}
diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
index 5ec8662172c..67b62ceaf7e 100644
--- a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
@@ -20,8 +20,8 @@
#include <vector>
// Other libraries and framework includes
-#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
// Project includes
#include "GoUserExpression.h"
@@ -57,705 +57,621 @@
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;
- }
+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 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
- VisitBinaryExpr(const GoASTBinaryExpr *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitTypeAssertExpr(const GoASTTypeAssertExpr *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitArrayType(const GoASTArrayType *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitBinaryExpr(const GoASTBinaryExpr *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitChanType(const GoASTChanType *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitArrayType(const GoASTArrayType *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitCompositeLit(const GoASTCompositeLit *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitChanType(const GoASTChanType *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitEllipsis(const GoASTEllipsis *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitCompositeLit(const GoASTCompositeLit *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitFuncType(const GoASTFuncType *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitEllipsis(const GoASTEllipsis *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitFuncLit(const GoASTFuncLit *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitFuncType(const GoASTFuncType *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitInterfaceType(const GoASTInterfaceType *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitFuncLit(const GoASTFuncLit *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitKeyValueExpr(const GoASTKeyValueExpr *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitInterfaceType(const GoASTInterfaceType *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitMapType(const GoASTMapType *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitKeyValueExpr(const GoASTKeyValueExpr *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitSliceExpr(const GoASTSliceExpr *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitMapType(const GoASTMapType *e) {
+ return NotImplemented(e);
+ }
- ValueObjectSP
- VisitStructType(const GoASTStructType *e)
- {
- return NotImplemented(e);
- }
+ ValueObjectSP VisitSliceExpr(const GoASTSliceExpr *e) {
+ return NotImplemented(e);
+ }
- CompilerType EvaluateType(const GoASTExpr *e);
+ ValueObjectSP VisitStructType(const GoASTStructType *e) {
+ return NotImplemented(e);
+ }
- Error &
- error()
- {
- return m_error;
- }
+ CompilerType EvaluateType(const GoASTExpr *e);
- private:
- std::nullptr_t
- NotImplemented(const GoASTExpr *e)
- {
- m_error.SetErrorStringWithFormat("%s node not implemented", e->GetKindName());
- return nullptr;
- }
+ Error &error() { return m_error; }
- ExecutionContext m_exe_ctx;
- lldb::StackFrameSP m_frame;
- GoParser m_parser;
- DynamicValueType m_use_dynamic;
- Error m_error;
- llvm::StringRef m_package;
- std::vector<std::unique_ptr<GoASTStmt>> m_statements;
+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;
+ Error m_error;
+ llvm::StringRef m_package;
+ std::vector<std::unique_ptr<GoASTStmt>> m_statements;
};
-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);
- if (match_count == 1)
- {
- return variable_list.GetVariableAtIndex(0);
- }
+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);
+ 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<SymbolFile *> 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();
- }
+CompilerType LookupType(TargetSP target, ConstString name) {
+ if (!target)
return CompilerType();
+ SymbolContext sc;
+ TypeList type_list;
+ llvm::DenseSet<SymbolFile *> 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, const char *expr, const char *expr_prefix,
- lldb::LanguageType language, ResultType desired_type,
+GoUserExpression::GoUserExpression(ExecutionContextScope &exe_scope,
+ const char *expr, const char *expr_prefix,
+ lldb::LanguageType language,
+ ResultType desired_type,
const EvaluateExpressionOptions &options)
- : UserExpression(exe_scope, expr, 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.PutCString(eDiagnosticSeverityError, error_cstr);
- else
- diagnostic_manager.Printf(eDiagnosticSeverityError, "expression can't be interpreted or run");
- return false;
+ : UserExpression(exe_scope, expr, 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.PutCString(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));
+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;
+ lldb_private::ExecutionPolicy execution_policy = options.GetExecutionPolicy();
+ lldb::ExpressionResults execution_results = lldb::eExpressionSetupError;
- Process *process = exe_ctx.GetProcessPtr();
- Target *target = exe_ctx.GetTargetPtr();
+ 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 ==");
+ 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.PutCString(eDiagnosticSeverityError, "expression needed to run but couldn't");
+ diagnostic_manager.PutCString(eDiagnosticSeverityError,
+ "expression needed to run but couldn't");
- return execution_results;
- }
+ return execution_results;
}
+ }
- m_interpreter->set_use_dynamic(options.GetUseDynamic());
- ValueObjectSP result_val_sp = m_interpreter->Evaluate(exe_ctx);
- Error 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.PutCString(eDiagnosticSeverityError, error_cstr);
- else
- diagnostic_manager.PutCString(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());
- pv->AddVariable(result);
- }
- return lldb::eExpressionCompleted;
-}
+ m_interpreter->set_use_dynamic(options.GetUseDynamic());
+ ValueObjectSP result_val_sp = m_interpreter->Evaluate(exe_ctx);
+ Error err = m_interpreter->error();
+ m_interpreter.reset();
-bool
-GoUserExpression::GoInterpreter::Parse()
-{
- for (std::unique_ptr<GoASTStmt> 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);
+ if (!result_val_sp) {
+ const char *error_cstr = err.AsCString();
+ if (error_cstr && error_cstr[0])
+ diagnostic_manager.PutCString(eDiagnosticSeverityError, error_cstr);
+ else
+ diagnostic_manager.PutCString(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());
+ pv->AddVariable(result);
+ }
+ return lldb::eExpressionCompleted;
+}
- return m_error.Success();
+bool GoUserExpression::GoInterpreter::Parse() {
+ for (std::unique_ptr<GoASTStmt> 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<GoASTStmt> &stmt : m_statements)
- {
- result = EvaluateStatement(stmt.get());
- if (m_error.Fail())
- return nullptr;
- }
- return result;
+GoUserExpression::GoInterpreter::Evaluate(ExecutionContext &exe_ctx) {
+ m_exe_ctx = exe_ctx;
+ ValueObjectSP result;
+ for (const std::unique_ptr<GoASTStmt> &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<GoASTBlockStmt>(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<GoASTExprStmt>(stmt);
- return EvaluateExpr(expr->GetX());
- }
- default:
- m_error.SetErrorStringWithFormat("%s node not supported", stmt->GetKindName());
- }
- return result;
+ValueObjectSP GoUserExpression::GoInterpreter::EvaluateStatement(
+ const lldb_private::GoASTStmt *stmt) {
+ ValueObjectSP result;
+ switch (stmt->GetKind()) {
+ case GoASTNode::eBlockStmt: {
+ const GoASTBlockStmt *block = llvm::cast<GoASTBlockStmt>(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<GoASTExprStmt>(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<ValueObjectSP>(this);
- return ValueObjectSP();
+ValueObjectSP GoUserExpression::GoInterpreter::EvaluateExpr(
+ const lldb_private::GoASTExpr *e) {
+ if (e)
+ return e->Visit<ValueObjectSP>(this);
+ return ValueObjectSP();
}
-ValueObjectSP
-GoUserExpression::GoInterpreter::VisitParenExpr(const lldb_private::GoASTParenExpr *e)
-{
- return EvaluateExpr(e->GetX());
+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;
+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;
}
- 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;
- }
- }
+ 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;
}
- 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);
+ }
+ 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.SetErrorStringWithFormat("Unknown variable %s", e->GetName().m_value.str().c_str());
- return val;
+ 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);
+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<GoASTIdent>(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);
- }
- }
+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;
}
- if (const GoASTBasicLit *packageLit = llvm::dyn_cast<GoASTBasicLit>(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);
- }
- }
+ 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<GoASTIdent>(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<GoASTBasicLit>(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;
+ }
+ // 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<uint64_t>(intvalue));
- DataExtractor data(buf, order, addr_size);
-
- CompilerType type = LookupType(target, ConstString("int64"));
- return ValueObject::CreateValueObjectFromData(nullptr, data, m_exe_ctx, type);
+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<uint64_t>(intvalue));
+ DataExtractor data(buf, order, addr_size);
+
+ CompilerType type = LookupType(target, ConstString("int64"));
+ return ValueObject::CreateValueObjectFromData(nullptr, 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");
+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;
+ }
}
- 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);
+ target = target->GetChildMemberWithName(ConstString("array"), true);
+ if (target && m_use_dynamic != eNoDynamicValues) {
+ ValueObjectSP dynamic = target->GetDynamicValue(m_use_dynamic);
+ if (dynamic)
+ target = dynamic;
}
- return target->GetChildAtIndex(idx, true);
+ 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(nullptr, 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;
- }
+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(nullptr, 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<GoASTIdent>(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<GoASTSelectorExpr>(e))
- {
- std::string package;
- if (auto *pkg_node = llvm::dyn_cast<GoASTIdent>(sel->GetX()))
- {
- package = pkg_node->GetName().m_value.str();
- }
- else if (auto *str_node = llvm::dyn_cast<GoASTBasicLit>(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<GoASTStarExpr>(e))
- {
- CompilerType elem = EvaluateType(star->GetX());
- return elem.GetPointerType();
- }
- if (auto *paren = llvm::dyn_cast<GoASTParenExpr>(e))
- return EvaluateType(paren->GetX());
- if (auto *array = llvm::dyn_cast<GoASTArrayType>(e))
- {
- CompilerType elem = EvaluateType(array->GetElt());
- }
-
- m_error.SetErrorStringWithFormat("Invalid %s in type expression", e->GetKindName());
- return CompilerType();
+CompilerType GoUserExpression::GoInterpreter::EvaluateType(const GoASTExpr *e) {
+ TargetSP target = m_exe_ctx.GetTargetSP();
+ if (auto *id = llvm::dyn_cast<GoASTIdent>(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<GoASTSelectorExpr>(e)) {
+ std::string package;
+ if (auto *pkg_node = llvm::dyn_cast<GoASTIdent>(sel->GetX())) {
+ package = pkg_node->GetName().m_value.str();
+ } else if (auto *str_node = llvm::dyn_cast<GoASTBasicLit>(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<GoASTStarExpr>(e)) {
+ CompilerType elem = EvaluateType(star->GetX());
+ return elem.GetPointerType();
+ }
+ if (auto *paren = llvm::dyn_cast<GoASTParenExpr>(e))
+ return EvaluateType(paren->GetX());
+ if (auto *array = llvm::dyn_cast<GoASTArrayType>(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);
+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)
-{
-}
+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;
+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);
+void GoPersistentExpressionState::RemovePersistentVariable(
+ lldb::ExpressionVariableSP variable) {
+ RemoveVariable(variable);
- const char *name = variable->GetName().AsCString();
+ const char *name = variable->GetName().AsCString();
- if (*(name++) != '$')
- return;
- if (*(name++) != 'g')
- return;
- if (*(name++) != 'o')
- return;
+ 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--;
+ if (strtoul(name, nullptr, 0) == m_next_persistent_variable_id - 1)
+ m_next_persistent_variable_id--;
}
diff --git a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h
index 711a4c46215..4976f694bd7 100644
--- a/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h
+++ b/lldb/source/Plugins/ExpressionParser/Go/GoUserExpression.h
@@ -16,83 +16,75 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-forward.h"
-#include "lldb/lldb-private.h"
-#include "lldb/Expression/UserExpression.h"
#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
-{
+namespace lldb_private {
class GoParser;
-class GoPersistentExpressionState : public PersistentExpressionState
-{
- public:
- GoPersistentExpressionState();
+class GoPersistentExpressionState : public PersistentExpressionState {
+public:
+ GoPersistentExpressionState();
- ConstString GetNextPersistentVariableName() override;
+ ConstString GetNextPersistentVariableName() override;
- void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
+ void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
- lldb::addr_t
- LookupSymbol(const ConstString &name) override
- {
- return LLDB_INVALID_ADDRESS;
- }
+ lldb::addr_t LookupSymbol(const ConstString &name) override {
+ return LLDB_INVALID_ADDRESS;
+ }
- static bool
- classof(const PersistentExpressionState *pv)
- {
- return pv->getKind() == PersistentExpressionState::eKindGo;
- }
+ static bool classof(const PersistentExpressionState *pv) {
+ return pv->getKind() == PersistentExpressionState::eKindGo;
+ }
- private:
- uint32_t m_next_persistent_variable_id; ///< The counter used by GetNextResultName().
+private:
+ uint32_t m_next_persistent_variable_id; ///< The counter used by
+ ///GetNextResultName().
};
//----------------------------------------------------------------------
-/// @class GoUserExpression GoUserExpression.h "lldb/Expression/GoUserExpression.h"
+/// @class GoUserExpression GoUserExpression.h
+/// "lldb/Expression/GoUserExpression.h"
/// @brief 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, const char *expr, const char *expr_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<GoInterpreter> m_interpreter;
+class GoUserExpression : public UserExpression {
+public:
+ GoUserExpression(ExecutionContextScope &exe_scope, const char *expr,
+ const char *expr_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<GoInterpreter> m_interpreter;
};
} // namespace lldb_private
diff --git a/lldb/source/Plugins/ExpressionParser/Go/gen_go_ast.py b/lldb/source/Plugins/ExpressionParser/Go/gen_go_ast.py
index 05b589a9976..3be0e5f506e 100644
--- a/lldb/source/Plugins/ExpressionParser/Go/gen_go_ast.py
+++ b/lldb/source/Plugins/ExpressionParser/Go/gen_go_ast.py
@@ -1,8 +1,17 @@
import StringIO
+
def addNodes():
addNode("ArrayType", "Expr", "len", "Expr", "elt", "Expr")
- addNode("AssignStmt", "Stmt", "lhs", "[]Expr", "rhs", "[]Expr", "define", "bool")
+ addNode(
+ "AssignStmt",
+ "Stmt",
+ "lhs",
+ "[]Expr",
+ "rhs",
+ "[]Expr",
+ "define",
+ "bool")
addNode("BadDecl", "Decl")
addNode("BadExpr", "Expr")
addNode("BadStmt", "Stmt")
@@ -11,7 +20,15 @@ def addNodes():
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(
+ "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")
@@ -21,15 +38,53 @@ def addNodes():
addNode("Ellipsis", "Expr", "elt", "Expr")
addNode("EmptyStmt", "Stmt")
addNode("ExprStmt", "Stmt", "x", "Expr")
- addNode("Field", "Node", "names", "[]Ident", "type", "Expr", "tag", "BasicLit")
+ 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(
+ "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(
+ "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(
+ "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")
@@ -38,20 +93,68 @@ def addNodes():
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(
+ "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(
+ "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(
+ "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(
+ "TypeSwitchStmt",
+ "Stmt",
+ "init",
+ "Stmt",
+ "assign",
+ "Stmt",
+ "body",
+ "BlockStmt")
addNode("UnaryExpr", "Expr", "op", "TokenType", "x", "Expr")
- addNode("ValueSpec", "Spec", "names", "[]Ident", "type", "Expr", "values", "[]Expr")
+ addNode(
+ "ValueSpec",
+ "Spec",
+ "names",
+ "[]Ident",
+ "type",
+ "Expr",
+ "values",
+ "[]Expr")
addParent("Decl", "Node")
addParent("Expr", "Node")
addParent("Spec", "Node")
@@ -59,6 +162,7 @@ def addNodes():
class Member(object):
+
def __init__(self, name, typename):
self.title = name.title()
self.sname = name
@@ -75,13 +179,14 @@ class Member(object):
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
@@ -89,6 +194,7 @@ class GoAST%s : public GoAST%s
public:
""" % (name, parent))
+
def endClass(name, out):
out.write("""
%(name)s(const %(name)s &) = delete;
@@ -96,6 +202,7 @@ def endClass(name, out):
};
""" % {'name': 'GoAST' + name})
+
def addNode(name, parent, *children):
startClass(name, parent, childClasses)
l = kinds.setdefault(parent, [])
@@ -114,10 +221,11 @@ def addNode(name, parent, *children):
{
return n->GetKind() == e%(name)s;
}
- """ % {'name':name})
+ """ % {'name': name})
addChildren(name, children)
endClass(name, childClasses)
+
def isValueType(typename):
if typename[0].islower():
return True
@@ -161,7 +269,7 @@ def addConstructor(name, parent, children):
~GoAST%s() override = default;
""" % name)
-
+
def addChildren(name, children):
if len(children) == 0:
return
@@ -169,7 +277,7 @@ def addChildren(name, children):
case e%(n)s:
{
GoAST%(n)s *n = llvm::cast<GoAST%(n)s>(this);
- (void)n;""" % {'n':name})
+ (void)n;""" % {'n': name})
for c in children:
if c.is_list:
childClasses.write("""
@@ -217,14 +325,14 @@ def addChildren(name, children):
{
%(set)s;
}
-""" % {'const':const, 'title': c.title, 'sname': c.sname, 'get': get, 'set': set, 'type': t, 'mname': c.mname})
+""" % {'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))
-
+ childClasses.write(' %s %s;\n' % (c.mtype, c.mname))
+
def addParent(name, parent):
startClass(name, parent, parentClasses)
@@ -244,7 +352,7 @@ def addParent(name, parent):
private:
""" % (minName, maxName, name))
endClass(name, parentClasses)
-
+
addNodes()
print """//===-- GoAST.h -------------------------------------------------*- C++ -*-===//
@@ -305,7 +413,7 @@ print """ };
private:
const NodeKind m_kind;
-
+
GoASTNode(const GoASTNode &) = delete;
const GoASTNode &operator=(const GoASTNode &) = delete;
};
@@ -326,7 +434,7 @@ R GoAST%s::Visit(V* v) const
{""" % k
for subtype in l:
print """ case e%(n)s:
- return v->Visit%(n)s(llvm::cast<const GoAST%(n)s>(this));""" % {'n':subtype}
+ return v->Visit%(n)s(llvm::cast<const GoAST%(n)s>(this));""" % {'n': subtype}
print """ default:
assert(false && "Invalid kind");
OpenPOWER on IntegriCloud