xref: /trunk/main/autodoc/source/parser/cpp/c_rcode.cxx (revision 78bc99aa)
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 "c_rcode.hxx"
24 
25 
26 // NOT FULLY DECLARED SERVICES
27 #include <ary/cpp/c_gate.hxx>
28 #include <ary/cpp/c_namesp.hxx>
29 // #include <ary/cpp/c_groups.hxx>
30 #include <ary/loc/locp_le.hxx>
31 #include "cpp_pe.hxx"
32 #include <adc_cl.hxx>
33 #include <x_parse.hxx>
34 #include "pe_file.hxx"
35 
36 const uintt	C_nNO_TRY = uintt(-1);
37 
38 
39 namespace cpp {
40 
41 
CodeExplorer(ary::cpp::Gate & io_rAryGate)42 CodeExplorer::CodeExplorer( ary::cpp::Gate & io_rAryGate )
43 	:   aGlobalParseContext(io_rAryGate),
44         // aEnvironments,
45         pPE_File(0),
46         pGate(&io_rAryGate),
47 		dpCurToken(0)
48 {
49 	pPE_File = new PE_File( aGlobalParseContext );
50 }
51 
~CodeExplorer()52 CodeExplorer::~CodeExplorer()
53 {
54 }
55 
56 void
StartNewFile()57 CodeExplorer::StartNewFile()
58 {
59 	csv::erase_container(aEnvironments);
60 
61 	aEnvironments.push_back( pPE_File.MutablePtr() );
62     pPE_File->Enter(push);
63 }
64 
65 void
Process_Token(DYN cpp::Token & let_drToken)66 CodeExplorer::Process_Token( DYN cpp::Token & let_drToken )
67 {
68 if (DEBUG_ShowTokens())
69 {
70 	Cout() << let_drToken.Text() << Endl();
71 }
72 	dpCurToken = &let_drToken;
73 	aGlobalParseContext.ResetResult();
74 
75 	do {
76 		CurToken().Trigger( CurEnv() );
77 		AcknowledgeResult();
78 	} while ( dpCurToken );
79 }
80 
81 void
AcknowledgeResult()82 CodeExplorer::AcknowledgeResult()
83 {
84 	if (CurResult().eDone == done)
85 		dpCurToken = 0;
86 
87 	switch ( CurResult().eStackAction )
88 	{
89 		case stay:
90 				break;
91 		case push:
92 				CurEnv().Leave(push);
93 				aEnvironments.push_back( &PushEnv() );
94 				PushEnv().Enter(push);
95 				break;
96 		case pop_success:
97 				CurEnv().Leave(pop_success);
98 				aEnvironments.pop_back();
99 				CurEnv().Enter(pop_success);
100 				break;
101 		case pop_failure:
102 		{
103                 Cpp_PE * pRecover = 0;
104                 do {
105                     CurEnv().Leave(pop_failure);
106         			aEnvironments.pop_back();
107                     if ( aEnvironments.empty() )
108                         break;
109                     pRecover = CurEnv().Handle_ChildFailure();
110                 } while ( pRecover == 0 );
111                 if ( pRecover != 0 )
112                 {
113                     aEnvironments.push_back(pRecover);
114                     pRecover->Enter(push);
115                 }
116                 else
117                 {
118     				throw X_Parser( X_Parser::x_UnexpectedToken, CurToken().Text(), aGlobalParseContext.CurFileName(), aGlobalParseContext.LineCount() );
119                 }
120 		}		break;
121 		default:
122 			csv_assert(false);
123 	}	// end switch(CurResult().eStackAction)
124 }
125 
126 const Token &
CurToken() const127 CodeExplorer::CurToken() const
128 {
129 	csv_assert(dpCurToken);
130 
131 	return *dpCurToken;
132 }
133 
134 Cpp_PE &
CurEnv() const135 CodeExplorer::CurEnv() const
136 {
137 	csv_assert(aEnvironments.size() > 0);
138 	csv_assert(aEnvironments.back() != 0);
139 
140 	return *aEnvironments.back();
141 }
142 
143 Cpp_PE &
PushEnv() const144 CodeExplorer::PushEnv() const
145 {
146     TokenProcessing_Result & rCurResult = const_cast< TokenProcessing_Result& >(aGlobalParseContext.CurResult());
147 	Cpp_PE * ret = dynamic_cast< Cpp_PE* >(rCurResult.pEnv2Push);
148 	csv_assert( ret != 0 );
149 	return *ret;
150 }
151 
152 
153 
154 }   // namespace cpp
155 
156