1*78bc99aaSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*78bc99aaSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*78bc99aaSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*78bc99aaSAndrew Rist * distributed with this work for additional information 6*78bc99aaSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*78bc99aaSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*78bc99aaSAndrew Rist * "License"); you may not use this file except in compliance 9*78bc99aaSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*78bc99aaSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*78bc99aaSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*78bc99aaSAndrew Rist * software distributed under the License is distributed on an 15*78bc99aaSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*78bc99aaSAndrew Rist * KIND, either express or implied. See the License for the 17*78bc99aaSAndrew Rist * specific language governing permissions and limitations 18*78bc99aaSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*78bc99aaSAndrew Rist *************************************************************/ 21cdf0e10cSrcweir 22cdf0e10cSrcweir #include <precomp.h> 23cdf0e10cSrcweir #include <s2_luidl/pe_func2.hxx> 24cdf0e10cSrcweir 25cdf0e10cSrcweir 26cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES 27cdf0e10cSrcweir #include <ary/idl/i_function.hxx> 28cdf0e10cSrcweir #include <ary/idl/i_type.hxx> 29cdf0e10cSrcweir #include <ary/idl/i_gate.hxx> 30cdf0e10cSrcweir #include <ary/idl/ip_ce.hxx> 31cdf0e10cSrcweir #include <ary/idl/ip_type.hxx> 32cdf0e10cSrcweir #include <ary/doc/d_oldidldocu.hxx> 33cdf0e10cSrcweir #include <s2_luidl/pe_type2.hxx> 34cdf0e10cSrcweir #include <s2_luidl/pe_vari2.hxx> 35cdf0e10cSrcweir #include <s2_luidl/tk_keyw.hxx> 36cdf0e10cSrcweir #include <s2_luidl/tk_ident.hxx> 37cdf0e10cSrcweir #include <s2_luidl/tk_punct.hxx> 38cdf0e10cSrcweir #include <x_parse2.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir 41cdf0e10cSrcweir namespace csi 42cdf0e10cSrcweir { 43cdf0e10cSrcweir namespace uidl 44cdf0e10cSrcweir { 45cdf0e10cSrcweir 46cdf0e10cSrcweir 47cdf0e10cSrcweir PE_Function::PE_Function( const RParent & i_rCurInterface ) 48cdf0e10cSrcweir : eState(e_none), 49cdf0e10cSrcweir sData_Name(), 50cdf0e10cSrcweir nData_ReturnType(0), 51cdf0e10cSrcweir bData_Oneway(false), 52cdf0e10cSrcweir pCurFunction(0), 53cdf0e10cSrcweir pCurParent(&i_rCurInterface), 54cdf0e10cSrcweir pPE_Type(0), 55cdf0e10cSrcweir nCurParsedType(0), 56cdf0e10cSrcweir sName(), 57cdf0e10cSrcweir pPE_Variable(0), 58cdf0e10cSrcweir eCurParsedParam_Direction(ary::idl::param_in), 59cdf0e10cSrcweir nCurParsedParam_Type(0), 60cdf0e10cSrcweir sCurParsedParam_Name(), 61cdf0e10cSrcweir bIsForConstructors(false) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir pPE_Type = new PE_Type(nCurParsedType); 64cdf0e10cSrcweir pPE_Variable = new PE_Variable(nCurParsedParam_Type, sCurParsedParam_Name); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir PE_Function::PE_Function( const RParent & i_rCurService, 68cdf0e10cSrcweir E_Constructor ) 69cdf0e10cSrcweir : eState(expect_name), 70cdf0e10cSrcweir sData_Name(), 71cdf0e10cSrcweir nData_ReturnType(0), 72cdf0e10cSrcweir bData_Oneway(false), 73cdf0e10cSrcweir pCurFunction(0), 74cdf0e10cSrcweir pCurParent(&i_rCurService), 75cdf0e10cSrcweir pPE_Type(0), 76cdf0e10cSrcweir nCurParsedType(0), 77cdf0e10cSrcweir sName(), 78cdf0e10cSrcweir pPE_Variable(0), 79cdf0e10cSrcweir eCurParsedParam_Direction(ary::idl::param_in), 80cdf0e10cSrcweir nCurParsedParam_Type(0), 81cdf0e10cSrcweir sCurParsedParam_Name(), 82cdf0e10cSrcweir bIsForConstructors(true) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir pPE_Type = new PE_Type(nCurParsedType); 85cdf0e10cSrcweir pPE_Variable = new PE_Variable(nCurParsedParam_Type, sCurParsedParam_Name); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir void 89cdf0e10cSrcweir PE_Function::EstablishContacts( UnoIDL_PE * io_pParentPE, 90cdf0e10cSrcweir ary::Repository & io_rRepository, 91cdf0e10cSrcweir TokenProcessing_Result & o_rResult ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult); 94cdf0e10cSrcweir pPE_Type->EstablishContacts(this,io_rRepository,o_rResult); 95cdf0e10cSrcweir pPE_Variable->EstablishContacts(this,io_rRepository,o_rResult); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir PE_Function::~PE_Function() 99cdf0e10cSrcweir { 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir void 103cdf0e10cSrcweir PE_Function::ProcessToken( const Token & i_rToken ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir i_rToken.Trigger(*this); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir void 109cdf0e10cSrcweir PE_Function::Process_Stereotype( const TokStereotype & i_rToken ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir if (eState == e_start) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir switch (i_rToken.Id()) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir case TokStereotype::ste_oneway: 116cdf0e10cSrcweir bData_Oneway = true; 117cdf0e10cSrcweir SetResult(done, stay); 118cdf0e10cSrcweir break; 119cdf0e10cSrcweir default: 120cdf0e10cSrcweir OnDefault(); 121cdf0e10cSrcweir } // end switch 122cdf0e10cSrcweir } 123cdf0e10cSrcweir else 124cdf0e10cSrcweir OnDefault(); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir void 128cdf0e10cSrcweir PE_Function::Process_Identifier( const TokIdentifier & i_rToken ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir switch (eState) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir case e_start: 133cdf0e10cSrcweir GoIntoReturnType(); 134cdf0e10cSrcweir break; 135cdf0e10cSrcweir case expect_name: 136cdf0e10cSrcweir sData_Name = i_rToken.Text(); 137cdf0e10cSrcweir SetResult(done,stay); 138cdf0e10cSrcweir eState = expect_params_list; 139cdf0e10cSrcweir 140cdf0e10cSrcweir if (NOT bIsForConstructors) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir pCurFunction = &Gate().Ces().Store_Function( 143cdf0e10cSrcweir *pCurParent, 144cdf0e10cSrcweir sData_Name, 145cdf0e10cSrcweir nData_ReturnType, 146cdf0e10cSrcweir bData_Oneway ); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir else 149cdf0e10cSrcweir { 150cdf0e10cSrcweir pCurFunction = &Gate().Ces().Store_ServiceConstructor( 151cdf0e10cSrcweir *pCurParent, 152cdf0e10cSrcweir sData_Name ); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir PassDocuAt(*pCurFunction); 155cdf0e10cSrcweir break; 156cdf0e10cSrcweir case expect_parameter_variable: 157cdf0e10cSrcweir GoIntoParameterVariable(); 158cdf0e10cSrcweir break; 159cdf0e10cSrcweir case expect_exception: 160cdf0e10cSrcweir GoIntoException(); 161cdf0e10cSrcweir break; 162cdf0e10cSrcweir default: 163cdf0e10cSrcweir OnDefault(); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir void 168cdf0e10cSrcweir PE_Function::Process_Punctuation( const TokPunctuation & i_rToken ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir switch (eState) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir case e_start: 173cdf0e10cSrcweir SetResult(done,stay); 174cdf0e10cSrcweir break; 175cdf0e10cSrcweir case expect_params_list: 176cdf0e10cSrcweir if (i_rToken.Id() != TokPunctuation::BracketOpen) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir OnDefault(); 179cdf0e10cSrcweir return; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir SetResult(done,stay); 182cdf0e10cSrcweir eState = expect_parameter; 183cdf0e10cSrcweir break; 184cdf0e10cSrcweir case expect_parameter: 185cdf0e10cSrcweir if (i_rToken.Id() == TokPunctuation::BracketClose) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir SetResult(done,stay); 188cdf0e10cSrcweir eState = params_finished; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir else 191cdf0e10cSrcweir { 192cdf0e10cSrcweir OnDefault(); 193cdf0e10cSrcweir return; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir break; 196cdf0e10cSrcweir case expect_parameter_separator: 197cdf0e10cSrcweir if (i_rToken.Id() == TokPunctuation::Comma) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir SetResult(done,stay); 200cdf0e10cSrcweir eState = expect_parameter; 201cdf0e10cSrcweir } 202cdf0e10cSrcweir else if (i_rToken.Id() == TokPunctuation::BracketClose) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir SetResult(done,stay); 205cdf0e10cSrcweir eState = params_finished; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir else 208cdf0e10cSrcweir { 209cdf0e10cSrcweir OnDefault(); 210cdf0e10cSrcweir return; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir break; 213cdf0e10cSrcweir case params_finished: 214cdf0e10cSrcweir case exceptions_finished: 215cdf0e10cSrcweir if (i_rToken.Id() != TokPunctuation::Semicolon) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir OnDefault(); 218cdf0e10cSrcweir return; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir SetResult(done,pop_success); 221cdf0e10cSrcweir eState = e_none; 222cdf0e10cSrcweir break; 223cdf0e10cSrcweir case expect_exceptions_list: 224cdf0e10cSrcweir if (i_rToken.Id() != TokPunctuation::BracketOpen) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir OnDefault(); 227cdf0e10cSrcweir return; 228cdf0e10cSrcweir } 229cdf0e10cSrcweir SetResult(done,stay); 230cdf0e10cSrcweir eState = expect_exception; 231cdf0e10cSrcweir break; 232cdf0e10cSrcweir case expect_exception_separator: 233cdf0e10cSrcweir if (i_rToken.Id() == TokPunctuation::Comma) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir SetResult(done,stay); 236cdf0e10cSrcweir eState = expect_exception; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir else if (i_rToken.Id() == TokPunctuation::BracketClose) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir SetResult(done,stay); 241cdf0e10cSrcweir eState = exceptions_finished; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir else 244cdf0e10cSrcweir { 245cdf0e10cSrcweir OnDefault(); 246cdf0e10cSrcweir return; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir break; 249cdf0e10cSrcweir default: 250cdf0e10cSrcweir OnDefault(); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir void 255cdf0e10cSrcweir PE_Function::Process_BuiltInType( const TokBuiltInType & i_rToken ) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir switch (eState) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir case e_start: 260cdf0e10cSrcweir GoIntoReturnType(); 261cdf0e10cSrcweir break; 262cdf0e10cSrcweir case expect_parameter_variable: 263cdf0e10cSrcweir GoIntoParameterVariable(); 264cdf0e10cSrcweir break; 265cdf0e10cSrcweir case expect_parameter_separator: 266cdf0e10cSrcweir if (i_rToken.Id() != TokBuiltInType::bty_ellipse) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir OnDefault(); 269cdf0e10cSrcweir } 270cdf0e10cSrcweir else 271cdf0e10cSrcweir { 272cdf0e10cSrcweir pCurFunction->Set_Ellipse(); 273cdf0e10cSrcweir SetResult(done,stay); 274cdf0e10cSrcweir // eState stays the same, because we wait for the closing ")" now. 275cdf0e10cSrcweir } 276cdf0e10cSrcweir break; 277cdf0e10cSrcweir case expect_exception: 278cdf0e10cSrcweir GoIntoException(); 279cdf0e10cSrcweir break; 280cdf0e10cSrcweir default: 281cdf0e10cSrcweir OnDefault(); 282cdf0e10cSrcweir } // end switch 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir void 286cdf0e10cSrcweir PE_Function::Process_ParameterHandling( const TokParameterHandling & i_rToken ) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir if (eState != expect_parameter) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir OnDefault(); 291cdf0e10cSrcweir return; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir switch (i_rToken.Id()) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir case TokParameterHandling::ph_in: 297cdf0e10cSrcweir eCurParsedParam_Direction = ary::idl::param_in; 298cdf0e10cSrcweir break; 299cdf0e10cSrcweir case TokParameterHandling::ph_out: 300cdf0e10cSrcweir eCurParsedParam_Direction = ary::idl::param_out; 301cdf0e10cSrcweir break; 302cdf0e10cSrcweir case TokParameterHandling::ph_inout: 303cdf0e10cSrcweir eCurParsedParam_Direction = ary::idl::param_inout; 304cdf0e10cSrcweir break; 305cdf0e10cSrcweir default: 306cdf0e10cSrcweir csv_assert(false); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir SetResult(done,stay); 309cdf0e10cSrcweir eState = expect_parameter_variable; 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir void 313cdf0e10cSrcweir PE_Function::Process_Raises() 314cdf0e10cSrcweir { 315cdf0e10cSrcweir if (eState != params_finished) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir OnDefault(); 318cdf0e10cSrcweir return; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir SetResult(done,stay); 321cdf0e10cSrcweir eState = expect_exceptions_list; 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir void 325cdf0e10cSrcweir PE_Function::Process_Default() 326cdf0e10cSrcweir { 327cdf0e10cSrcweir switch (eState) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir case e_start: 330cdf0e10cSrcweir GoIntoReturnType(); 331cdf0e10cSrcweir break; 332cdf0e10cSrcweir case expect_parameter_variable: 333cdf0e10cSrcweir GoIntoParameterVariable(); 334cdf0e10cSrcweir break; 335cdf0e10cSrcweir case expect_exception: 336cdf0e10cSrcweir GoIntoException(); 337cdf0e10cSrcweir break; 338cdf0e10cSrcweir default: 339cdf0e10cSrcweir OnDefault(); 340cdf0e10cSrcweir } // end switch 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir void 344cdf0e10cSrcweir PE_Function::GoIntoReturnType() 345cdf0e10cSrcweir { 346cdf0e10cSrcweir SetResult(not_done, push_sure, pPE_Type.Ptr()); 347cdf0e10cSrcweir eState = in_return_type; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir void 351cdf0e10cSrcweir PE_Function::GoIntoParameterVariable() 352cdf0e10cSrcweir { 353cdf0e10cSrcweir SetResult(not_done, push_sure, pPE_Variable.Ptr()); 354cdf0e10cSrcweir eState = in_parameter_variable; 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir void 358cdf0e10cSrcweir PE_Function::GoIntoException() 359cdf0e10cSrcweir { 360cdf0e10cSrcweir SetResult(not_done, push_sure, pPE_Type.Ptr()); 361cdf0e10cSrcweir eState = in_exception; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir void 365cdf0e10cSrcweir PE_Function::OnDefault() 366cdf0e10cSrcweir { 367cdf0e10cSrcweir throw X_AutodocParser(X_AutodocParser::x_Any); 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir void 371cdf0e10cSrcweir PE_Function::InitData() 372cdf0e10cSrcweir { 373cdf0e10cSrcweir eState = e_start; 374cdf0e10cSrcweir 375cdf0e10cSrcweir sData_Name.clear(); 376cdf0e10cSrcweir nData_ReturnType = 0; 377cdf0e10cSrcweir bData_Oneway = false; 378cdf0e10cSrcweir pCurFunction = 0; 379cdf0e10cSrcweir 380cdf0e10cSrcweir nCurParsedType = 0; 381cdf0e10cSrcweir eCurParsedParam_Direction = ary::idl::param_in; 382cdf0e10cSrcweir nCurParsedParam_Type = 0; 383cdf0e10cSrcweir sCurParsedParam_Name.clear(); 384cdf0e10cSrcweir 385cdf0e10cSrcweir if (bIsForConstructors) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir eState = expect_name; 388cdf0e10cSrcweir } 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir void 392cdf0e10cSrcweir PE_Function::ReceiveData() 393cdf0e10cSrcweir { 394cdf0e10cSrcweir switch (eState) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir case in_return_type: 397cdf0e10cSrcweir nData_ReturnType = nCurParsedType; 398cdf0e10cSrcweir nCurParsedType = 0; 399cdf0e10cSrcweir eState = expect_name; 400cdf0e10cSrcweir break; 401cdf0e10cSrcweir case in_parameter_variable: 402cdf0e10cSrcweir csv_assert(pCurFunction != 0); 403cdf0e10cSrcweir pCurFunction->Add_Parameter( 404cdf0e10cSrcweir sCurParsedParam_Name, 405cdf0e10cSrcweir nCurParsedParam_Type, 406cdf0e10cSrcweir eCurParsedParam_Direction ); 407cdf0e10cSrcweir sCurParsedParam_Name = ""; 408cdf0e10cSrcweir nCurParsedParam_Type = 0; 409cdf0e10cSrcweir eCurParsedParam_Direction = ary::idl::param_in; 410cdf0e10cSrcweir eState = expect_parameter_separator; 411cdf0e10cSrcweir break; 412cdf0e10cSrcweir case in_exception: 413cdf0e10cSrcweir csv_assert(pCurFunction != 0); 414cdf0e10cSrcweir pCurFunction->Add_Exception(nCurParsedType); 415cdf0e10cSrcweir eState = expect_exception_separator; 416cdf0e10cSrcweir break; 417cdf0e10cSrcweir default: 418cdf0e10cSrcweir csv_assert(false); 419cdf0e10cSrcweir } // end switch 420cdf0e10cSrcweir } 421cdf0e10cSrcweir 422cdf0e10cSrcweir void 423cdf0e10cSrcweir PE_Function::TransferData() 424cdf0e10cSrcweir { 425cdf0e10cSrcweir pCurFunction = 0; 426cdf0e10cSrcweir eState = e_none; 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir UnoIDL_PE & 430cdf0e10cSrcweir PE_Function::MyPE() 431cdf0e10cSrcweir { 432cdf0e10cSrcweir return *this; 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir 436cdf0e10cSrcweir 437cdf0e10cSrcweir } // namespace uidl 438cdf0e10cSrcweir } // namespace csi 439cdf0e10cSrcweir 440