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_namsp.hxx>
24
25
26 // NOT FULLY DECLARED SERVICES
27 #include <all_toks.hxx>
28 #include <ary/cpp/c_namesp.hxx>
29 #include <ary/cpp/c_gate.hxx>
30 #include <ary/cpp/cp_ce.hxx>
31 #include <semantic/callf.hxx>
32 #include "x_parse.hxx"
33
34
35
36
37 namespace cpp
38 {
39
PE_Namespace(Cpp_PE * i_pParent)40 PE_Namespace::PE_Namespace( Cpp_PE * i_pParent )
41 : Cpp_PE(i_pParent),
42 pStati( new PeStatusArray<PE_Namespace> ),
43 // sLocalname
44 bPush(false)
45 {
46 Setup_StatusFunctions();
47 }
48
~PE_Namespace()49 PE_Namespace::~PE_Namespace()
50 {
51 }
52
53 void
Setup_StatusFunctions()54 PE_Namespace::Setup_StatusFunctions()
55 {
56 typedef CallFunction<PE_Namespace>::F_Tok F_Tok;
57 static F_Tok stateF_start[] = { &PE_Namespace::On_start_Identifier,
58 &PE_Namespace::On_start_SwBracket_Left };
59 static INT16 stateT_start[] = { Tid_Identifier,
60 Tid_SwBracket_Left };
61 static F_Tok stateF_gotName[] = { &PE_Namespace::On_gotName_SwBracket_Left,
62 &PE_Namespace::On_gotName_Assign };
63 static INT16 stateT_gotName[] = { Tid_SwBracket_Left,
64 Tid_Assign };
65 static F_Tok stateF_expectSemicolon[] = { &PE_Namespace::On_expectSemicolon_Semicolon };
66 static INT16 stateT_expectSemicolon[] = { Tid_Semicolon };
67
68 SEMPARSE_CREATE_STATUS(PE_Namespace, start, Hdl_SyntaxError);
69 SEMPARSE_CREATE_STATUS(PE_Namespace, gotName, Hdl_SyntaxError);
70 SEMPARSE_CREATE_STATUS(PE_Namespace, expectSemicolon, Hdl_SyntaxError);
71 }
72
73 void
Call_Handler(const cpp::Token & i_rTok)74 PE_Namespace::Call_Handler( const cpp::Token & i_rTok )
75 {
76 pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
77 }
78
79 void
InitData()80 PE_Namespace::InitData()
81 {
82 pStati->SetCur(start);
83 sLocalName = "";
84 bPush = false;
85 }
86
87 void
TransferData()88 PE_Namespace::TransferData()
89 {
90 if (bPush)
91 {
92 ary::cpp::Namespace &
93 rNew = Env().AryGate().Ces().CheckIn_Namespace(
94 Env().Context(),
95 sLocalName );
96 Env().OpenNamespace(rNew);
97 }
98 }
99
100 void
Hdl_SyntaxError(const char * i_sText)101 PE_Namespace::Hdl_SyntaxError( const char * i_sText)
102 {
103 throw X_Parser( X_Parser::x_UnexpectedToken,
104 i_sText != 0 ? i_sText : "",
105 Env().CurFileName(),
106 Env().LineCount() );
107 }
108
109 void
On_start_Identifier(const char * i_sText)110 PE_Namespace::On_start_Identifier(const char * i_sText)
111 {
112 SetTokenResult(done, stay);
113 pStati->SetCur(gotName);
114
115 sLocalName = i_sText;
116 }
117
118 void
On_start_SwBracket_Left(const char *)119 PE_Namespace::On_start_SwBracket_Left(const char * )
120 {
121 SetTokenResult(done, pop_success);
122 pStati->SetCur(size_of_states);
123
124 sLocalName = ""; // Anonymous namespace, a name is created in
125 // Gate().CheckIn_Namespace() .
126
127 bPush = true;
128 }
129
130 void
On_gotName_SwBracket_Left(const char *)131 PE_Namespace::On_gotName_SwBracket_Left(const char * )
132 {
133 SetTokenResult(done, pop_success);
134 pStati->SetCur(size_of_states);
135
136 bPush = true;
137 }
138
139 void
On_gotName_Assign(const char *)140 PE_Namespace::On_gotName_Assign(const char * )
141 {
142 // KORR_FUTURE
143 Hdl_SyntaxError(0);
144 }
145
146 void
On_expectSemicolon_Semicolon(const char *)147 PE_Namespace::On_expectSemicolon_Semicolon(const char * )
148 {
149 SetTokenResult(done,pop_success);
150 pStati->SetCur(size_of_states);
151 }
152
153 } // namespace cpp
154
155
156
157
158