CppParser
Loading...
Searching...
No Matches
cppparser.h
Go to the documentation of this file.
1/*
2 The MIT License (MIT)
3
4 Copyright (c) 2018 Satya Das
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of
7 this software and associated documentation files (the "Software"), to deal in
8 the Software without restriction, including without limitation the rights to
9 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 the Software, and to permit persons to whom the Software is furnished to do so,
11 subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#pragma once
25
26#include "cppobjfactory.h"
27
28#include <functional>
29#include <utility>
30
32
40{
41public:
43 std::function<void(const char* errLineText, size_t lineNum, size_t errorStartPos, int lexerContext)>;
44
45public:
46 CppParser(CppObjFactoryPtr objFactory = nullptr);
48 : objFactory_(std::move(rhs.objFactory_))
49 {
50 }
51
52public:
53 void addKnownMacro(std::string knownMacro);
54 void addKnownMacros(const std::vector<std::string>& knownMacros);
55
56 void addDefinedName(std::string definedName, int value = 0);
57
58 void addUndefinedName(std::string undefinedName);
59 void addUndefinedNames(const std::vector<std::string>& undefinedNames);
60
61 void addIgnorableMacro(std::string ignorableMacro);
62 void addIgnorableMacros(const std::vector<std::string>& ignorableMacros);
63
64 void addKnownApiDecor(std::string knownApiDecor);
65 void addKnownApiDecors(const std::vector<std::string>& knownApiDecor);
66
67 bool addRenamedKeyword(const std::string& keyword, std::string renamedKeyword);
68
70 void parseFunctionBodyAsBlob(bool asBlob);
71
72public:
73 CppCompoundPtr parseFile(const std::string& filename);
74 CppCompoundPtr parseString(const std::string& filePathToSave, const std::string& content);
75 CppCompoundPtr parseString(const std::string& content);
76 CppCompoundPtr parseStream(char* stm, size_t stmSize);
77
78 void setErrorHandler(ErrorHandler errorHandler);
79 void resetErrorHandler();
80
81private:
83};
Parses C++ source and generates an AST.
Definition: cppparser.h:40
CppParser(CppParser &&rhs)
Definition: cppparser.h:47
void addKnownMacros(const std::vector< std::string > &knownMacros)
Definition: cppparser.cpp:66
void parseEnumBodyAsBlob()
Definition: cppparser.cpp:121
void addKnownApiDecor(std::string knownApiDecor)
Definition: cppparser.cpp:99
void addIgnorableMacros(const std::vector< std::string > &ignorableMacros)
Definition: cppparser.cpp:93
void parseFunctionBodyAsBlob(bool asBlob)
Definition: cppparser.cpp:126
void addUndefinedNames(const std::vector< std::string > &undefinedNames)
Definition: cppparser.cpp:82
CppObjFactoryPtr objFactory_
Definition: cppparser.h:82
CppCompoundPtr parseStream(char *stm, size_t stmSize)
Definition: cppparser.cpp:154
void addIgnorableMacro(std::string ignorableMacro)
Definition: cppparser.cpp:88
void resetErrorHandler()
Definition: cppparser.cpp:167
void addDefinedName(std::string definedName, int value=0)
Definition: cppparser.cpp:72
std::function< void(const char *errLineText, size_t lineNum, size_t errorStartPos, int lexerContext)> ErrorHandler
Definition: cppparser.h:43
void addKnownApiDecors(const std::vector< std::string > &knownApiDecor)
Definition: cppparser.cpp:104
CppCompoundPtr parseString(const std::string &filePathToSave, const std::string &content)
Definition: cppparser.cpp:141
void addKnownMacro(std::string knownMacro)
Definition: cppparser.cpp:61
void setErrorHandler(ErrorHandler errorHandler)
Definition: cppparser.cpp:162
CppCompoundPtr parseFile(const std::string &filename)
Definition: cppparser.cpp:131
void addUndefinedName(std::string undefinedName)
Definition: cppparser.cpp:77
bool addRenamedKeyword(const std::string &keyword, std::string renamedKeyword)
Definition: cppparser.cpp:110
std::unique_ptr< CppCompound > CppCompoundPtr
Definition: cppast.h:416
std::unique_ptr< CppObjFactory > CppObjFactoryPtr
Definition: cppobjfactory.h:59
std::function< void(const char *errLineText, size_t lineNum, size_t errorStartPos, int lexerContext)> ErrorHandler
Definition: parser.h:35