xref: /trunk/main/autodoc/source/parser/cpp/pe_defs.cxx (revision cdf0e10c)
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_defs.hxx"
30 
31 
32 // NOT FULLY DECLARED SERVICES
33 #include <cosv/tpl/tpltools.hxx>
34 #include <ary/cpp/c_gate.hxx>
35 #include <ary/cpp/c_define.hxx>
36 #include <ary/cpp/c_macro.hxx>
37 #include <ary/cpp/cp_def.hxx>
38 #include "all_toks.hxx"
39 
40 
41 namespace cpp
42 {
43 
44 
45 PE_Defines::PE_Defines( Cpp_PE * i_pParent )
46 	:   Cpp_PE(i_pParent),
47 		pStati( new PeStatusArray<PE_Defines> ),
48 	    // sName,
49         // aParameters,
50         // sDefinition,
51         bIsMacro(false)
52 {
53 	Setup_StatusFunctions();
54 }
55 
56 
57 PE_Defines::~PE_Defines()
58 {
59 }
60 
61 void
62 PE_Defines::Call_Handler( const cpp::Token & i_rTok )
63 {
64 	pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
65 }
66 
67 void
68 PE_Defines::Setup_StatusFunctions()
69 {
70 	typedef CallFunction<PE_Defines>::F_Tok	F_Tok;
71 	static F_Tok stateF_expectName[] = 		{ &PE_Defines::On_expectName_DefineName,
72                                               &PE_Defines::On_expectName_MacroName
73                                             };
74 	static INT16 stateT_expectName[] = 		{ Tid_DefineName,
75                                               Tid_MacroName
76                                             };
77 
78 	static F_Tok stateF_gotDefineName[] =   { &PE_Defines::On_gotDefineName_PreProDefinition };
79 	static INT16 stateT_gotDefineName[] =  	{ Tid_PreProDefinition };
80 
81 	static F_Tok stateF_expectMacroParameters[] =
82                                             { &PE_Defines::On_expectMacroParameters_MacroParameter,
83                                               &PE_Defines::On_expectMacroParameters_PreProDefinition
84                                             };
85 	static INT16 stateT_expectMacroParameters[] =
86                                            	{ Tid_MacroParameter,
87                                               Tid_PreProDefinition
88                                             };
89 
90 	SEMPARSE_CREATE_STATUS(PE_Defines, expectName, Hdl_SyntaxError);
91 	SEMPARSE_CREATE_STATUS(PE_Defines, gotDefineName, Hdl_SyntaxError);
92 	SEMPARSE_CREATE_STATUS(PE_Defines, expectMacroParameters, Hdl_SyntaxError);
93 }
94 
95 void
96 PE_Defines::InitData()
97 {
98 	pStati->SetCur(expectName);
99 
100 	sName.clear();
101     csv::erase_container( aParameters );
102     csv::erase_container( aDefinition );
103     bIsMacro = false;
104 }
105 
106 void
107 PE_Defines::TransferData()
108 {
109     if (NOT bIsMacro)
110     {
111         if (aDefinition.empty() OR aDefinition.front().empty())
112             return;
113 
114     	ary::cpp::Define &
115             rNew = Env().AryGate().Defs().Store_Define(
116                             Env().Context(), sName, aDefinition );
117         Env().Event_Store_CppDefinition(rNew);
118     }
119     else
120     {
121         ary::cpp::Macro &
122             rNew = Env().AryGate().Defs().Store_Macro(
123                             Env().Context(), sName, aParameters, aDefinition );
124         Env().Event_Store_CppDefinition(rNew);
125     }
126 	pStati->SetCur(size_of_states);
127 }
128 
129 void
130 PE_Defines::Hdl_SyntaxError( const char * i_sText)
131 {
132 	StdHandlingOfSyntaxError(i_sText);
133 }
134 
135 void
136 PE_Defines::On_expectName_DefineName( const char * i_sText )
137 {
138 	SetTokenResult(done, stay);
139 	pStati->SetCur(gotDefineName);
140 
141 	sName = i_sText;
142 	bIsMacro = false;
143 }
144 
145 void
146 PE_Defines::On_expectName_MacroName( const char * i_sText )
147 {
148 	SetTokenResult(done, stay);
149 	pStati->SetCur(expectMacroParameters);
150 
151 	sName = i_sText;
152 	bIsMacro = true;
153 }
154 
155 void
156 PE_Defines::On_gotDefineName_PreProDefinition( const char * i_sText )
157 {
158 	SetTokenResult(done, pop_success);
159 
160     aDefinition.push_back( String (i_sText) );
161 }
162 
163 void
164 PE_Defines::On_expectMacroParameters_MacroParameter( const char * i_sText )
165 {
166 	SetTokenResult(done, stay);
167     aParameters.push_back( String (i_sText) );
168 }
169 
170 void
171 PE_Defines::On_expectMacroParameters_PreProDefinition( const char * i_sText )
172 {
173 	SetTokenResult(done, pop_success);
174 
175     aDefinition.push_back( String (i_sText) );
176 }
177 
178 
179 }   // namespace cpp
180 
181