1 //===-- GoParser.h -----------------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef liblldb_GoParser_h
12 #define liblldb_GoParser_h
14 #include "Plugins/ExpressionParser/Go/GoAST.h"
15 #include "Plugins/ExpressionParser/Go/GoLexer.h"
16 #include "lldb/lldb-private.h"
18 namespace lldb_private {
21 explicit GoParser(const char *src);
23 GoASTStmt *Statement();
26 GoASTStmt *ReturnStmt();
27 GoASTStmt *BranchStmt();
28 GoASTStmt *EmptyStmt();
29 GoASTStmt *ExpressionStmt(GoASTExpr *e);
30 GoASTStmt *IncDecStmt(GoASTExpr *e);
31 GoASTStmt *Assignment(GoASTExpr *e);
32 GoASTBlockStmt *Block();
34 GoASTExpr *MoreExpressionList(); // ["," Expression]
35 GoASTIdent *MoreIdentifierList(); // ["," Identifier]
37 GoASTExpr *Expression();
38 GoASTExpr *UnaryExpr();
44 GoASTExpr *PrimaryExpr();
46 GoASTExpr *Conversion();
48 GoASTExpr *Selector(GoASTExpr *e);
49 GoASTExpr *IndexOrSlice(GoASTExpr *e);
50 GoASTExpr *TypeAssertion(GoASTExpr *e);
51 GoASTExpr *Arguments(GoASTExpr *e);
55 GoASTExpr *ArrayOrSliceType(bool allowEllipsis);
56 GoASTExpr *StructType();
57 GoASTExpr *FunctionType();
58 GoASTExpr *InterfaceType();
60 GoASTExpr *ChanType();
61 GoASTExpr *ChanType2();
64 GoASTExpr *QualifiedIdent(GoASTIdent *p);
65 GoASTIdent *Identifier();
67 GoASTField *FieldDecl();
68 GoASTExpr *AnonymousFieldType();
69 GoASTExpr *FieldNamesAndType(GoASTField *f);
71 GoASTFieldList *Params();
72 GoASTField *ParamDecl();
73 GoASTExpr *ParamType();
74 GoASTFuncType *Signature();
75 GoASTExpr *CompositeLit();
76 GoASTExpr *FunctionLit();
78 GoASTCompositeLit *LiteralValue();
80 bool Failed() const { return m_failed; }
82 return m_lexer.BytesRemaining() == 0 && m_pos == m_tokens.size();
85 void GetError(Status &error);
91 std::nullptr_t syntaxerror() {
95 GoLexer::Token &next() {
96 if (m_pos >= m_tokens.size()) {
97 if (m_pos != 0 && (m_tokens.back().m_type == GoLexer::TOK_EOF ||
98 m_tokens.back().m_type == GoLexer::TOK_INVALID))
99 return m_tokens.back();
100 m_pos = m_tokens.size();
101 m_tokens.push_back(m_lexer.Lex());
103 return m_tokens[m_pos++];
105 GoLexer::TokenType peek() {
106 GoLexer::Token &tok = next();
110 GoLexer::Token *match(GoLexer::TokenType t) {
111 GoLexer::Token &tok = next();
118 GoLexer::Token *mustMatch(GoLexer::TokenType t) {
119 GoLexer::Token *tok = match(t);
122 return syntaxerror();
126 GoASTStmt *FinishStmt(GoASTStmt *s) {
132 llvm::StringRef CopyString(llvm::StringRef s);
135 std::vector<GoLexer::Token> m_tokens;
137 llvm::StringRef m_error;
138 llvm::StringRef m_last;
139 GoLexer::TokenType m_last_tok;
140 llvm::StringMap<uint8_t> m_strings;