CppParser
Loading...
Searching...
No Matches
parser.l.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 "cpptoken.h"
27#include "cppvarinit.h"
28#include "parser.tab.h"
29
30#include <functional>
31#include <map>
32#include <set>
33#include <vector>
34
35/*
36Parsing of #define is complex. So we will try to parse simple #defines to know what it trys to define.
37For any thing complex we will treat the entire definition as one BLOB.
38*/
40{
41 kNoDef = 0,
42 kNumDef = tknNumber, // #define is used to define a numeric constant.
43 kStrLitDef = tknStrLit, // #define is used to define a string literal.
44 kCharLitDef = tknCharLit, // #define is used to define a character literal.
45 kReDef = tknName, // #define is used to rename something, e.g. #define CALLTYPE __stdcall
46 kComplexDef = tknPreProDef, // It is something beyond our parser can comprehand.
47};
48
50{
51 None,
55};
56
58{
59 kNoInfo,
62};
63
65{
66 kNoInfo,
69};
70
72{
73 MacroDependentCodeEnablement macroDependentCodeEnablement = MacroDependentCodeEnablement::kNoInfo;
79};
80
81using CodeEnablementInfoStack = std::vector<CodeEnablementInfo>;
82using BracketDepthStack = std::vector<int>;
83
85{
86 int mLexLog = 0;
87 int mLineNo = 1;
88
89 const char* mInputBuffer = nullptr;
90 size_t mInputBufferSize = 0;
91
92 const char* mOldYytext = nullptr;
93
97
99 const char* mNotAMemInitColon = nullptr;
102 const char* mExpectedBracePosition = nullptr;
103 const char* mExpectedColonPosition = nullptr;
106
107 const char* mExpectedRShiftOperator = nullptr;
108
117 bool mTokenizeComment = true;
118
131
136
137 DefineLooksLike mDefLooksLike = DefineLooksLike::kNoDef;
138
141
144};
MacroDependentCodeEnablement
Definition: parser.l.h:65
MacroDefineInfo
Definition: parser.l.h:58
std::vector< int > BracketDepthStack
Definition: parser.l.h:82
std::vector< CodeEnablementInfo > CodeEnablementInfoStack
Definition: parser.l.h:81
TokenSetupFlag
Definition: parser.l.h:50
@ DisableCommentTokenization
DefineLooksLike
Definition: parser.l.h:40
@ kNumDef
Definition: parser.l.h:42
@ kNoDef
Definition: parser.l.h:41
@ kStrLitDef
Definition: parser.l.h:43
@ kCharLitDef
Definition: parser.l.h:44
@ kComplexDef
Definition: parser.l.h:46
@ kReDef
Definition: parser.l.h:45
MacroDependentCodeEnablement macroDependentCodeEnablement
Definition: parser.l.h:73
int numHashIfInMacroDependentCode
Counting of # to keep track of when we need to consider the code outside of disabled segment.
Definition: parser.l.h:78
bool codeSegmentDependsOnMacroDefinition
Definition: parser.l.h:143
BracketDepthStack mBracketDepthStack
Definition: parser.l.h:130
const char * mNotAMemInitColon
Definition: parser.l.h:99
int mLexLog
Definition: parser.l.h:86
int mNestedCurlyBracketDepth
It is currently used for parsing function body as a blob.
Definition: parser.l.h:135
const char * mInputBuffer
Definition: parser.l.h:89
const char * mExpectedBracePosition
Definition: parser.l.h:102
CodeEnablementInfo currentCodeEnablementInfo
Definition: parser.l.h:140
size_t mInputBufferSize
Definition: parser.l.h:90
const char * mPossibleFuncImplStartBracePosition
Definition: parser.l.h:104
bool mFunctionBodyWillBeEncountered
Definition: parser.l.h:100
const char * mExpectedRShiftOperator
Definition: parser.l.h:107
bool mEnumBodyWillBeEncountered
Definition: parser.l.h:95
bool mMemInitListWillBeEncountered
Definition: parser.l.h:101
const char * mOldYytext
Definition: parser.l.h:92
const char * mExpectedColonPosition
Definition: parser.l.h:103
int mLineNo
Definition: parser.l.h:87
bool mTokenizeComment
Comments can appear anywhere in a C/C++ program and unfortunately not all coments can be preserved.
Definition: parser.l.h:117
CodeEnablementInfoStack codeEnablementInfoStack
Definition: parser.l.h:139
bool parseDisabledCodeAsBlob
Definition: parser.l.h:142
DefineLooksLike mDefLooksLike
Definition: parser.l.h:137