xref: /trunk/main/autodoc/source/parser/cpp/pe_defs.cxx (revision 78bc99aa)
1*78bc99aaSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*78bc99aaSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*78bc99aaSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*78bc99aaSAndrew Rist  * distributed with this work for additional information
6*78bc99aaSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*78bc99aaSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*78bc99aaSAndrew Rist  * "License"); you may not use this file except in compliance
9*78bc99aaSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*78bc99aaSAndrew Rist  *
11*78bc99aaSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*78bc99aaSAndrew Rist  *
13*78bc99aaSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*78bc99aaSAndrew Rist  * software distributed under the License is distributed on an
15*78bc99aaSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*78bc99aaSAndrew Rist  * KIND, either express or implied.  See the License for the
17*78bc99aaSAndrew Rist  * specific language governing permissions and limitations
18*78bc99aaSAndrew Rist  * under the License.
19*78bc99aaSAndrew Rist  *
20*78bc99aaSAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir #include <precomp.h>
23cdf0e10cSrcweir #include "pe_defs.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir 
26cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES
27cdf0e10cSrcweir #include <cosv/tpl/tpltools.hxx>
28cdf0e10cSrcweir #include <ary/cpp/c_gate.hxx>
29cdf0e10cSrcweir #include <ary/cpp/c_define.hxx>
30cdf0e10cSrcweir #include <ary/cpp/c_macro.hxx>
31cdf0e10cSrcweir #include <ary/cpp/cp_def.hxx>
32cdf0e10cSrcweir #include "all_toks.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace cpp
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
PE_Defines(Cpp_PE * i_pParent)39cdf0e10cSrcweir PE_Defines::PE_Defines( Cpp_PE * i_pParent )
40cdf0e10cSrcweir 	:   Cpp_PE(i_pParent),
41cdf0e10cSrcweir 		pStati( new PeStatusArray<PE_Defines> ),
42cdf0e10cSrcweir 	    // sName,
43cdf0e10cSrcweir         // aParameters,
44cdf0e10cSrcweir         // sDefinition,
45cdf0e10cSrcweir         bIsMacro(false)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	Setup_StatusFunctions();
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
~PE_Defines()51cdf0e10cSrcweir PE_Defines::~PE_Defines()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir void
Call_Handler(const cpp::Token & i_rTok)56cdf0e10cSrcweir PE_Defines::Call_Handler( const cpp::Token & i_rTok )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 	pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir void
Setup_StatusFunctions()62cdf0e10cSrcweir PE_Defines::Setup_StatusFunctions()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	typedef CallFunction<PE_Defines>::F_Tok	F_Tok;
65cdf0e10cSrcweir 	static F_Tok stateF_expectName[] = 		{ &PE_Defines::On_expectName_DefineName,
66cdf0e10cSrcweir                                               &PE_Defines::On_expectName_MacroName
67cdf0e10cSrcweir                                             };
68cdf0e10cSrcweir 	static INT16 stateT_expectName[] = 		{ Tid_DefineName,
69cdf0e10cSrcweir                                               Tid_MacroName
70cdf0e10cSrcweir                                             };
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	static F_Tok stateF_gotDefineName[] =   { &PE_Defines::On_gotDefineName_PreProDefinition };
73cdf0e10cSrcweir 	static INT16 stateT_gotDefineName[] =  	{ Tid_PreProDefinition };
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	static F_Tok stateF_expectMacroParameters[] =
76cdf0e10cSrcweir                                             { &PE_Defines::On_expectMacroParameters_MacroParameter,
77cdf0e10cSrcweir                                               &PE_Defines::On_expectMacroParameters_PreProDefinition
78cdf0e10cSrcweir                                             };
79cdf0e10cSrcweir 	static INT16 stateT_expectMacroParameters[] =
80cdf0e10cSrcweir                                            	{ Tid_MacroParameter,
81cdf0e10cSrcweir                                               Tid_PreProDefinition
82cdf0e10cSrcweir                                             };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	SEMPARSE_CREATE_STATUS(PE_Defines, expectName, Hdl_SyntaxError);
85cdf0e10cSrcweir 	SEMPARSE_CREATE_STATUS(PE_Defines, gotDefineName, Hdl_SyntaxError);
86cdf0e10cSrcweir 	SEMPARSE_CREATE_STATUS(PE_Defines, expectMacroParameters, Hdl_SyntaxError);
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir void
InitData()90cdf0e10cSrcweir PE_Defines::InitData()
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	pStati->SetCur(expectName);
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	sName.clear();
95cdf0e10cSrcweir     csv::erase_container( aParameters );
96cdf0e10cSrcweir     csv::erase_container( aDefinition );
97cdf0e10cSrcweir     bIsMacro = false;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir void
TransferData()101cdf0e10cSrcweir PE_Defines::TransferData()
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     if (NOT bIsMacro)
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         if (aDefinition.empty() OR aDefinition.front().empty())
106cdf0e10cSrcweir             return;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     	ary::cpp::Define &
109cdf0e10cSrcweir             rNew = Env().AryGate().Defs().Store_Define(
110cdf0e10cSrcweir                             Env().Context(), sName, aDefinition );
111cdf0e10cSrcweir         Env().Event_Store_CppDefinition(rNew);
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir     else
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         ary::cpp::Macro &
116cdf0e10cSrcweir             rNew = Env().AryGate().Defs().Store_Macro(
117cdf0e10cSrcweir                             Env().Context(), sName, aParameters, aDefinition );
118cdf0e10cSrcweir         Env().Event_Store_CppDefinition(rNew);
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 	pStati->SetCur(size_of_states);
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir void
Hdl_SyntaxError(const char * i_sText)124cdf0e10cSrcweir PE_Defines::Hdl_SyntaxError( const char * i_sText)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	StdHandlingOfSyntaxError(i_sText);
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir void
On_expectName_DefineName(const char * i_sText)130cdf0e10cSrcweir PE_Defines::On_expectName_DefineName( const char * i_sText )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	SetTokenResult(done, stay);
133cdf0e10cSrcweir 	pStati->SetCur(gotDefineName);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	sName = i_sText;
136cdf0e10cSrcweir 	bIsMacro = false;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir void
On_expectName_MacroName(const char * i_sText)140cdf0e10cSrcweir PE_Defines::On_expectName_MacroName( const char * i_sText )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	SetTokenResult(done, stay);
143cdf0e10cSrcweir 	pStati->SetCur(expectMacroParameters);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	sName = i_sText;
146cdf0e10cSrcweir 	bIsMacro = true;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir void
On_gotDefineName_PreProDefinition(const char * i_sText)150cdf0e10cSrcweir PE_Defines::On_gotDefineName_PreProDefinition( const char * i_sText )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	SetTokenResult(done, pop_success);
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     aDefinition.push_back( String (i_sText) );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir void
On_expectMacroParameters_MacroParameter(const char * i_sText)158cdf0e10cSrcweir PE_Defines::On_expectMacroParameters_MacroParameter( const char * i_sText )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	SetTokenResult(done, stay);
161cdf0e10cSrcweir     aParameters.push_back( String (i_sText) );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir void
On_expectMacroParameters_PreProDefinition(const char * i_sText)165cdf0e10cSrcweir PE_Defines::On_expectMacroParameters_PreProDefinition( const char * i_sText )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir 	SetTokenResult(done, pop_success);
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     aDefinition.push_back( String (i_sText) );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 
173cdf0e10cSrcweir }   // namespace cpp
174cdf0e10cSrcweir 
175