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_vari.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <cosv/tpl/tpltools.hxx>
28 #include "pe_expr.hxx"
29 
30 
31 
32 
33 namespace cpp {
34 
35 
PE_Variable(Cpp_PE * i_pParent)36 PE_Variable::PE_Variable( Cpp_PE * i_pParent )
37 	:   Cpp_PE(i_pParent),
38 		pStati( new PeStatusArray<PE_Variable> )
39 		// pSpExpression,
40         // pSpuArraySizeExpression,
41 		// pSpuInitExpression,
42         // sResultSizeExpression,
43         // sResultInitExpression
44 {
45 	Setup_StatusFunctions();
46 
47 	pSpExpression       = new SP_Expression(*this);
48 
49 	pSpuArraySizeExpression  = new SPU_Expression(*pSpExpression, 0, &PE_Variable::SpReturn_ArraySizeExpression);
50 	pSpuInitExpression  = new SPU_Expression(*pSpExpression, 0, &PE_Variable::SpReturn_InitExpression);
51 }
52 
~PE_Variable()53 PE_Variable::~PE_Variable()
54 {
55 }
56 
57 void
Call_Handler(const cpp::Token & i_rTok)58 PE_Variable::Call_Handler( const cpp::Token &	i_rTok )
59 {
60 	pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
61 }
62 
63 void
Setup_StatusFunctions()64 PE_Variable::Setup_StatusFunctions()
65 {
66 	typedef CallFunction<PE_Variable>::F_Tok	F_Tok;
67 
68 	static F_Tok stateF_afterName[] =		{ &PE_Variable::On_afterName_ArrayBracket_Left,
69 											  &PE_Variable::On_afterName_Semicolon,
70 											  &PE_Variable::On_afterName_Comma,
71 											  &PE_Variable::On_afterName_Assign };
72 	static INT16 stateT_afterName[] =     	{ Tid_ArrayBracket_Left,
73 											  Tid_Semicolon,
74 											  Tid_Comma,
75 											  Tid_Assign };
76 	static F_Tok stateF_afterSize[] =		{ &PE_Variable::On_afterSize_ArrayBracket_Right };
77 	static INT16 stateT_afterSize[] =		{ Tid_ArrayBracket_Right };
78 	static F_Tok stateF_expectFinish[] =	{ &PE_Variable::On_expectFinish_Bracket_Right,
79                                               &PE_Variable::On_expectFinish_Semicolon,
80 											  &PE_Variable::On_expectFinish_Comma };
81 	static INT16 stateT_expectFinish[] =   	{ Tid_Bracket_Right,
82                                               Tid_Semicolon,
83 											  Tid_Comma };
84 
85 	SEMPARSE_CREATE_STATUS(PE_Variable, afterName, Hdl_SyntaxError);
86 	SEMPARSE_CREATE_STATUS(PE_Variable, afterSize, Hdl_SyntaxError);
87 	SEMPARSE_CREATE_STATUS(PE_Variable, expectFinish, Hdl_SyntaxError);
88 }
89 
90 void
InitData()91 PE_Variable::InitData()
92 {
93     pStati->SetCur(afterName);
94 
95     sResultSizeExpression.clear();
96     sResultInitExpression.clear();
97 }
98 
99 void
TransferData()100 PE_Variable::TransferData()
101 {
102     pStati->SetCur(size_of_states);
103 }
104 
105 void
Hdl_SyntaxError(const char * i_sText)106 PE_Variable::Hdl_SyntaxError( const char * i_sText)
107 {
108 	StdHandlingOfSyntaxError(i_sText);
109 }
110 
111 void
SpReturn_ArraySizeExpression()112 PE_Variable::SpReturn_ArraySizeExpression()
113 {
114     pStati->SetCur(afterSize);
115 
116     sResultSizeExpression = pSpuArraySizeExpression->Child().Result_Text();
117 }
118 
119 void
SpReturn_InitExpression()120 PE_Variable::SpReturn_InitExpression()
121 {
122     pStati->SetCur(expectFinish);
123 
124     sResultInitExpression = pSpuInitExpression->Child().Result_Text();
125 }
126 
127 void
On_afterName_ArrayBracket_Left(const char *)128 PE_Variable::On_afterName_ArrayBracket_Left(const char *)
129 {
130     pSpuArraySizeExpression->Push(done);
131 }
132 
133 void
On_afterName_Semicolon(const char *)134 PE_Variable::On_afterName_Semicolon(const char *)
135 {
136     SetTokenResult(not_done, pop_success);
137 }
138 
139 void
On_afterName_Comma(const char *)140 PE_Variable::On_afterName_Comma(const char *)
141 {
142     SetTokenResult(not_done, pop_success);
143 }
144 
145 void
On_afterName_Assign(const char *)146 PE_Variable::On_afterName_Assign(const char *)
147 {
148     pSpuInitExpression->Push(done);
149 }
150 
151 void
On_afterSize_ArrayBracket_Right(const char *)152 PE_Variable::On_afterSize_ArrayBracket_Right(const char *)
153 {
154     SetTokenResult(done, stay);
155     pStati->SetCur(afterName);
156 }
157 
158 void
On_expectFinish_Semicolon(const char *)159 PE_Variable::On_expectFinish_Semicolon(const char *)
160 {
161     SetTokenResult(not_done, pop_success);
162 }
163 
164 void
On_expectFinish_Comma(const char *)165 PE_Variable::On_expectFinish_Comma(const char *)
166 {
167     SetTokenResult(not_done, pop_success);
168 }
169 
170 void
On_expectFinish_Bracket_Right(const char *)171 PE_Variable::On_expectFinish_Bracket_Right(const char *)
172 {
173     SetTokenResult(not_done, pop_success);
174 }
175 
176 
177 }   // namespace cpp
178 
179 
180 
181 
182