1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef ADC_CPP_PREPROC_HXX
29 #define ADC_CPP_PREPROC_HXX
30 
31 
32 
33 // USED SERVICES
34 	// BASE CLASSES
35 	// COMPONENTS
36 #include <deque>
37 	// PARAMETERS
38 
39 class CharacterSource;
40 
41 
42 namespace cpp
43 {
44 
45 class Token;
46 class CodeExplorer;
47 class DefineDescription;
48 
49 
50 class PreProcessor
51 {
52   public:
53     typedef std::map< String, DefineDescription* > MacroMap;
54 
55     // LIFECYCLE
56 						PreProcessor();
57 						~PreProcessor();
58     // OPERATONS
59     void                AssignPartners(
60                             CodeExplorer &      o_rCodeExplorer,
61                             CharacterSource &   o_rCharSource,
62                             const MacroMap &    i_rCurValidDefines );
63     void                Process_Token(
64                             cpp::Token &        let_drToken );
65     void                UnblockMacro(
66                             const char *        i_sMacroName );
67   private:
68     public: // Necessary for instantiation of static variable:
69     enum E_State
70     {
71         plain = 0,
72         expect_macro_bracket_left,
73         expect_macro_param,
74         state_MAX
75     };
76     typedef void (PreProcessor::*                   F_TOKENPROC )(cpp::Token &);
77     void                On_plain( cpp::Token & );
78     void                On_expect_macro_bracket_left( cpp::Token & );
79     void                On_expect_macro_param( cpp::Token & );
80 
81     private:  // Reprivate again:
82     typedef std::deque< DYN cpp::Token * >          TokenQueue;
83     typedef StringVector                  List_MacroParams;
84 
85 
86     bool                CheckForDefine(
87                             cpp::Token &        let_drToken );
88     void                InterpretMacro();
89 
90 	// DATA
91     static F_TOKENPROC  aTokProcs[state_MAX];
92         // Referenced extern objects
93     CodeExplorer *      pCppExplorer;
94     CharacterSource *   pSourceText;
95     const MacroMap *    pCurValidDefines;
96 
97         // internal data
98     TokenQueue          aTokens;
99 
100     E_State             eState;
101 
102     DefineDescription * pCurMacro;
103     DYN Token *         dpCurMacroName;
104     List_MacroParams    aCurMacroParams;
105     csv::StreamStr      aCurParamText;
106 
107     intt                nBracketInParameterCounter;
108     StringVector        aBlockedMacroNames;
109 };
110 
111 
112 
113 }   // end namespace cpp
114 
115 #endif
116 
117