forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.h
More file actions
executable file
·129 lines (107 loc) · 4.2 KB
/
Parser.h
File metadata and controls
executable file
·129 lines (107 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// Parser.h
//
// $Id: //poco/1.4/CppParser/include/Poco/CppParser/Parser.h#1 $
//
// Library: CppParser
// Package: CppParser
// Module: Parser
//
// Definition of the Parser class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Parser_INCLUDED
#define CppParser_Parser_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Tokenizer.h"
#include "Poco/CppParser/Symbol.h"
#include "Poco/CppParser/NameSpace.h"
#include "Poco/CountingStream.h"
#include <vector>
namespace Poco {
namespace CppParser {
class Enum;
class Struct;
class Function;
class CppParser_API Parser
/// A minimal parser for C++ (header files).
///
/// The parser reads a (preprocessed) source or header file and
/// builds a symbol table containing as much information as
/// the parser is able to extract from the file.
///
/// A special comment syntax is used for inline API documentation.
///
/// A comment starting with three consecutive slashes (///) contains
/// API documentation for a symbol (class, function, typedef, enum, etc.).
/// API documentation comments always come after the declaration, with the
/// exception of structs and classes, where the comments are expected
/// immediately before the opening brace.
{
public:
Parser(NameSpace::SymbolTable& gst, const std::string& file, std::istream& istr);
/// Creates the Parser.
~Parser();
/// Destroys the Parser.
void parse();
/// Parses the file.
protected:
const Poco::Token* parseFile(const Poco::Token* pNext);
const Poco::Token* parseNameSpace(const Poco::Token* pNext);
const Poco::Token* parseClass(const Poco::Token* pNext);
const Poco::Token* parseClass(const Poco::Token* pNext, std::string& decl);
const Poco::Token* parseTemplate(const Poco::Token* pNext);
const Poco::Token* parseTemplateArgs(const Poco::Token* pNext, std::string& decl);
const Poco::Token* parseVarFunc(const Poco::Token* pNext);
const Poco::Token* parseVarFunc(const Poco::Token* pNext, std::string& decl);
const Poco::Token* parseFriend(const Poco::Token* pNext);
const Poco::Token* parseExtern(const Poco::Token* pNext);
const Poco::Token* parseTypeDef(const Poco::Token* pNext);
const Poco::Token* parseUsing(const Poco::Token* pNext);
const Poco::Token* parseFunc(const Poco::Token* pNext, std::string& decl);
const Poco::Token* parseParameters(const Poco::Token* pNext, Function* pFunc);
const Poco::Token* parseBlock(const Poco::Token* pNext);
const Poco::Token* parseEnum(const Poco::Token* pNext);
const Poco::Token* parseEnumValue(const Poco::Token* pNext, Enum* pEnum);
const Poco::Token* parseBaseClassList(const Poco::Token* pNext, Struct* pClass);
const Poco::Token* parseClassMembers(const Poco::Token* pNext, Struct* pClass);
const Poco::Token* parseAccess(const Poco::Token* pNext);
const Poco::Token* parseIdentifier(const Poco::Token* pNext, std::string& id);
void addSymbol(Symbol* pSymbol, int lineNumber, bool addGST = true);
void pushNameSpace(NameSpace* pNameSpace, int lineNumber, bool addGST = true);
void popNameSpace();
NameSpace* currentNameSpace() const;
static bool isIdentifier(const Poco::Token* pToken);
static bool isOperator(const Poco::Token* pToken, int kind);
static bool isKeyword(const Poco::Token* pToken, int kind);
static bool isEOF(const Poco::Token* pToken);
static void expectOperator(const Poco::Token* pToken, int kind, const std::string& msg);
static void syntaxError(const std::string& msg);
static void append(std::string& decl, const std::string& token);
static void append(std::string& decl, const Poco::Token* pToken);
const Poco::Token* next();
const Poco::Token* nextPreprocessed();
const Poco::Token* nextToken();
private:
typedef std::vector<NameSpace*> NSStack;
NameSpace::SymbolTable& _gst;
Poco::CountingInputStream _istr;
Tokenizer _tokenizer;
std::string _file;
std::string _path;
std::string _currentPath;
bool _inFile;
std::string _package;
std::string _library;
NSStack _nsStack;
Symbol* _pCurrentSymbol;
Symbol::Access _access;
std::string _doc;
std::string _attrs;
};
} } // namespace Poco::CppParser
#endif // CppParser_Parser_INCLUDED