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_param.hxx" 24 25 26 // NOT FULLY DEFINED SERVICES 27 #include <cosv/tpl/tpltools.hxx> 28 #include <ary/cpp/c_gate.hxx> 29 #include <ary/cpp/cp_type.hxx> 30 #include "pe_type.hxx" 31 #include "pe_vari.hxx" 32 33 34 namespace cpp { 35 36 37 38 //*********************** PE_Parameter ***********************// 39 40 41 PE_Parameter::PE_Parameter( Cpp_PE * i_pParent ) 42 : Cpp_PE(i_pParent), 43 pStati( new PeStatusArray<PE_Parameter> ) 44 // pSpType, 45 // pSpuType, 46 // pSpVariable, 47 // pSpuVariable, 48 // aResultParamInfo 49 { 50 Setup_StatusFunctions(); 51 52 pSpType = new SP_Type(*this); 53 pSpuType = new SPU_Type(*pSpType, &PE_Parameter::SpInit_Type, &PE_Parameter::SpReturn_Type); 54 pSpVariable = new SP_Variable(*this); 55 pSpuVariable = new SPU_Variable(*pSpVariable, &PE_Parameter::SpInit_Variable, &PE_Parameter::SpReturn_Variable); 56 } 57 58 PE_Parameter::~PE_Parameter() 59 { 60 } 61 62 void 63 PE_Parameter::Call_Handler( const cpp::Token & i_rTok ) 64 { 65 pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text()); 66 } 67 68 void 69 PE_Parameter::Setup_StatusFunctions() 70 { 71 typedef CallFunction<PE_Parameter>::F_Tok F_Tok; 72 static F_Tok stateF_start[] = { &PE_Parameter::On_start_Type, 73 &PE_Parameter::On_start_Type, 74 &PE_Parameter::On_start_Type, 75 &PE_Parameter::On_start_Type, 76 &PE_Parameter::On_start_Type, 77 78 &PE_Parameter::On_start_Type, 79 &PE_Parameter::On_start_Type, 80 &PE_Parameter::On_start_Bracket_Right, 81 &PE_Parameter::On_start_Type, 82 &PE_Parameter::On_start_Ellipse, 83 84 &PE_Parameter::On_start_Type, 85 &PE_Parameter::On_start_Type, 86 &PE_Parameter::On_start_Type }; 87 static INT16 stateT_start[] = { Tid_Identifier, 88 Tid_class, 89 Tid_struct, 90 Tid_union, 91 Tid_enum, 92 93 Tid_const, 94 Tid_volatile, 95 Tid_Bracket_Right, 96 Tid_DoubleColon, 97 Tid_Ellipse, 98 99 Tid_typename, 100 Tid_BuiltInType, 101 Tid_TypeSpecializer }; 102 103 static F_Tok stateF_expectName[] = { &PE_Parameter::On_expectName_Identifier, 104 &PE_Parameter::On_expectName_ArrayBracket_Left, 105 &PE_Parameter::On_expectName_Bracket_Right, 106 &PE_Parameter::On_expectName_Comma, 107 &PE_Parameter::On_afterName_Assign }; 108 static INT16 stateT_expectName[] = { Tid_Identifier, 109 Tid_ArrayBracket_Left, 110 Tid_Bracket_Right, 111 Tid_Comma, 112 Tid_Assign }; 113 static F_Tok stateF_afterName[] = { &PE_Parameter::On_afterName_ArrayBracket_Left, 114 &PE_Parameter::On_afterName_Bracket_Right, 115 &PE_Parameter::On_afterName_Comma, 116 &PE_Parameter::On_afterName_Assign }; 117 static INT16 stateT_afterName[] = { Tid_ArrayBracket_Left, 118 Tid_Bracket_Right, 119 Tid_Comma, 120 Tid_Assign }; 121 static F_Tok stateF_finished[] = { &PE_Parameter::On_finished_Comma, 122 &PE_Parameter::On_finished_Bracket_Right }; 123 static INT16 stateT_finished[] = { Tid_Bracket_Right, 124 Tid_Comma }; 125 126 SEMPARSE_CREATE_STATUS(PE_Parameter, start, Hdl_SyntaxError); 127 SEMPARSE_CREATE_STATUS(PE_Parameter, expectName, Hdl_SyntaxError); 128 SEMPARSE_CREATE_STATUS(PE_Parameter, afterName, Hdl_SyntaxError); 129 SEMPARSE_CREATE_STATUS(PE_Parameter, finished, Hdl_SyntaxError); 130 } 131 132 133 void 134 PE_Parameter::InitData() 135 { 136 pStati->SetCur(start); 137 aResultParamInfo.Empty(); 138 } 139 140 void 141 PE_Parameter::TransferData() 142 { 143 pStati->SetCur(size_of_states); 144 } 145 146 void 147 PE_Parameter::Hdl_SyntaxError( const char * i_sText) 148 { 149 StdHandlingOfSyntaxError(i_sText); 150 } 151 152 void 153 PE_Parameter::SpInit_Type() 154 { 155 // Does nothing. 156 } 157 158 void 159 PE_Parameter::SpInit_Variable() 160 { 161 // Does nothing. 162 } 163 164 void 165 PE_Parameter::SpReturn_Type() 166 { 167 aResultParamInfo.nType = pSpuType->Child().Result_Type().Id(); 168 pStati->SetCur(expectName); 169 } 170 171 void 172 PE_Parameter::SpReturn_Variable() 173 { 174 if (pSpuVariable->Child().Result_Pattern() > 0) 175 { 176 aResultParamInfo.sSizeExpression = pSpuVariable->Child().Result_SizeExpression(); 177 aResultParamInfo.sInitExpression = pSpuVariable->Child().Result_InitExpression(); 178 } 179 } 180 181 void 182 PE_Parameter::On_start_Type(const char *) 183 { 184 pSpuType->Push(not_done); 185 } 186 187 void 188 PE_Parameter::On_start_Bracket_Right(const char *) 189 { 190 SetTokenResult(not_done, pop_success); 191 } 192 193 void 194 PE_Parameter::On_start_Ellipse(const char *) 195 { 196 SetTokenResult(done, pop_success); 197 198 aResultParamInfo.nType = Env().AryGate().Types().Tid_Ellipse(); 199 } 200 201 void 202 PE_Parameter::On_expectName_Identifier(const char * i_sText) 203 { 204 SetTokenResult(done, stay); 205 pStati->SetCur(afterName); 206 207 aResultParamInfo.sName = i_sText; 208 } 209 210 void 211 PE_Parameter::On_expectName_ArrayBracket_Left(const char * i_sText) 212 { 213 On_afterName_ArrayBracket_Left(i_sText); 214 } 215 216 void 217 PE_Parameter::On_expectName_Bracket_Right(const char * i_sText) 218 { 219 On_afterName_Bracket_Right(i_sText); 220 } 221 222 void 223 PE_Parameter::On_expectName_Comma(const char * i_sText) 224 { 225 On_afterName_Comma(i_sText); 226 } 227 228 void 229 PE_Parameter::On_afterName_ArrayBracket_Left(const char *) 230 { 231 pSpuVariable->Push(not_done); 232 } 233 234 void 235 PE_Parameter::On_afterName_Bracket_Right(const char *) 236 { 237 SetTokenResult(not_done, pop_success); 238 } 239 240 void 241 PE_Parameter::On_afterName_Comma(const char *) 242 { 243 SetTokenResult(not_done, pop_success); 244 } 245 246 void 247 PE_Parameter::On_afterName_Assign(const char *) 248 { 249 pSpuVariable->Push(not_done); 250 } 251 252 void 253 PE_Parameter::On_finished_Bracket_Right(const char *) 254 { 255 SetTokenResult(not_done, pop_success); 256 } 257 258 void 259 PE_Parameter::On_finished_Comma(const char *) 260 { 261 SetTokenResult(not_done, pop_success); 262 } 263 264 265 } // namespace cpp 266 267 268 269 270 271 272 273 274 275