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 <s2_luidl/pe_const.hxx> 24 25 // NOT FULLY DECLARED SERVICES 26 #include <ary/idl/i_gate.hxx> 27 #include <ary/idl/i_constant.hxx> 28 #include <ary/idl/i_constgroup.hxx> 29 #include <ary/idl/ip_ce.hxx> 30 #include <ary/doc/d_oldidldocu.hxx> 31 #include <s2_luidl/pe_type2.hxx> 32 #include <s2_luidl/pe_evalu.hxx> 33 #include <s2_luidl/tk_punct.hxx> 34 #include <s2_luidl/tk_ident.hxx> 35 #include <s2_luidl/tk_keyw.hxx> 36 37 38 namespace csi 39 { 40 namespace uidl 41 { 42 43 44 #ifdef DF 45 #undef DF 46 #endif 47 #define DF &PE_Constant::On_Default 48 49 PE_Constant::F_TOK 50 PE_Constant::aDispatcher[PE_Constant::e_STATES_MAX][PE_Constant::tt_MAX] = 51 { { DF, DF, DF }, // e_none 52 { DF, &PE_Constant::On_expect_name_Identifier, 53 DF }, // expect_name 54 { DF, DF, &PE_Constant::On_expect_curl_bracket_open_Punctuation }, // expect_curl_bracket_open 55 { &PE_Constant::On_expect_const_Stereotype, 56 DF, &PE_Constant::On_expect_const_Punctuation }, // expect_const 57 { DF, &PE_Constant::On_expect_value_Identifier, 58 DF }, // expect_value 59 { DF, DF, &PE_Constant::On_expect_finish_Punctuation } // expect_finish 60 }; 61 62 63 64 inline void 65 PE_Constant::CallHandler( const char * i_sTokenText, 66 E_TokenType i_eTokenType ) 67 { (this->*aDispatcher[eState][i_eTokenType])(i_sTokenText); } 68 69 70 71 72 PE_Constant::PE_Constant() 73 : eState(e_none), 74 sData_Name(), 75 nDataId(0), 76 pPE_Type(0), 77 nType(0), 78 pPE_Value(0), 79 sName(), 80 sAssignment() 81 { 82 pPE_Type = new PE_Type(nType); 83 pPE_Value = new PE_Value(sName, sAssignment, true); 84 } 85 86 void 87 PE_Constant::EstablishContacts( UnoIDL_PE * io_pParentPE, 88 ary::Repository & io_rRepository, 89 TokenProcessing_Result & o_rResult ) 90 { 91 UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult); 92 pPE_Type->EstablishContacts(this,io_rRepository,o_rResult); 93 pPE_Value->EstablishContacts(this,io_rRepository,o_rResult); 94 } 95 96 PE_Constant::~PE_Constant() 97 { 98 } 99 100 void 101 PE_Constant::ProcessToken( const Token & i_rToken ) 102 { 103 i_rToken.Trigger(*this); 104 } 105 106 void 107 PE_Constant::Process_Identifier( const TokIdentifier & i_rToken ) 108 { 109 CallHandler(i_rToken.Text(), tt_identifier); 110 } 111 112 void 113 PE_Constant::Process_Punctuation( const TokPunctuation & i_rToken ) 114 { 115 CallHandler(i_rToken.Text(), tt_punctuation); 116 } 117 118 void 119 PE_Constant::Process_Stereotype( const TokStereotype & i_rToken ) 120 { 121 CallHandler(i_rToken.Text(), tt_stereotype); 122 } 123 124 void 125 PE_Constant::On_expect_name_Identifier(const char * i_sText) 126 { 127 sName = i_sText; 128 129 SetResult(done,stay); 130 eState = expect_curl_bracket_open; 131 } 132 133 void 134 PE_Constant::On_expect_curl_bracket_open_Punctuation(const char * i_sText) 135 { 136 if ( i_sText[0] == '{') 137 { 138 sData_Name = sName; 139 140 ary::idl::ConstantsGroup & 141 rCe = Gate().Ces(). 142 Store_ConstantsGroup(CurNamespace().CeId(),sData_Name); 143 PassDocuAt(rCe); 144 nDataId = rCe.CeId(); 145 146 SetResult(done,stay); 147 eState = expect_const; 148 } 149 else 150 { 151 On_Default(i_sText); 152 } 153 } 154 155 void 156 PE_Constant::On_expect_const_Stereotype(const char *) 157 { 158 SetResult( done, push_sure, pPE_Type.Ptr() ); 159 } 160 161 void 162 PE_Constant::On_expect_const_Punctuation(const char * i_sText) 163 { 164 if ( i_sText[0] == '}') 165 { 166 SetResult(done,stay); 167 eState = expect_finish; 168 } 169 else 170 { 171 On_Default(i_sText); 172 } 173 } 174 175 void 176 PE_Constant::On_expect_value_Identifier(const char *) 177 { 178 SetResult( not_done, push_sure, pPE_Value.Ptr() ); 179 } 180 181 void 182 PE_Constant::On_expect_finish_Punctuation(const char * i_sText) 183 { 184 if ( i_sText[0] == ';') 185 { 186 SetResult(done,pop_success); 187 eState = e_none; 188 } 189 else 190 { 191 On_Default(i_sText); 192 } 193 } 194 195 void 196 PE_Constant::On_Default(const char * ) 197 { 198 SetResult(not_done,pop_failure); 199 eState = e_none; 200 } 201 202 void 203 PE_Constant::EmptySingleConstData() 204 { 205 nType = 0; 206 sName = ""; 207 sAssignment = ""; 208 } 209 210 void 211 PE_Constant::CreateSingleConstant() 212 { 213 ary::idl::Constant & 214 rCe = Gate().Ces().Store_Constant( nDataId, 215 sName, 216 nType, 217 sAssignment ); 218 pPE_Type->PassDocuAt(rCe); 219 } 220 221 void 222 PE_Constant::InitData() 223 { 224 eState = expect_name; 225 226 sData_Name.clear(); 227 nDataId = 0; 228 229 EmptySingleConstData(); 230 } 231 232 void 233 PE_Constant::ReceiveData() 234 { 235 switch (eState) 236 { 237 case expect_const: 238 eState = expect_value; 239 break; 240 case expect_value: 241 { 242 if (sName.length() == 0 OR sAssignment.length() == 0 OR NOT nType.IsValid()) 243 { 244 Cerr() << "Constant without value found." << Endl(); 245 eState = expect_const; 246 break; 247 } 248 249 CreateSingleConstant(); 250 EmptySingleConstData(); 251 eState = expect_const; 252 } break; 253 default: 254 SetResult(not_done, pop_failure); 255 eState = e_none; 256 } // end switch 257 } 258 259 void 260 PE_Constant::TransferData() 261 { 262 csv_assert(nDataId.IsValid()); 263 eState = e_none; 264 } 265 266 UnoIDL_PE & 267 PE_Constant::MyPE() 268 { 269 return *this; 270 } 271 272 } // namespace uidl 273 } // namespace csi 274 275