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