retdec
borland_ast_parser.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_BORLAND_AST_PARSER_H
8 #define RETDEC_BORLAND_AST_PARSER_H
9 
10 #include <llvm/Demangle/StringView.h>
11 
14 
15 namespace retdec {
16 namespace demangler {
17 namespace borland {
18 
20 
21 class FunctionTypeNode;
22 class NodeArray;
23 enum class CallConv;
24 
29 {
30 public:
31  enum Status : uint8_t
32  {
33  success = 0,
38  };
39 
40 public:
41  explicit BorlandASTParser(Context &context);
42 
43  void parse(const std::string &mangled);
44 
45  std::shared_ptr<Node> ast();
46 
47  Status status();
48 
49 private:
50  char peek() const;
51  bool peek(char c) const;
52  bool peek(const StringView &s) const;
53  unsigned peekNumber() const;
54  bool statusOk() const;
55  bool checkResult(std::shared_ptr<Node> node);
56  bool consumeIfPossible(char c);
57  bool consumeIfPossible(const StringView &s);
58  bool consume(char c);
59  bool consume(const StringView &s);
60 
61  std::shared_ptr<Node> parseFunction();
62  std::shared_ptr<FunctionTypeNode> parseFuncType(Qualifiers &quals);
65  std::shared_ptr<NodeArray> parseFuncParams();
66  bool parseBackref(std::shared_ptr<NodeArray> &paramArray);
67  std::shared_ptr<TypeNode> parseType();
68  std::shared_ptr<TypeNode> parseBuildInType(const Qualifiers &quals);
69  unsigned parseNumber();
70  std::shared_ptr<TypeNode> parseNamedType(unsigned nameLen, const Qualifiers &quals);
71  std::shared_ptr<Node> parseFuncName();
72  std::shared_ptr<Node> parseFuncNameClasic();
73  std::shared_ptr<Node> parseFuncNameLlvm();
74  bool couldBeOperator();
75  std::shared_ptr<Node> parseOperator();
76  std::shared_ptr<Node> parseAsNameUntil(const char *end);
77  std::shared_ptr<Node> parseTemplate(std::shared_ptr<Node> templateNamespace);
78  std::shared_ptr<Node> parseTemplateName(std::shared_ptr<Node> templateNamespace);
79  std::shared_ptr<Node> parseTemplateParams();
80  std::shared_ptr<TypeNode> parsePointer(const Qualifiers &quals);
81  std::shared_ptr<TypeNode> parseReference();
82  std::shared_ptr<TypeNode> parseRReference();
83  std::shared_ptr<TypeNode> parseArray(const Qualifiers &quals);
84  std::shared_ptr<Node> parseIntExpresion(StringView &s);
85  unsigned parseNumber(StringView &s);
87  StringView &mangled,
88  std::shared_ptr<NodeArray> &params);
89 private:
92  std::shared_ptr<Node> _ast;
94 };
95 
96 } // borland
97 } // demangler
98 } // retdec
99 
100 #endif //RETDEC_BORLAND_AST_PARSER_H
Parses name mangled by borland mangling scheme into AST.
Definition: borland_ast_parser.h:29
StringView _mangled
Definition: borland_ast_parser.h:91
void parse(const std::string &mangled)
Main method of parser. Tries to create AST, sets status.
Definition: borland_ast_parser.cpp:180
char peek() const
Definition: borland_ast_parser.cpp:67
std::shared_ptr< Node > parseOperator()
Definition: borland_ast_parser.cpp:432
bool couldBeOperator()
Definition: borland_ast_parser.cpp:359
std::shared_ptr< Node > parseFuncName()
Definition: borland_ast_parser.cpp:239
BorlandASTParser(Context &context)
Constructor for AST parser. Immediately parses name mangled by borland mangling scheme into AST.
Definition: borland_ast_parser.cpp:42
std::shared_ptr< Node > parseTemplateName(std::shared_ptr< Node > templateNamespace)
Definition: borland_ast_parser.cpp:981
std::shared_ptr< Node > parseFuncNameClasic()
Definition: borland_ast_parser.cpp:261
Status _status
Definition: borland_ast_parser.h:90
std::shared_ptr< FunctionTypeNode > parseFuncType(Qualifiers &quals)
Definition: borland_ast_parser.cpp:601
std::shared_ptr< Node > parseAsNameUntil(const char *end)
Definition: borland_ast_parser.cpp:554
std::shared_ptr< Node > parseTemplateParams()
Definition: borland_ast_parser.cpp:1019
std::shared_ptr< TypeNode > parseType()
Definition: borland_ast_parser.cpp:724
unsigned peekNumber() const
Definition: borland_ast_parser.cpp:91
std::shared_ptr< TypeNode > parsePointer(const Qualifiers &quals)
Definition: borland_ast_parser.cpp:776
std::shared_ptr< TypeNode > parseRReference()
Definition: borland_ast_parser.cpp:815
Context & _context
Definition: borland_ast_parser.h:93
std::shared_ptr< Node > _ast
Definition: borland_ast_parser.h:92
bool parseBackref(std::shared_ptr< NodeArray > &paramArray)
Definition: borland_ast_parser.cpp:694
std::shared_ptr< TypeNode > parseReference()
Definition: borland_ast_parser.cpp:790
std::shared_ptr< Node > parseTemplate(std::shared_ptr< Node > templateNamespace)
Definition: borland_ast_parser.cpp:1149
std::shared_ptr< TypeNode > parseBuildInType(const Qualifiers &quals)
Definition: borland_ast_parser.cpp:863
bool consumeIfPossible(char c)
Definition: borland_ast_parser.cpp:134
Status status()
Definition: borland_ast_parser.cpp:59
std::shared_ptr< TypeNode > parseNamedType(unsigned nameLen, const Qualifiers &quals)
Definition: borland_ast_parser.cpp:950
bool consume(char c)
Definition: borland_ast_parser.cpp:151
std::shared_ptr< Node > ast()
Definition: borland_ast_parser.cpp:51
std::shared_ptr< NodeArray > parseFuncParams()
Definition: borland_ast_parser.cpp:666
std::shared_ptr< TypeNode > parseArray(const Qualifiers &quals)
Definition: borland_ast_parser.cpp:838
std::shared_ptr< Node > parseFunction()
Definition: borland_ast_parser.cpp:202
Qualifiers parseQualifiers()
Definition: borland_ast_parser.cpp:633
std::shared_ptr< Node > parseIntExpresion(StringView &s)
Definition: borland_ast_parser.cpp:1108
unsigned parseNumber()
Definition: borland_ast_parser.cpp:927
CallConv parseCallConv()
Definition: borland_ast_parser.cpp:646
bool checkResult(std::shared_ptr< Node > node)
Definition: borland_ast_parser.cpp:121
Status
Definition: borland_ast_parser.h:32
@ unknown_error
Definition: borland_ast_parser.h:37
@ in_progress
Definition: borland_ast_parser.h:35
@ invalid_mangled_name
Definition: borland_ast_parser.h:36
@ init
Definition: borland_ast_parser.h:34
@ success
Definition: borland_ast_parser.h:33
bool parseTemplateBackref(StringView &mangled, std::shared_ptr< NodeArray > &params)
Definition: borland_ast_parser.cpp:1082
bool statusOk() const
Definition: borland_ast_parser.cpp:110
std::shared_ptr< Node > parseFuncNameLlvm()
Definition: borland_ast_parser.cpp:329
Storage for functions, types and names. Used for cacheing.
Definition: context.h:38
Representation of function types. Used for information about functions without name.
Definition: function_type.h:32
Node for representation of arrays of nodes.
Definition: node_array.h:20
Definition: qualifiers.h:20
Storage for all created nodes in borland AST.
llvm::itanium_demangle::StringView StringView
Definition: borland_ast_parser.h:19
CallConv
Definition: function_type.h:19
Definition: archive_wrapper.h:19
Base class for all nodes in borland AST.