1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pe_file.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include "pe_file.hxx"
34 // NOT FULLY DECLARED SERVICES
35 #include "pe_defs.hxx"
36 #include "pe_enum.hxx"
37 #include "pe_namsp.hxx"
38 #include "pe_tpltp.hxx"
39 #include "pe_tydef.hxx"
40 #include "pe_vafu.hxx"
41 #include "pe_ignor.hxx"
44 // NOT FULLY DECLARED SERVICES
50 PE_File::PE_File( cpp::PeEnvironment
& io_rEnv
)
53 pStati( new PeStatusArray
<PE_File
> ),
65 bWithinSingleExternC(false)
67 Setup_StatusFunctions();
69 pSpNamespace
= new SP_Namespace(*this);
70 pSpTypedef
= new SP_Typedef(*this);
71 pSpVarFunc
= new SP_VarFunc(*this);
72 pSpTemplate
= new SP_Template(*this);
73 pSpDefs
= new SP_Defines(*this);
74 pSpIgnore
= new SP_Ignore(*this);
76 pSpuNamespace
= new SPU_Namespace(*pSpNamespace
, 0, 0);
77 pSpuTypedef
= new SPU_Typedef(*pSpTypedef
, 0, 0);
78 pSpuVarFunc
= new SPU_VarFunc(*pSpVarFunc
, 0, &PE_File::SpReturn_VarFunc
);
79 pSpuTemplate
= new SPU_Template(*pSpTemplate
, 0, &PE_File::SpReturn_Template
);
80 pSpuDefs
= new SPU_Defines(*pSpDefs
, 0, 0);
81 pSpuUsing
= new SPU_Ignore(*pSpIgnore
, 0, 0);
83 = new SPU_Ignore(*pSpIgnore
, 0, 0);
91 PE_File::Call_Handler( const cpp::Token
& i_rTok
)
93 pStati
->Cur().Call_Handler(i_rTok
.TypeId(), i_rTok
.Text());
97 PE_File::Handle_ChildFailure()
99 SetCurSPU(pSpuIgnoreFailure
.Ptr());
100 return &pSpuIgnoreFailure
->Child();
104 PE_File::Setup_StatusFunctions()
106 typedef CallFunction
<PE_File
>::F_Tok F_Tok
;
107 static F_Tok stateF_std
[] = { &PE_File::On_std_VarFunc
,
108 &PE_File::On_std_ClassKey
,
109 &PE_File::On_std_ClassKey
,
110 &PE_File::On_std_ClassKey
,
111 &PE_File::On_std_enum
,
113 &PE_File::On_std_typedef
,
114 &PE_File::On_std_template
,
115 &PE_File::On_std_VarFunc
,
116 &PE_File::On_std_VarFunc
,
117 &PE_File::On_std_extern
,
119 &PE_File::On_std_VarFunc
,
120 &PE_File::On_std_VarFunc
,
121 &PE_File::On_std_VarFunc
,
122 &PE_File::On_std_namespace
,
123 &PE_File::On_std_using
,
125 &PE_File::On_std_SwBracketRight
,
126 &PE_File::On_std_VarFunc
,
127 &PE_File::On_std_VarFunc
,
128 &PE_File::On_std_DefineName
,
129 &PE_File::On_std_MacroName
,
131 &PE_File::On_std_VarFunc
,
132 &PE_File::On_std_VarFunc
};
134 static INT16 stateT_std
[] = { Tid_Identifier
,
159 Tid_TypeSpecializer
};
161 static F_Tok stateF_in_extern
[] = { &PE_File::On_in_extern_Constant
};
162 static INT16 stateT_in_extern
[] = { Tid_Constant
};
164 static F_Tok stateF_in_externC
[] = { &PE_File::On_in_externC_SwBracket_Left
};
165 static INT16 stateT_in_externC
[] = { Tid_SwBracket_Left
};
168 SEMPARSE_CREATE_STATUS(PE_File
, std
, Hdl_SyntaxError
);
169 SEMPARSE_CREATE_STATUS(PE_File
, in_extern
, On_in_extern_Ignore
);
170 SEMPARSE_CREATE_STATUS(PE_File
, in_externC
, On_in_externC_NoBlock
);
180 PE_File::TransferData()
182 pStati
->SetCur(size_of_states
);
186 PE_File::Hdl_SyntaxError( const char * i_sText
)
188 if ( *i_sText
== ';' )
190 Cerr() << Env().CurFileName() << ", line "
192 << ": Sourcecode warning: ';' as a toplevel declaration is deprecated."
194 SetTokenResult(done
,stay
);
198 StdHandlingOfSyntaxError(i_sText
);
202 PE_File::SpReturn_VarFunc()
204 if (bWithinSingleExternC
)
206 access_Env().CloseBlock();
207 bWithinSingleExternC
= false;
212 PE_File::SpReturn_Template()
214 access_Env().OpenTemplate( pSpuTemplate
->Child().Result_Parameters() );
218 PE_File::On_std_namespace(const char * )
220 pSpuNamespace
->Push(done
);
224 PE_File::On_std_ClassKey(const char * )
226 pSpuVarFunc
->Push(not_done
); // This is correct,
227 // classes are parsed via PE_Type.
231 PE_File::On_std_typedef(const char * )
233 pSpuTypedef
->Push(not_done
);
237 PE_File::On_std_enum(const char * )
239 pSpuVarFunc
->Push(not_done
); // This is correct,
240 // enums are parsed via PE_Type.
244 PE_File::On_std_VarFunc(const char * )
246 pSpuVarFunc
->Push(not_done
);
250 PE_File::On_std_template(const char * )
252 pSpuTemplate
->Push(done
);
256 PE_File::On_std_extern(const char * )
258 SetTokenResult(done
, stay
);
259 pStati
->SetCur(in_extern
);
263 PE_File::On_std_using(const char * )
265 pSpuUsing
->Push(done
);
269 PE_File::On_std_SwBracketRight(const char * )
271 SetTokenResult(done
,stay
);
272 access_Env().CloseBlock();
276 PE_File::On_std_DefineName(const char * )
278 pSpuDefs
->Push(not_done
);
282 PE_File::On_std_MacroName(const char * )
284 pSpuDefs
->Push(not_done
);
288 PE_File::On_in_extern_Constant(const char * )
290 SetTokenResult(done
,stay
);
291 pStati
->SetCur(in_externC
);
293 access_Env().OpenExternC();
297 PE_File::On_in_extern_Ignore(const char * )
299 SetTokenResult(not_done
, stay
);
304 PE_File::On_in_externC_SwBracket_Left(const char * )
306 SetTokenResult(done
, stay
);
311 PE_File::On_in_externC_NoBlock(const char * )
313 SetTokenResult(not_done
, stay
);
316 bWithinSingleExternC
= true;