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