1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #pragma once
20 
21 #include "idlctypes.hxx"
22 #include "aststack.hxx"
23 #include "options.hxx"
24 #include <memory>
25 #include <string_view>
26 
27 #ifdef SAL_UNX
28 #define SEPARATOR '/'
29 #define PATH_SEPARATOR "/"
30 #else
31 #define SEPARATOR '\\'
32 #define PATH_SEPARATOR "\\"
33 #endif
34 
35 class AstInterface;
36 class AstModule;
37 class AstType;
38 class Options;
39 class ErrorHandler;
40 
41 class Idlc final
42 {
43 public:
44     Idlc(Options* pOptions);
45     ~Idlc();
46 
47     void init();
48 
49     bool dumpDeps(std::string_view rDepFile,
50                   OString const& rTarget);
51 
getOptions()52     Options* getOptions()
53         { return m_pOptions; }
scopes()54     AstStack* scopes()
55         { return m_pScopes.get(); }
getRoot()56     AstModule* getRoot()
57         { return m_pRoot.get(); }
getFileName() const58     const OString& getFileName() const
59         { return m_fileName; }
setFileName(const OString & fileName)60     void setFileName(const OString& fileName)
61         { m_fileName = fileName; addInclude(fileName); }
getMainFileName() const62     const OString& getMainFileName() const
63         { return m_mainFileName; }
setMainFileName(const OString & mainFileName)64     void setMainFileName(const OString& mainFileName)
65         { m_mainFileName = mainFileName; }
getRealFileName() const66     const OString& getRealFileName() const
67         { return m_realFileName; }
setRealFileName(const OString & realFileName)68     void setRealFileName(const OString& realFileName)
69         { m_realFileName = realFileName; }
getDocumentation()70     const OString& getDocumentation()
71         {
72             m_bIsDocValid = false;
73             return m_documentation;
74         }
setDocumentation(const OString & documentation)75     void setDocumentation(const OString& documentation)
76         {
77             m_documentation = documentation;
78             m_bIsDocValid = true;
79         }
80     OUString processDocumentation();
isInMainFile() const81     bool isInMainFile() const
82         { return m_bIsInMainfile; }
setInMainfile(bool bInMainfile)83     void setInMainfile(bool bInMainfile)
84         { m_bIsInMainfile = bInMainfile; }
getErrorCount() const85     sal_uInt32 getErrorCount() const
86         { return m_errorCount; }
incErrorCount()87     void incErrorCount()
88         { m_errorCount++; }
getWarningCount() const89     sal_uInt32 getWarningCount() const
90         { return m_warningCount; }
incWarningCount()91     void incWarningCount()
92         { m_warningCount++; }
getLineNumber() const93     sal_uInt32 getLineNumber() const
94         { return m_lineNumber; }
getOffsetStart() const95     sal_uInt32 getOffsetStart() const
96         { return m_offsetStart; }
getOffsetEnd() const97     sal_uInt32 getOffsetEnd() const
98         { return m_offsetEnd; }
setOffset(sal_uInt32 start,sal_uInt32 end)99     void setOffset( sal_uInt32 start, sal_uInt32 end)
100         { m_offsetStart = start; m_offsetEnd = end; }
setLineNumber(sal_uInt32 lineNumber)101     void setLineNumber(sal_uInt32 lineNumber)
102         { m_lineNumber = lineNumber; }
incLineNumber()103     void incLineNumber()
104         { m_lineNumber++; }
getParseState() const105     ParseState getParseState() const
106         { return m_parseState; }
setParseState(ParseState parseState)107     void setParseState(ParseState parseState)
108         { m_parseState = parseState; }
109 
addInclude(const OString & inc)110     void addInclude(const OString& inc)
111         { m_includes.insert(inc); }
112 
setPublished(bool published)113     void setPublished(bool published) { m_published = published; }
isPublished() const114     bool isPublished() const { return m_published; }
115 
116     void reset();
117 private:
118     Options*            m_pOptions;
119     std::unique_ptr<AstStack>  m_pScopes;
120     std::unique_ptr<AstModule> m_pRoot;
121     OString      m_fileName;
122     OString      m_mainFileName;
123     OString      m_realFileName;
124     OString      m_documentation;
125     bool            m_bIsDocValid;
126     bool            m_bGenerateDoc;
127     bool            m_bIsInMainfile;
128     bool                m_published;
129     sal_uInt32          m_errorCount;
130     sal_uInt32          m_warningCount;
131     sal_uInt32          m_lineNumber;
132     sal_uInt32          m_offsetStart;
133     sal_uInt32          m_offsetEnd;
134     ParseState          m_parseState;
135     std::set< OString >           m_includes;
136 };
137 
138 
139 typedef ::std::pair< OString, OString > sPair_t;
140 sal_Int32 compileFile(const OString * pathname);
141     // a null pathname means stdin
142 sal_Int32 produceFile(const OString& filenameBase,
143         sPair_t const*const pDepFile);
144     // filenameBase is filename without ".idl"
145 void removeIfExists(std::string_view pathname);
146 
147 bool copyFile(const OString* source, const OString& target);
148     // a null source means stdin
149 
150 bool isFileUrl(const OString& fileName);
151 OString convertToAbsoluteSystemPath(const OString& fileName);
152 OString convertToFileUrl(const OString& fileName);
153 
154 Idlc* idlc();
155 Idlc* setIdlc(Options* pOptions);
156 
157 AstDeclaration const * resolveTypedefs(AstDeclaration const * type);
158 
159 AstDeclaration const * deconstructAndResolveTypedefs(
160     AstDeclaration const * type, sal_Int32 * rank);
161 
162 AstInterface const * resolveInterfaceTypedefs(AstType const * type);
163 
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
165