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