1
// This file is part of PUMA.
2
// Copyright (C) 1999-2003 The PUMA developer team.
4
// This program is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU General Public License as
6
// published by the Free Software Foundation; either version 2 of
7
// the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public
15
// License along with this program; if not, write to the Free
16
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19
#ifndef __preprocessor_parser__
20
#define __preprocessor_parser__
22
// Preprocessor parser class. !!! The preprocessor parser has to
23
// be added last to the composite parser of a translation unit !!!
25
#include "Puma/Stack.h"
26
#include "Puma/Config.h"
27
#include "Puma/CScanner.h"
28
#include "Puma/CUnit.h"
29
#include "Puma/TokenSource.h"
30
#include "Puma/PreMacroExpander.h"
44
class PreMacroManager;
45
class PreFileIncluder;
46
class PrePredicateManager;
48
class PreprocessorParser : public PumaTokenSource {
50
// The current mode for token preprocessing
62
// Do not print the result of the parse process.
65
// If the preprocessor parser is the last in chain,
66
// the result of the parse process will be putted on
70
// Stack for the macro expansion.
71
Array<PreMacro*> *_macroStack;
72
set<Token*> *_prescanned;
74
PreLevelState *_levelState;
75
PreParserState *_parserState;
76
PreMacroManager *_macroManager;
77
PreFileIncluder *_fileIncluder;
78
PrePredicateManager *_predicateManager;
79
UnitManager *_unitManager;
82
PreMacroExpander _expander;
83
PreMacroExpander _macroExpander;
91
const char *_importHandler;
94
// Parse a single token.
97
// Free the preprocessor syntax tree.
98
void freeSyntaxTree (PreTree*);
101
// Get several preprocessor informations.
102
Array<PreMacro*> *macroStack () const { return _macroStack; }
103
set<Token*> *prescanned () const { return _prescanned; }
104
PreLevelState *levelState () const { return _levelState; }
105
PreParserState *parserState () const { return _parserState; }
106
PreMacroManager *macroManager () const { return _macroManager; }
107
PreFileIncluder *fileIncluder () const { return _fileIncluder; }
108
PrePredicateManager *predicateManager () const { return _predicateManager; }
109
UnitManager *unitManager () const { return _unitManager; }
110
UnitManager *locals () const { return _locals; }
111
PreMode pre_mode () const { return _pre_mode; }
112
bool supportGNU () const { return _support_gnu; }
113
CScanner &cscanner () const { return (CScanner&) _scanner; }
115
// Return the preprocessor syntax tree.
116
PreTree *syntaxTree () const;
119
PreprocessorParser (ErrorStream *, UnitManager *, UnitManager *,
120
ostream &out = cout, int max_depth = 400);
122
~PreprocessorParser ();
124
// Reset the preprocessor parser.
125
void reset (ErrorStream *, UnitManager *, UnitManager *,
126
ostream &out = cout, int max_depth = 400);
128
// Free the preprocessor syntax tree.
129
void freeSyntaxTree ();
131
// Configure the preprocessor.
132
void configure (const Config &, bool = true);
134
// Get the next token to parse.
137
TokenStream *scanner () const { return _stream; }
138
void stream (TokenStream *s) { _stream = s; }
140
// Map scanner token types to parser token types
141
int map_token (Token *token, bool &parse);
143
// Invoke the parse process.
146
// Switch to silent mode.
147
void silentMode (bool mode = true) { _silentMode = mode; }
149
// Define a new macro.
150
void defMacro (const char *, const char * = (const char*)0, char = 0) const;
153
void undefMacro (const char *) const;
155
// Define a new predicate.
156
void defPredicate (const char *, const char *) const;
158
// Undefine a predicate.
159
void undefPredicate (const char *) const;
161
// Add a new include path.
162
void addInclPath (const char *) const;
164
void supportGNU (bool);
170
#endif /* __preprocessor_parser__ */