1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <precomp.h> 29 #include <s2_luidl/pe_iface.hxx> 30 31 32 // NOT FULLY DEFINED SERVICES 33 #include <ary/idl/i_interface.hxx> 34 #include <ary/idl/i_gate.hxx> 35 #include <ary/idl/ip_ce.hxx> 36 #include <ary/doc/d_oldidldocu.hxx> 37 #include <s2_luidl/pe_func2.hxx> 38 #include <s2_luidl/pe_attri.hxx> 39 #include <s2_luidl/pe_type2.hxx> 40 #include <s2_luidl/tk_keyw.hxx> 41 #include <s2_luidl/tk_ident.hxx> 42 #include <s2_luidl/tk_punct.hxx> 43 #include <adc_cl.hxx> 44 45 46 47 namespace csi 48 { 49 namespace uidl 50 { 51 52 #ifdef DF 53 #undef DF 54 #endif 55 #define DF &PE_Interface::On_Default 56 57 PE_Interface::F_TOK 58 PE_Interface::aDispatcher[PE_Interface::e_STATES_MAX][PE_Interface::tt_MAX] = 59 { { DF, DF, DF, DF, DF }, // e_none 60 { &PE_Interface::On_need_uik_MetaType, 61 DF, DF, DF, DF }, // need_uik 62 { DF, &PE_Interface::On_uik_Identifier, 63 &PE_Interface::On_uik_Punctuation, 64 DF, DF }, // uik 65 { &PE_Interface::On_need_ident_MetaType, 66 DF, DF, DF, DF }, // need_ident 67 { DF, &PE_Interface::On_ident_Identifier, 68 &PE_Interface::On_ident_Punctuation, 69 DF, DF }, // ident 70 { &PE_Interface::On_need_interface_MetaType, 71 DF, DF, DF, DF }, // need_interface 72 { DF, &PE_Interface::On_need_name_Identifer, 73 DF, DF, DF }, // need_name 74 { DF, DF, &PE_Interface::On_wait_for_base_Punctuation, 75 DF, DF }, // wait_for_base 76 { DF, DF, DF, DF, DF }, // in_base 77 { DF, DF, &PE_Interface::On_need_curlbr_open_Punctuation, 78 DF, DF }, // need_curlbr_open 79 { &PE_Interface::On_std_Metatype, 80 &PE_Interface::On_std_GotoFunction, 81 &PE_Interface::On_std_Punctuation, 82 &PE_Interface::On_std_GotoFunction, 83 &PE_Interface::On_std_Stereotype }, // e_std 84 { DF, DF, DF, DF, DF }, // in_function 85 { DF, DF, DF, DF, DF }, // in_attribute 86 { DF, DF, &PE_Interface::On_need_finish_Punctuation, 87 DF, DF }, // need_finish 88 { DF, DF, DF, DF, DF } // in_base_interface 89 }; 90 91 92 93 inline void 94 PE_Interface::CallHandler( const char * i_sTokenText, 95 E_TokenType i_eTokenType ) 96 { (this->*aDispatcher[eState][i_eTokenType])(i_sTokenText); } 97 98 99 100 PE_Interface::PE_Interface() 101 : eState(e_none), 102 sData_Name(), 103 bIsPreDeclaration(false), 104 pCurInterface(0), 105 nCurInterface(0), 106 pPE_Function(0), 107 pPE_Attribute(0), 108 pPE_Type(0), 109 nCurParsed_Base(0), 110 bOptionalMember(false) 111 { 112 pPE_Function = new PE_Function(nCurInterface); 113 pPE_Type = new PE_Type(nCurParsed_Base); 114 pPE_Attribute = new PE_Attribute(nCurInterface); 115 } 116 117 void 118 PE_Interface::EstablishContacts( UnoIDL_PE * io_pParentPE, 119 ary::Repository & io_rRepository, 120 TokenProcessing_Result & o_rResult ) 121 { 122 UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult); 123 pPE_Function->EstablishContacts(this,io_rRepository,o_rResult); 124 pPE_Type->EstablishContacts(this,io_rRepository,o_rResult); 125 pPE_Attribute->EstablishContacts(this,io_rRepository,o_rResult); 126 } 127 128 PE_Interface::~PE_Interface() 129 { 130 } 131 132 void 133 PE_Interface::ProcessToken( const Token & i_rToken ) 134 { 135 i_rToken.Trigger(*this); 136 } 137 138 139 void 140 PE_Interface::Process_MetaType( const TokMetaType & i_rToken ) 141 { 142 CallHandler( i_rToken.Text(), tt_metatype ); 143 } 144 145 void 146 PE_Interface::Process_Identifier( const TokIdentifier & i_rToken ) 147 { 148 CallHandler( i_rToken.Text(), tt_identifier ); 149 } 150 151 void 152 PE_Interface::Process_Punctuation( const TokPunctuation & i_rToken ) 153 { 154 CallHandler( i_rToken.Text(), tt_punctuation ); 155 } 156 157 void 158 PE_Interface::Process_NameSeparator() 159 { 160 CallHandler( "", tt_startoftype ); 161 } 162 163 void 164 PE_Interface::Process_BuiltInType( const TokBuiltInType & i_rToken ) 165 { 166 CallHandler( i_rToken.Text(), tt_startoftype ); 167 } 168 169 void 170 PE_Interface::Process_TypeModifier( const TokTypeModifier & i_rToken ) 171 { 172 CallHandler( i_rToken.Text(), tt_startoftype ); 173 } 174 175 void 176 PE_Interface::Process_Stereotype( const TokStereotype & i_rToken ) 177 { 178 CallHandler( i_rToken.Text(), tt_stereotype ); 179 } 180 181 void 182 PE_Interface::Process_Default() 183 { 184 SetResult(done, stay); 185 } 186 187 188 void 189 PE_Interface::On_need_uik_MetaType(const char *) 190 { 191 // Deprecated, data will be ignored 192 SetResult(done, stay); 193 eState = uik; 194 } 195 196 void 197 PE_Interface::On_uik_Identifier(const char *) 198 { 199 // Deprecated, data will be ignored 200 SetResult(done, stay); 201 } 202 203 void 204 PE_Interface::On_uik_Punctuation(const char * i_sText) 205 { 206 // Deprecated, data will be ignored 207 SetResult(done, stay); 208 if (strcmp(",",i_sText) == 0) 209 { 210 eState = need_ident; 211 } 212 } 213 214 void 215 PE_Interface::On_need_ident_MetaType(const char *) 216 { 217 SetResult(done, stay); 218 eState = ident; 219 } 220 221 void 222 PE_Interface::On_ident_Identifier(const char *) 223 { 224 SetResult(done, stay); 225 } 226 227 void 228 PE_Interface::On_ident_Punctuation(const char * i_sText) 229 { 230 SetResult(done, stay); 231 if (strcmp(")",i_sText) == 0) 232 { 233 eState = need_interface; 234 } 235 } 236 237 void 238 PE_Interface::On_need_interface_MetaType(const char *) 239 { 240 SetResult(done, stay); 241 eState = need_name; 242 } 243 244 void 245 PE_Interface::On_need_name_Identifer(const char * i_sText) 246 { 247 SetResult(done, stay); 248 sData_Name = i_sText; 249 eState = wait_for_base; 250 } 251 252 void 253 PE_Interface::On_wait_for_base_Punctuation(const char * i_sText) 254 { 255 if (i_sText[0] != ';') 256 { 257 switch (i_sText[0]) 258 { 259 case ':': 260 SetResult(done, push_sure, pPE_Type.Ptr()); 261 eState = in_base; 262 break; 263 case '{': 264 store_Interface(); 265 266 SetResult(done,stay); 267 eState = e_std; 268 break; 269 default: 270 SetResult(not_done, pop_failure); 271 eState = e_none; 272 } // end switch 273 } 274 else 275 { 276 bIsPreDeclaration = true; 277 SetResult(done, pop_success); 278 eState = e_none; 279 } 280 } 281 282 void 283 PE_Interface::On_need_curlbr_open_Punctuation(const char * i_sText) 284 { 285 if (i_sText[0] == '{') 286 { 287 store_Interface(); 288 289 SetResult(done, stay); 290 eState = e_std; 291 } 292 else { 293 csv_assert(false); 294 } 295 } 296 297 298 void 299 PE_Interface::On_std_Metatype(const char * i_sText) 300 { 301 if (strcmp(i_sText,"attribute") == 0) 302 On_std_GotoAttribute(i_sText); 303 else if (strcmp(i_sText,"interface") == 0) 304 On_std_GotoBaseInterface(i_sText); 305 else 306 On_std_GotoFunction(i_sText); 307 } 308 309 void 310 PE_Interface::On_std_Punctuation(const char * i_sText) 311 { 312 switch (i_sText[0]) 313 { 314 case '}': 315 SetResult(done, stay); 316 eState = need_finish; 317 break; 318 case ';': // Appears after base interface declarations. 319 SetResult(done, stay); 320 break; 321 default: 322 SetResult(not_done, pop_failure); 323 eState = e_none; 324 } // end switch 325 } 326 327 void 328 PE_Interface::On_std_Stereotype(const char * i_sText) 329 { 330 if (strcmp(i_sText,"oneway") == 0) 331 On_std_GotoFunction(i_sText); 332 else if ( strcmp(i_sText,"readonly") == 0 333 OR strcmp(i_sText,"bound") == 0 ) 334 On_std_GotoAttribute(i_sText); 335 else if (strcmp(i_sText,"optional") == 0) 336 { 337 bOptionalMember = true; 338 SetResult(done, stay); 339 } 340 else 341 SetResult(not_done, pop_failure); 342 } 343 344 void 345 PE_Interface::On_std_GotoFunction(const char * ) 346 { 347 SetResult(not_done, push_sure, pPE_Function.Ptr()); 348 eState = in_function; 349 } 350 351 void 352 PE_Interface::On_std_GotoAttribute(const char * ) 353 { 354 SetResult(not_done, push_sure, pPE_Attribute.Ptr()); 355 eState = in_attribute; 356 } 357 358 void 359 PE_Interface::On_std_GotoBaseInterface(const char * ) 360 { 361 SetResult(done, push_sure, pPE_Type.Ptr()); 362 eState = in_base_interface; 363 } 364 365 void 366 PE_Interface::On_need_finish_Punctuation(const char * i_sText) 367 { 368 switch (i_sText[0]) 369 { 370 case ';': 371 SetResult(done, pop_success); 372 eState = e_none; 373 break; 374 default: 375 SetResult(not_done, pop_failure); 376 eState = e_none; 377 } // end switch 378 } 379 380 void 381 PE_Interface::On_Default(const char *) 382 { 383 SetResult(not_done, pop_failure); 384 } 385 386 void 387 PE_Interface::InitData() 388 { 389 eState = need_interface; 390 391 sData_Name.clear(); 392 bIsPreDeclaration = false; 393 pCurInterface = 0; 394 nCurInterface = 0; 395 nCurParsed_Base = 0; 396 bOptionalMember = false; 397 } 398 399 void 400 PE_Interface::TransferData() 401 { 402 if (NOT bIsPreDeclaration) 403 { 404 csv_assert(sData_Name.size() > 0); 405 csv_assert(nCurInterface.IsValid()); 406 } 407 else 408 { 409 sData_Name.clear(); 410 pCurInterface = 0; 411 nCurInterface = 0; 412 } 413 414 eState = e_none; 415 } 416 417 void 418 PE_Interface::ReceiveData() 419 { 420 switch (eState) 421 { 422 case in_base: 423 eState = need_curlbr_open; 424 break; 425 case in_function: 426 eState = e_std; 427 break; 428 case in_attribute: 429 eState = e_std; 430 break; 431 case in_base_interface: 432 if (bOptionalMember) 433 { 434 pPE_Type->SetOptional(); 435 bOptionalMember = false; 436 } 437 pCurInterface->Add_Base( 438 nCurParsed_Base, 439 pPE_Type->ReleaseDocu()); 440 nCurParsed_Base = 0; 441 eState = e_std; 442 break; 443 default: 444 csv_assert(false); 445 } 446 } 447 448 UnoIDL_PE & 449 PE_Interface::MyPE() 450 { 451 return *this; 452 } 453 454 void 455 PE_Interface::store_Interface() 456 { 457 pCurInterface = & Gate().Ces().Store_Interface( 458 CurNamespace().CeId(), 459 sData_Name, 460 nCurParsed_Base ); 461 nCurInterface = pCurInterface->CeId(); 462 PassDocuAt(*pCurInterface); 463 } 464 465 466 } // namespace uidl 467 } // namespace csi 468