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_file.hxx" 30 31 // NOT FULLY DECLARED SERVICES 32 #include "pe_defs.hxx" 33 #include "pe_enum.hxx" 34 #include "pe_namsp.hxx" 35 #include "pe_tpltp.hxx" 36 #include "pe_tydef.hxx" 37 #include "pe_vafu.hxx" 38 #include "pe_ignor.hxx" 39 40 41 // NOT FULLY DECLARED SERVICES 42 43 44 namespace cpp 45 { 46 47 PE_File::PE_File( cpp::PeEnvironment & io_rEnv) 48 : Cpp_PE(io_rEnv), 49 pEnv(&io_rEnv), 50 pStati( new PeStatusArray<PE_File> ), 51 // pSpNamespace, 52 // pSpTypedef, 53 // pSpVarFunc, 54 // pSpIgnore, 55 // pSpuNamespace, 56 // pSpuClass, 57 // pSpuTypedef, 58 // pSpuVarFunc, 59 // pSpuTemplate, 60 // pSpuUsing, 61 // pSpuIgnoreFailure, 62 bWithinSingleExternC(false) 63 { 64 Setup_StatusFunctions(); 65 66 pSpNamespace = new SP_Namespace(*this); 67 pSpTypedef = new SP_Typedef(*this); 68 pSpVarFunc = new SP_VarFunc(*this); 69 pSpTemplate = new SP_Template(*this); 70 pSpDefs = new SP_Defines(*this); 71 pSpIgnore = new SP_Ignore(*this); 72 73 pSpuNamespace = new SPU_Namespace(*pSpNamespace, 0, 0); 74 pSpuTypedef = new SPU_Typedef(*pSpTypedef, 0, 0); 75 pSpuVarFunc = new SPU_VarFunc(*pSpVarFunc, 0, &PE_File::SpReturn_VarFunc); 76 pSpuTemplate = new SPU_Template(*pSpTemplate, 0, &PE_File::SpReturn_Template); 77 pSpuDefs = new SPU_Defines(*pSpDefs, 0, 0); 78 pSpuUsing = new SPU_Ignore(*pSpIgnore, 0, 0); 79 pSpuIgnoreFailure 80 = new SPU_Ignore(*pSpIgnore, 0, 0); 81 } 82 83 PE_File::~PE_File() 84 { 85 } 86 87 void 88 PE_File::Call_Handler( const cpp::Token & i_rTok ) 89 { 90 pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text()); 91 } 92 93 Cpp_PE * 94 PE_File::Handle_ChildFailure() 95 { 96 SetCurSPU(pSpuIgnoreFailure.Ptr()); 97 return &pSpuIgnoreFailure->Child(); 98 } 99 100 void 101 PE_File::Setup_StatusFunctions() 102 { 103 typedef CallFunction<PE_File>::F_Tok F_Tok; 104 static F_Tok stateF_std[] = { &PE_File::On_std_VarFunc, 105 &PE_File::On_std_ClassKey, 106 &PE_File::On_std_ClassKey, 107 &PE_File::On_std_ClassKey, 108 &PE_File::On_std_enum, 109 110 &PE_File::On_std_typedef, 111 &PE_File::On_std_template, 112 &PE_File::On_std_VarFunc, 113 &PE_File::On_std_VarFunc, 114 &PE_File::On_std_extern, 115 116 &PE_File::On_std_VarFunc, 117 &PE_File::On_std_VarFunc, 118 &PE_File::On_std_VarFunc, 119 &PE_File::On_std_namespace, 120 &PE_File::On_std_using, 121 122 &PE_File::On_std_SwBracketRight, 123 &PE_File::On_std_VarFunc, 124 &PE_File::On_std_VarFunc, 125 &PE_File::On_std_DefineName, 126 &PE_File::On_std_MacroName, 127 128 &PE_File::On_std_VarFunc, 129 &PE_File::On_std_VarFunc }; 130 131 static INT16 stateT_std[] = { Tid_Identifier, 132 Tid_class, 133 Tid_struct, 134 Tid_union, 135 Tid_enum, 136 137 Tid_typedef, 138 Tid_template, 139 Tid_const, 140 Tid_volatile, 141 Tid_extern, 142 143 Tid_static, 144 Tid_register, 145 Tid_inline, 146 Tid_namespace, 147 Tid_using, 148 149 Tid_SwBracket_Right, 150 Tid_DoubleColon, 151 Tid_typename, 152 Tid_DefineName, 153 Tid_MacroName, 154 155 Tid_BuiltInType, 156 Tid_TypeSpecializer }; 157 158 static F_Tok stateF_in_extern[] = { &PE_File::On_in_extern_Constant }; 159 static INT16 stateT_in_extern[] = { Tid_Constant }; 160 161 static F_Tok stateF_in_externC[] = { &PE_File::On_in_externC_SwBracket_Left }; 162 static INT16 stateT_in_externC[] = { Tid_SwBracket_Left }; 163 164 165 SEMPARSE_CREATE_STATUS(PE_File, std, Hdl_SyntaxError); 166 SEMPARSE_CREATE_STATUS(PE_File, in_extern, On_in_extern_Ignore); 167 SEMPARSE_CREATE_STATUS(PE_File, in_externC, On_in_externC_NoBlock); 168 } 169 170 void 171 PE_File::InitData() 172 { 173 pStati->SetCur(std); 174 } 175 176 void 177 PE_File::TransferData() 178 { 179 pStati->SetCur(size_of_states); 180 } 181 182 void 183 PE_File::Hdl_SyntaxError( const char * i_sText) 184 { 185 if ( *i_sText == ';' ) 186 { 187 Cerr() << Env().CurFileName() << ", line " 188 << Env().LineCount() 189 << ": Sourcecode warning: ';' as a toplevel declaration is deprecated." 190 << Endl(); 191 SetTokenResult(done,stay); 192 return; 193 } 194 195 StdHandlingOfSyntaxError(i_sText); 196 } 197 198 void 199 PE_File::SpReturn_VarFunc() 200 { 201 if (bWithinSingleExternC) 202 { 203 access_Env().CloseBlock(); 204 bWithinSingleExternC = false; 205 } 206 } 207 208 void 209 PE_File::SpReturn_Template() 210 { 211 access_Env().OpenTemplate( pSpuTemplate->Child().Result_Parameters() ); 212 } 213 214 void 215 PE_File::On_std_namespace(const char * ) 216 { 217 pSpuNamespace->Push(done); 218 } 219 220 void 221 PE_File::On_std_ClassKey(const char * ) 222 { 223 pSpuVarFunc->Push(not_done); // This is correct, 224 // classes are parsed via PE_Type. 225 } 226 227 void 228 PE_File::On_std_typedef(const char * ) 229 { 230 pSpuTypedef->Push(not_done); 231 } 232 233 void 234 PE_File::On_std_enum(const char * ) 235 { 236 pSpuVarFunc->Push(not_done); // This is correct, 237 // enums are parsed via PE_Type. 238 } 239 240 void 241 PE_File::On_std_VarFunc(const char * ) 242 { 243 pSpuVarFunc->Push(not_done); 244 } 245 246 void 247 PE_File::On_std_template(const char * ) 248 { 249 pSpuTemplate->Push(done); 250 } 251 252 void 253 PE_File::On_std_extern(const char * ) 254 { 255 SetTokenResult(done, stay); 256 pStati->SetCur(in_extern); 257 } 258 259 void 260 PE_File::On_std_using(const char * ) 261 { 262 pSpuUsing->Push(done); 263 } 264 265 void 266 PE_File::On_std_SwBracketRight(const char * ) 267 { 268 SetTokenResult(done,stay); 269 access_Env().CloseBlock(); 270 } 271 272 void 273 PE_File::On_std_DefineName(const char * ) 274 { 275 pSpuDefs->Push(not_done); 276 } 277 278 void 279 PE_File::On_std_MacroName(const char * ) 280 { 281 pSpuDefs->Push(not_done); 282 } 283 284 void 285 PE_File::On_in_extern_Constant(const char * ) 286 { 287 SetTokenResult(done,stay); 288 pStati->SetCur(in_externC); 289 290 access_Env().OpenExternC(); 291 } 292 293 void 294 PE_File::On_in_extern_Ignore(const char * ) 295 { 296 SetTokenResult(not_done, stay); 297 pStati->SetCur(std); 298 } 299 300 void 301 PE_File::On_in_externC_SwBracket_Left(const char * ) 302 { 303 SetTokenResult(done, stay); 304 pStati->SetCur(std); 305 } 306 307 void 308 PE_File::On_in_externC_NoBlock(const char * ) 309 { 310 SetTokenResult(not_done, stay); 311 pStati->SetCur(std); 312 313 bWithinSingleExternC = true; 314 } 315 316 317 } // namespace cpp 318