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_expr.hxx" 24 25 26 // NOT FULLY DECLARED SERVICES 27 28 29 namespace cpp { 30 31 32 33 PE_Expression::PE_Expression( Cpp_PE * i_pParent ) 34 : Cpp_PE(i_pParent), 35 pStati( new PeStatusArray<PE_Expression> ), 36 aResult_Text(100), 37 nBracketCounter(0) 38 { 39 Setup_StatusFunctions(); 40 } 41 42 43 PE_Expression::~PE_Expression() 44 { 45 } 46 47 void 48 PE_Expression::Call_Handler( const cpp::Token & i_rTok ) 49 { 50 pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text()); 51 52 #if 0 53 switch (i_rTok.TypeId()) 54 { 55 case Tid_SwBracket_Left: SetTokenResult(done, stay); 56 nBracketCounter++; 57 bBlockOpened = true; 58 break; 59 case Tid_SwBracket_Right: SetTokenResult(done, stay); 60 nBracketCounter--; 61 break; 62 case Tid_Semicolon: if (nBracketCounter == 0) 63 SetTokenResult(done, pop_success); 64 else 65 SetTokenResult(done, stay); 66 break; 67 default: 68 if ( bBlockOpened AND nBracketCounter == 0 ) 69 { 70 SetTokenResult(not_done, pop_success); 71 } 72 else 73 { 74 SetTokenResult(done, stay); 75 } 76 } // end switch 77 #endif // 0 78 } 79 80 void 81 PE_Expression::Setup_StatusFunctions() 82 { 83 typedef CallFunction<PE_Expression>::F_Tok F_Tok; 84 85 static F_Tok stateF_std[] = { &PE_Expression::On_std_SwBracket_Left, 86 &PE_Expression::On_std_SwBracket_Right, 87 &PE_Expression::On_std_ArrayBracket_Left, 88 &PE_Expression::On_std_ArrayBracket_Right, 89 &PE_Expression::On_std_Bracket_Left, 90 &PE_Expression::On_std_Bracket_Right, 91 &PE_Expression::On_std_Semicolon, 92 &PE_Expression::On_std_Comma }; 93 static INT16 stateT_std[] = { Tid_SwBracket_Left, 94 Tid_SwBracket_Right, 95 Tid_ArrayBracket_Left, 96 Tid_ArrayBracket_Right, 97 Tid_Bracket_Left, 98 Tid_Bracket_Right, 99 Tid_Semicolon, 100 Tid_Comma }; 101 102 SEMPARSE_CREATE_STATUS(PE_Expression, std, On_std_Default); 103 } 104 105 void 106 PE_Expression::InitData() 107 { 108 pStati->SetCur(std); 109 aResult_Text.seekp(0); 110 nBracketCounter = 0; 111 } 112 113 void 114 PE_Expression::TransferData() 115 { 116 pStati->SetCur(size_of_states); 117 if ( aResult_Text.tellp() > 0) 118 aResult_Text.pop_back(1); 119 } 120 121 void 122 PE_Expression::On_std_Default( const char * i_sText) 123 { 124 SetTokenResult(done, stay); 125 aResult_Text << i_sText << " "; 126 } 127 128 void 129 PE_Expression::On_std_SwBracket_Left( const char *) 130 { 131 SetTokenResult(done, stay); 132 nBracketCounter++; 133 } 134 135 void 136 PE_Expression::On_std_SwBracket_Right( const char *) 137 { 138 nBracketCounter--; 139 if ( nBracketCounter >= 0 ) 140 SetTokenResult(done, stay); 141 else 142 SetTokenResult(not_done, pop_success); 143 } 144 145 void 146 PE_Expression::On_std_ArrayBracket_Left( const char *) 147 { 148 SetTokenResult(done, stay); 149 nBracketCounter++; 150 } 151 152 void 153 PE_Expression::On_std_ArrayBracket_Right( const char *) 154 { 155 nBracketCounter--; 156 if ( nBracketCounter >= 0 ) 157 SetTokenResult(done, stay); 158 else 159 SetTokenResult(not_done, pop_success); 160 } 161 162 void 163 PE_Expression::On_std_Bracket_Left( const char *) 164 { 165 SetTokenResult(done, stay); 166 nBracketCounter++; 167 } 168 169 void 170 PE_Expression::On_std_Bracket_Right( const char *) 171 { 172 nBracketCounter--; 173 if ( nBracketCounter >= 0 ) 174 SetTokenResult(done, stay); 175 else 176 SetTokenResult(not_done, pop_success); 177 } 178 179 void 180 PE_Expression::On_std_Semicolon( const char *) 181 { 182 SetTokenResult(not_done, pop_success); 183 } 184 185 void 186 PE_Expression::On_std_Comma( const char *) 187 { 188 SetTokenResult(not_done, pop_success); 189 } 190 191 192 } // namespace cpp 193 194 195 196 197 198 199