1 /*
2  * The contents of this file are subject to the Mozilla Public License
3  * Version 1.0 (the "License"); you may not use this file except in
4  * compliance with the License. You may obtain a copy of the License at
5  * http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9  * License for the specific language governing rights and limitations
10  * under the License.
11  *
12  * The Initial Developer of this code is David Baum.
13  * Portions created by David Baum are Copyright (C) 1998 David Baum.
14  * All Rights Reserved.
15  *
16  * Portions created by John Hansen are Copyright (C) 2005 John Hansen.
17  * All Rights Reserved.
18  *
19  */
20 
21 #ifndef __PreProc_h
22 #define __PreProc_h
23 
24 #ifndef __Token_h
25 #include "Token.h"
26 #endif
27 
28 #ifndef __PListS_h
29 #include "PListS.h"
30 #endif
31 
32 #ifndef __CondParser_h
33 #include "CondParser.h"
34 #endif
35 
36 #ifndef __Conditional_h
37 #include "Conditional.h"
38 #endif
39 
40 #include <vector>
41 
42 using std::vector;
43 
44 class Symbol;
45 class Expansion;
46 
47 class PreProc
48 {
49 public:
50 			PreProc();
51 			~PreProc();
52 
53 	// get fully preprocessed token
54 	int		Get(TokenVal &v);
55 
56 	// get after substitution but before directive processing
57 	int		GetReplacedToken(TokenVal &v);
58 
59 	// get next queued token (either from macro or file)
60 	int		GetRawToken(TokenVal &v);
61 
62 private:
63 
64 	bool	DoDefine();
65 	bool	DoInclude();
66 	int		DoSimpleDefine(Symbol *s);
67 	int		DoMacroDefine(Symbol *s);
68 	bool	DoIfdef(bool b);
69 	bool	DoUndef();
70 	bool	DoPragma();
71 
72 	int		ReadDefineArgs();
73 	void	ReadDefineBody();
74 	int		MatchArg(const Symbol *s);
75 
76 	void	DiscardLine();
77 
78 	bool	BeginExpansion(Symbol *s);
79 	bool	ReadExpansionArgs(Expansion *e);
80 	bool	ReadExpansionArg(Expansion *e, int i, int delim);
81 
82 	bool	fNLRead;
83 
84 	PListS<Expansion>	fExpList;
85 	vector<Symbol*>		fArguments;
86 	vector<Token>		fTokenBuf;
87 	Conditional			fConditional;
88 	bool				fActive;
89 	CondParser			fParser;
90 	bool				fEndOfFiles;
91 };
92 
93 
94 extern PreProc *gPreProc;
95 
96 #endif
97