-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathcppparser.h
More file actions
63 lines (47 loc) · 1.98 KB
/
Copy pathcppparser.h
File metadata and controls
63 lines (47 loc) · 1.98 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
// Copyright (C) 2022 Satya Das and CppParser contributors
// SPDX-License-Identifier: MIT
#ifndef A06AFF15_7A57_4160_9AB3_EE13CF751B6F
#define A06AFF15_7A57_4160_9AB3_EE13CF751B6F
#include <cppast/cppast.h>
#include <functional>
#include <memory>
namespace cppparser {
/**
* @brief Parses C++ source and generates an AST.
*
* @warning Although its a class it is not reentrant because underlying btyacc is not reentrant.
* So, any change done through this class is global and affects the result of other instances too.
*/
class CppParser
{
public:
using ErrorHandler =
std::function<void(const char* errLineText, size_t lineNum, size_t errorStartPos, int lexerContext)>;
public:
void addKnownMacro(std::string knownMacro);
void addKnownMacros(const std::vector<std::string>& knownMacros);
void addDefinedName(std::string definedName, int value = 0);
void addUndefinedName(std::string undefinedName);
void addUndefinedNames(const std::vector<std::string>& undefinedNames);
void addIgnorableMacro(std::string ignorableMacro);
void addIgnorableMacros(const std::vector<std::string>& ignorableMacros);
void addKnownApiDecor(std::string knownApiDecor);
void addKnownApiDecors(const std::vector<std::string>& knownApiDecor);
bool addRenamedKeyword(const std::string& keyword, std::string renamedKeyword);
void parseEnumBodyAsBlob();
void parseFunctionBodyAsBlob(bool asBlob);
public:
std::unique_ptr<cppast::CppCompound> parseFile(const std::string& filename);
/**
* @brief Parses the given stream and returns the AST.
* @param stm The stream to parse.
* @param stmSize The size of the stream.
* @return The AST.
* @warning The stream \a stm must terminate with double null characters, i.e. the last 2 bytes must be '\0'.
*/
std::unique_ptr<cppast::CppCompound> parseStream(char* stm, size_t stmSize);
void setErrorHandler(ErrorHandler errorHandler);
void resetErrorHandler();
};
} // namespace cppparser
#endif /* A06AFF15_7A57_4160_9AB3_EE13CF751B6F */