]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/ExpressionParser/Go/GoParser.h
MFC r345805: Unify SCSI_STATUS_BUSY retry handling with other cases.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / ExpressionParser / Go / GoParser.h
1 //===-- GoParser.h -----------------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef liblldb_GoParser_h
12 #define liblldb_GoParser_h
13
14 #include "Plugins/ExpressionParser/Go/GoAST.h"
15 #include "Plugins/ExpressionParser/Go/GoLexer.h"
16 #include "lldb/lldb-private.h"
17
18 namespace lldb_private {
19 class GoParser {
20 public:
21   explicit GoParser(const char *src);
22
23   GoASTStmt *Statement();
24
25   GoASTStmt *GoStmt();
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();
33
34   GoASTExpr *MoreExpressionList();  // ["," Expression]
35   GoASTIdent *MoreIdentifierList(); // ["," Identifier]
36
37   GoASTExpr *Expression();
38   GoASTExpr *UnaryExpr();
39   GoASTExpr *OrExpr();
40   GoASTExpr *AndExpr();
41   GoASTExpr *RelExpr();
42   GoASTExpr *AddExpr();
43   GoASTExpr *MulExpr();
44   GoASTExpr *PrimaryExpr();
45   GoASTExpr *Operand();
46   GoASTExpr *Conversion();
47
48   GoASTExpr *Selector(GoASTExpr *e);
49   GoASTExpr *IndexOrSlice(GoASTExpr *e);
50   GoASTExpr *TypeAssertion(GoASTExpr *e);
51   GoASTExpr *Arguments(GoASTExpr *e);
52
53   GoASTExpr *Type();
54   GoASTExpr *Type2();
55   GoASTExpr *ArrayOrSliceType(bool allowEllipsis);
56   GoASTExpr *StructType();
57   GoASTExpr *FunctionType();
58   GoASTExpr *InterfaceType();
59   GoASTExpr *MapType();
60   GoASTExpr *ChanType();
61   GoASTExpr *ChanType2();
62
63   GoASTExpr *Name();
64   GoASTExpr *QualifiedIdent(GoASTIdent *p);
65   GoASTIdent *Identifier();
66
67   GoASTField *FieldDecl();
68   GoASTExpr *AnonymousFieldType();
69   GoASTExpr *FieldNamesAndType(GoASTField *f);
70
71   GoASTFieldList *Params();
72   GoASTField *ParamDecl();
73   GoASTExpr *ParamType();
74   GoASTFuncType *Signature();
75   GoASTExpr *CompositeLit();
76   GoASTExpr *FunctionLit();
77   GoASTExpr *Element();
78   GoASTCompositeLit *LiteralValue();
79
80   bool Failed() const { return m_failed; }
81   bool AtEOF() const {
82     return m_lexer.BytesRemaining() == 0 && m_pos == m_tokens.size();
83   }
84
85   void GetError(Status &error);
86
87 private:
88   class Rule;
89   friend class Rule;
90
91   std::nullptr_t syntaxerror() {
92     m_failed = true;
93     return nullptr;
94   }
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());
102     }
103     return m_tokens[m_pos++];
104   }
105   GoLexer::TokenType peek() {
106     GoLexer::Token &tok = next();
107     --m_pos;
108     return tok.m_type;
109   }
110   GoLexer::Token *match(GoLexer::TokenType t) {
111     GoLexer::Token &tok = next();
112     if (tok.m_type == t)
113       return &tok;
114     --m_pos;
115     m_last_tok = t;
116     return nullptr;
117   }
118   GoLexer::Token *mustMatch(GoLexer::TokenType t) {
119     GoLexer::Token *tok = match(t);
120     if (tok)
121       return tok;
122     return syntaxerror();
123   }
124   bool Semicolon();
125
126   GoASTStmt *FinishStmt(GoASTStmt *s) {
127     if (!Semicolon())
128       m_failed = true;
129     return s;
130   }
131
132   llvm::StringRef CopyString(llvm::StringRef s);
133
134   GoLexer m_lexer;
135   std::vector<GoLexer::Token> m_tokens;
136   size_t m_pos;
137   llvm::StringRef m_error;
138   llvm::StringRef m_last;
139   GoLexer::TokenType m_last_tok;
140   llvm::StringMap<uint8_t> m_strings;
141   bool m_failed;
142 };
143 }
144
145 #endif