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