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_tydef.hxx" 24 25 26 // NOT FULLY DECLARED SERVICES 27 #include <ary/cpp/c_gate.hxx> 28 #include <ary/cpp/c_type.hxx> 29 #include <ary/cpp/cp_ce.hxx> 30 #include <all_toks.hxx> 31 #include "pe_type.hxx" 32 33 34 namespace cpp { 35 36 37 PE_Typedef::PE_Typedef(Cpp_PE * i_pParent ) 38 : Cpp_PE(i_pParent), 39 pStati( new PeStatusArray<PE_Typedef> ), 40 // pSpType, 41 // pSpuType, 42 // sName 43 nType(0) 44 { 45 Setup_StatusFunctions(); 46 47 pSpType = new SP_Type(*this); 48 pSpuType = new SPU_Type(*pSpType, 0, &PE_Typedef::SpReturn_Type); 49 } 50 51 PE_Typedef::~PE_Typedef() 52 { 53 } 54 55 void 56 PE_Typedef::Call_Handler( const cpp::Token & i_rTok ) 57 { 58 pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text()); 59 } 60 61 void 62 PE_Typedef::Setup_StatusFunctions() 63 { 64 typedef CallFunction<PE_Typedef>::F_Tok F_Tok; 65 static F_Tok stateF_start[] = { &PE_Typedef::On_start_typedef }; 66 static INT16 stateT_start[] = { Tid_typedef }; 67 68 static F_Tok stateF_expectName[] = { &PE_Typedef::On_expectName_Identifier }; 69 static INT16 stateT_expectName[] = { Tid_Identifier }; 70 71 static F_Tok stateF_afterName[] = { &PE_Typedef::On_afterName_Semicolon }; 72 static INT16 stateT_afterName[] = { Tid_Semicolon }; 73 74 SEMPARSE_CREATE_STATUS(PE_Typedef, start, Hdl_SyntaxError); 75 SEMPARSE_CREATE_STATUS(PE_Typedef, expectName, Hdl_SyntaxError); 76 SEMPARSE_CREATE_STATUS(PE_Typedef, afterName, Hdl_SyntaxError); 77 } 78 79 void 80 PE_Typedef::InitData() 81 { 82 pStati->SetCur(start); 83 84 sName.clear(); 85 nType = 0; 86 } 87 88 void 89 PE_Typedef::TransferData() 90 { 91 pStati->SetCur(size_of_states); 92 93 ary::cpp::Typedef & 94 rTypedef = Env().AryGate().Ces().Store_Typedef( 95 Env().Context(), sName, nType ); 96 Env().Event_Store_Typedef(rTypedef); 97 } 98 99 void 100 PE_Typedef::Hdl_SyntaxError( const char * i_sText) 101 { 102 StdHandlingOfSyntaxError(i_sText); 103 } 104 105 void 106 PE_Typedef::SpReturn_Type() 107 { 108 pStati->SetCur(expectName); 109 110 nType = pSpuType->Child().Result_Type().Id(); 111 } 112 113 void 114 PE_Typedef::On_start_typedef( const char * ) 115 { 116 pSpuType->Push(done); 117 } 118 119 void 120 PE_Typedef::On_expectName_Identifier( const char * i_sText ) 121 { 122 SetTokenResult(done, stay); 123 pStati->SetCur(afterName); 124 125 sName = i_sText; 126 } 127 128 void 129 PE_Typedef::On_afterName_Semicolon( const char * ) 130 { 131 SetTokenResult(done, pop_success); 132 } 133 134 } // namespace cpp 135 136 137 138