xref: /AOO41X/main/autodoc/source/parser_i/idl/unoidl.cxx (revision 78bc99aafea97f4987aed12e674c2d2f1166dd91)
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 <parser/unoidl.hxx>
24 
25 
26 // NOT FULLY DECLARED SERVICES
27 #include <stdlib.h>
28 #include <cosv/file.hxx>
29 #include <ary/ary.hxx>
30 #include <ary/idl/i_gate.hxx>
31 #include <ary/doc/d_oldidldocu.hxx>
32 #include <../parser/inc/x_docu.hxx>
33 #include <parser/parserinfo.hxx>
34 #include <tools/filecoll.hxx>
35 #include <tools/tkpchars.hxx>
36 #include <s2_luidl/tkp_uidl.hxx>
37 #include <s2_luidl/distrib.hxx>
38 #include <s2_luidl/pe_file2.hxx>
39 #include <s2_dsapi/cx_dsapi.hxx>
40 #include <adc_msg.hxx>
41 #include <x_parse2.hxx>
42 
43 
44 
45 namespace autodoc
46 {
47 
48 
49 class FileParsePerformers
50 {
51   public:
52                         FileParsePerformers(
53                             ary::Repository &
54                                                 io_rRepository,
55                             ParserInfo &        io_rParserInfo );
56 
57     void                ParseFile(
58                             const char *        i_sFullPath );
59 
60     void                ConnectLinks();
61 
62   private:
63     CharacterSource     aFileLoader;
64     Dyn<csi::uidl::TokenParser_Uidl>
65                         pTokens;
66     csi::uidl::TokenDistributor
67                         aDistributor;
68     Dyn<csi::uidl::PE_File>
69                         pFileParseEnvironment;
70     ary::Repository &
71                         rRepository;
72     ParserInfo &        rParserInfo;
73 };
74 
75 
IdlParser(ary::Repository & io_rRepository)76 IdlParser::IdlParser( ary::Repository & io_rRepository )
77     :   pRepository(&io_rRepository)
78 {
79 }
80 
81 void
Run(const autodoc::FileCollector_Ifc & i_rFiles)82 IdlParser::Run( const autodoc::FileCollector_Ifc & i_rFiles )
83 {
84     Dyn<FileParsePerformers>
85         pFileParsePerformers(
86             new FileParsePerformers(*pRepository,
87                                     static_cast< ParserInfo& >(*this)) );
88 
89     FileCollector::const_iterator iEnd = i_rFiles.End();
90     for ( FileCollector::const_iterator iter = i_rFiles.Begin();
91           iter != iEnd;
92           ++iter )
93     {
94         Cout() << (*iter) << " ..."<< Endl();
95 
96         try
97         {
98             pFileParsePerformers->ParseFile(*iter);
99         }
100         catch (X_AutodocParser &)
101         {
102             /// Ignore and goon
103             TheMessages().Out_ParseError(CurFile(), CurLine());
104             pFileParsePerformers
105                 = new FileParsePerformers(*pRepository,
106                                           static_cast< ParserInfo& >(*this));
107         }
108         catch (X_Docu & xd)
109         {
110             // Currently thic catches only wrong since tags, while since tags are
111             // transformed. In this case the program shall be terminated.
112             Cerr() << xd << Endl();
113             exit(1);
114         }
115         catch (...)
116         {
117             Cout() << "Unknown error." << Endl();
118             exit(0);
119 //          pFileParsePerformers = new FileParsePerformers( *pRepository );
120         }
121     }
122 
123     pFileParsePerformers->ConnectLinks();
124 }
125 
FileParsePerformers(ary::Repository & io_rRepository,ParserInfo & io_rParserInfo)126 FileParsePerformers::FileParsePerformers( ary::Repository & io_rRepository,
127                                           ParserInfo &           io_rParserInfo )
128     :   pTokens(0),
129         aDistributor(io_rRepository, io_rParserInfo),
130         rRepository( io_rRepository ),
131         rParserInfo(io_rParserInfo)
132 {
133     DYN csi::dsapi::Context_Docu *
134         dpDocuContext
135             = new csi::dsapi::Context_Docu( aDistributor.DocuTokens_Receiver() );
136     pTokens = new csi::uidl::TokenParser_Uidl( aDistributor.CodeTokens_Receiver(), *dpDocuContext );
137     pFileParseEnvironment
138             = new csi::uidl::PE_File(aDistributor,rParserInfo);
139 
140     aDistributor.SetTokenProvider(*pTokens);
141     aDistributor.SetTopParseEnvironment(*pFileParseEnvironment);
142 }
143 
144 void
ParseFile(const char * i_sFullPath)145 FileParsePerformers::ParseFile( const char * i_sFullPath )
146 {
147     csv::File aFile(i_sFullPath);
148 
149     aFile.open( csv::CFM_READ );
150     csv_assert( aFile.is_open() );
151     aFileLoader.LoadText(aFile);
152     aFile.close();
153 
154     rParserInfo.Set_CurFile(i_sFullPath, true); // true = count lines
155     pTokens->Start(aFileLoader);
156     aDistributor.Reset();
157 
158     do {
159         aDistributor.TradeToken();
160     } while ( NOT aFileLoader.IsFinished() );
161 }
162 
163 void
ConnectLinks()164 FileParsePerformers::ConnectLinks()
165 {
166     // KORR_FUTURE ?
167 //  rRepository.RwGate_Idl().ConnectAdditionalLinks();
168 }
169 
170 }   // namespace autodoc
171