~ubuntu-branches/ubuntu/natty/aspectc++/natty

« back to all changes in this revision

Viewing changes to Puma/gen-release/step1/inc/Puma/PreprocessorParser.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2005-12-23 10:49:40 UTC
  • Revision ID: james.westby@ubuntu.com-20051223104940-ig4klhoi991zs7km
Tags: upstream-0.99+1.0pre2
ImportĀ upstreamĀ versionĀ 0.99+1.0pre2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of PUMA.
 
2
// Copyright (C) 1999-2003  The PUMA developer team.
 
3
//                                                                
 
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.            
 
8
//                                                                
 
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.                   
 
13
//                                                                
 
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, 
 
17
// MA  02111-1307  USA                                            
 
18
 
 
19
#ifndef __preprocessor_parser__
 
20
#define __preprocessor_parser__
 
21
 
 
22
// Preprocessor parser class. !!! The preprocessor parser has to 
 
23
// be added last to the composite parser of a translation unit !!!
 
24
 
 
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"
 
31
#include <iostream>
 
32
#include <set>
 
33
using namespace std;
 
34
 
 
35
namespace Puma {
 
36
 
 
37
 
 
38
class PreTree;
 
39
class ErrorStream;
 
40
class UnitManager;
 
41
class PrePredicate;
 
42
class PreLevelState;
 
43
class PreParserState;
 
44
class PreMacroManager;
 
45
class PreFileIncluder;
 
46
class PrePredicateManager;
 
47
 
 
48
class PreprocessorParser : public PumaTokenSource {
 
49
public:
 
50
  // The current mode for token preprocessing
 
51
  typedef enum { 
 
52
    INITIAL, 
 
53
    DEFINING, 
 
54
    MAYBEMACRO, 
 
55
    ASSERT,
 
56
    TOKENLIST, 
 
57
    DIRECTIVE, 
 
58
    MACRO 
 
59
  } PreMode;
 
60
 
 
61
private:
 
62
  // Do not print the result of the parse process.
 
63
  bool _silentMode;
 
64
 
 
65
  // If the preprocessor parser is the last in chain,
 
66
  // the result of the parse process will be putted on 
 
67
  // the given stream.
 
68
  ostream *_out;
 
69
 
 
70
  // Stack for the macro expansion.
 
71
  Array<PreMacro*>    *_macroStack;
 
72
  set<Token*>         *_prescanned;
 
73
 
 
74
  PreLevelState       *_levelState;
 
75
  PreParserState      *_parserState;
 
76
  PreMacroManager     *_macroManager;
 
77
  PreFileIncluder     *_fileIncluder;
 
78
  PrePredicateManager *_predicateManager;
 
79
  UnitManager         *_unitManager;
 
80
  UnitManager         *_locals;
 
81
 
 
82
  PreMacroExpander     _expander;
 
83
  PreMacroExpander     _macroExpander;        
 
84
        
 
85
  PreMode              _pre_mode;
 
86
  bool                       _support_gnu;
 
87
 
 
88
  CScanner             _scanner;
 
89
  TokenStream         *_stream;
 
90
                
 
91
  const char          *_importHandler;
 
92
 
 
93
private:
 
94
  // Parse a single token.
 
95
  Token* parseToken ();
 
96
 
 
97
  // Free the preprocessor syntax tree.
 
98
  void freeSyntaxTree (PreTree*);
 
99
 
 
100
public:
 
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; }
 
114
 
 
115
  // Return the preprocessor syntax tree.
 
116
  PreTree *syntaxTree () const;
 
117
 
 
118
public:
 
119
  PreprocessorParser (ErrorStream *, UnitManager *, UnitManager *, 
 
120
                        ostream &out = cout, int max_depth = 400);
 
121
                           
 
122
  ~PreprocessorParser ();
 
123
        
 
124
  // Reset the preprocessor parser.
 
125
  void reset (ErrorStream *, UnitManager *, UnitManager *, 
 
126
              ostream &out = cout, int max_depth = 400);
 
127
 
 
128
  // Free the preprocessor syntax tree.
 
129
  void freeSyntaxTree ();
 
130
        
 
131
  // Configure the preprocessor.
 
132
  void configure (const Config &, bool = true);
 
133
        
 
134
  // Get the next token to parse.
 
135
  Token *next ();
 
136
        
 
137
  TokenStream *scanner () const { return _stream; }
 
138
  void stream (TokenStream *s) { _stream = s; }
 
139
 
 
140
  // Map scanner token types to parser token types
 
141
  int map_token (Token *token, bool &parse);
 
142
 
 
143
  // Invoke the parse process.
 
144
  void parse ();
 
145
        
 
146
  // Switch to silent mode.
 
147
  void silentMode (bool mode = true) { _silentMode = mode; }
 
148
 
 
149
  // Define a new macro.
 
150
  void defMacro (const char *, const char * = (const char*)0, char = 0) const;
 
151
        
 
152
  // Undefine a macro.
 
153
  void undefMacro (const char *) const;
 
154
        
 
155
  // Define a new predicate.
 
156
  void defPredicate (const char *, const char *) const;
 
157
        
 
158
  // Undefine a predicate.
 
159
  void undefPredicate (const char *) const;
 
160
        
 
161
  // Add a new include path.
 
162
  void addInclPath (const char *) const;
 
163
 
 
164
  void supportGNU (bool);
 
165
};
 
166
 
 
167
 
 
168
} // namespace Puma
 
169
 
 
170
#endif /* __preprocessor_parser__ */