Updated core
[LibreOffice.git] / autodoc / source / parser_i / idl / distrib.cxx
blobcff100993ad2d110ce74c06402a4a5e2ee5e14a2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <precomp.h>
21 #include <s2_luidl/distrib.hxx>
24 // NOT FULLY DECLARED SERVICES
25 #include <ary/doc/d_oldidldocu.hxx>
26 #include <parser/parserinfo.hxx>
27 #include <s2_luidl/tkp_uidl.hxx>
28 #include <s2_luidl/parsenv2.hxx>
29 #include <s2_luidl/tk_punct.hxx>
30 #include <s2_dsapi/docu_pe2.hxx>
31 #include <adc_cl.hxx>
32 #include <x_parse2.hxx>
36 const uintt C_nNO_TRY = uintt(-1);
39 namespace csi
41 namespace uidl
44 TokenDistributor::TokenDistributor( ary::Repository & io_rRepository,
45 ParserInfo & io_rParserInfo )
46 : pTokenSource(0),
47 aDocumentation(io_rParserInfo),
48 aProcessingData( io_rRepository, aDocumentation, io_rParserInfo )
52 TokenDistributor::~TokenDistributor()
56 void
57 TokenDistributor::TradeToken()
59 bool bGoon = true;
60 while (bGoon AND NOT aProcessingData.NextTokenExists())
62 bGoon = pTokenSource->GetNextToken();
64 if (bGoon)
65 aProcessingData.ProcessCurToken();
68 TokenDistributor::ProcessingData::ProcessingData(
69 ary::Repository & io_rRepository,
70 Documentation & i_rDocuProcessor,
71 ParserInfo & io_rParserInfo )
72 : // aEnvironments
73 // aTokenQueue
74 // itCurToken
75 // aCurResult
76 nTryCount(0),
77 rRepository(io_rRepository),
78 rParserInfo(io_rParserInfo),
79 pDocuProcessor(&i_rDocuProcessor),
80 bPublishedRecentlyOn(false)
82 itCurToken = aTokenQueue.end();
85 TokenDistributor::ProcessingData::~ProcessingData()
89 void
90 TokenDistributor::ProcessingData::SetTopParseEnvironment( UnoIDL_PE & io_pTopParseEnvironment )
92 csv::erase_container(aEnvironments);
93 aEnvironments.push_back( EnvironmentInfo( &io_pTopParseEnvironment, 0 ) );
94 io_pTopParseEnvironment.EstablishContacts(0,rRepository,aCurResult);
97 void
98 TokenDistributor::ProcessingData::Receive( DYN csi::uidl::Token & let_drToken )
100 aTokenQueue.push_back( &let_drToken );
101 itCurToken = aTokenQueue.end()-1;
104 void
105 TokenDistributor::ProcessingData::Increment_CurLine()
107 rParserInfo.Increment_CurLine();
110 void
111 TokenDistributor::ProcessingData::ProcessCurToken()
114 if (DEBUG_ShowTokens())
116 Cout() << (*itCurToken)->Text() << Endl();
119 aCurResult.reset();
121 CurEnvironment().ProcessToken( CurToken() );
122 AcknowledgeResult();
126 UnoIDL_PE &
127 TokenDistributor::ProcessingData::CurEnvironment() const
129 csv_assert(aEnvironments.size() > 0);
130 csv_assert(aEnvironments.back().first != 0);
132 return *aEnvironments.back().first;
135 bool
136 TokenDistributor::ProcessingData::NextTokenExists() const
138 return itCurToken != aTokenQueue.end();
141 void
142 TokenDistributor::ProcessingData::AcknowledgeResult()
144 if (aCurResult.eDone == done)
145 ++itCurToken;
147 switch ( aCurResult.eStackAction )
149 case stay:
150 if (aCurResult.eDone != done)
152 csv_assert(false);
154 break;
155 case push_sure:
156 CurEnv().Leave(push_sure);
157 aEnvironments.push_back( EnvironmentInfo(&PushEnv(), C_nNO_TRY) );
158 PushEnv().Enter(push_sure);
159 PushEnv().SetDocu(pDocuProcessor->ReleaseLastParsedDocu());
160 if (bPublishedRecentlyOn)
162 PushEnv().SetPublished();
163 bPublishedRecentlyOn = false;
166 break;
167 case push_try:
168 Cout() << "TestInfo: Environment tried." << Endl();
169 CurEnv().Leave(push_try);
170 aEnvironments.push_back( EnvironmentInfo(&PushEnv(), CurTokenPosition()) );
171 nTryCount++;
172 PushEnv().Enter(push_try);
173 break;
174 case pop_success:
175 CurEnv().Leave(pop_success);
176 if ( CurEnv_TriedTokenPosition() > 0 )
177 DecrementTryCount();
178 aEnvironments.pop_back();
179 CurEnv().Enter(pop_success);
180 break;
181 case pop_failure:
183 CurEnv().Leave(pop_failure);
184 if (aCurResult.eDone == done)
186 csv_assert(false);
189 if ( CurEnv_TriedTokenPosition() == C_nNO_TRY )
190 throw X_AutodocParser( X_AutodocParser::x_UnexpectedToken, (*itCurToken)->Text() );
192 itCurToken = aTokenQueue.begin() + CurEnv_TriedTokenPosition();
193 DecrementTryCount();
194 aEnvironments.pop_back();
195 CurEnv().Enter(pop_failure);
196 } break;
197 default:
198 csv_assert(false);
199 } // end switch(aCurResult.eStackAction)
202 void
203 TokenDistributor::ProcessingData::DecrementTryCount()
205 nTryCount--;
206 if (nTryCount == 0)
208 aTokenQueue.erase(aTokenQueue.begin(), itCurToken);
209 itCurToken = aTokenQueue.begin();
213 TokenDistributor::
214 Documentation::Documentation(ParserInfo & io_rParserInfo)
215 : pDocuParseEnv(new csi::dsapi::SapiDocu_PE(io_rParserInfo)),
216 rParserInfo(io_rParserInfo),
217 pMostRecentDocu(0),
218 bIsPassedFirstDocu(false)
222 TokenDistributor::
223 Documentation::~Documentation()
227 void
228 TokenDistributor::
229 Documentation::Receive( DYN csi::dsapi::Token & let_drToken )
231 csv_assert(pDocuParseEnv);
233 pDocuParseEnv->ProcessToken(let_drToken);
234 if ( pDocuParseEnv->IsComplete() )
236 pMostRecentDocu = pDocuParseEnv->ReleaseJustParsedDocu();
237 if (NOT bIsPassedFirstDocu)
239 pMostRecentDocu = 0; // Deletes the most recent docu.
240 bIsPassedFirstDocu = true;
245 void
246 TokenDistributor::
247 Documentation::Increment_CurLine()
249 rParserInfo.Increment_CurLine();
253 } // namespace uidl
254 } // namespace csi
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */