1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: idlc.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_idlc.hxx"
33 #include <idlc/idlc.hxx>
34 #include <idlc/errorhandler.hxx>
35 #include <idlc/astscope.hxx>
36 #include <idlc/astmodule.hxx>
37 #include <idlc/astservice.hxx>
38 #include <idlc/astconstants.hxx>
39 #include <idlc/astexception.hxx>
40 #include <idlc/astunion.hxx>
41 #include <idlc/astenum.hxx>
42 #include <idlc/astinterface.hxx>
43 #include <idlc/astoperation.hxx>
44 #include <idlc/astbasetype.hxx>
45 #include "idlc/astdeclaration.hxx"
46 #include "idlc/astparameter.hxx"
47 #include "idlc/astsequence.hxx"
48 #include "idlc/asttype.hxx"
49 #include "idlc/asttypedef.hxx"
51 #include "osl/diagnose.h"
53 using namespace ::rtl
;
55 AstDeclaration
* SAL_CALL
scopeAsDecl(AstScope
* pScope
)
57 if (pScope
== NULL
) return NULL
;
59 switch( pScope
->getScopeNodeType() )
63 return (AstService
*)(pScope
);
66 return (AstModule
*)(pScope
);
68 return (AstConstants
*)(pScope
);
70 return (AstInterface
*)(pScope
);
72 return (AstOperation
*)(pScope
);
74 return (AstException
*)(pScope
);
76 return (AstUnion
*)(pScope
);
78 return (AstStruct
*)(pScope
);
80 return (AstEnum
*)(pScope
);
86 AstScope
* SAL_CALL
declAsScope(AstDeclaration
* pDecl
)
88 if (pDecl
== NULL
) return NULL
;
90 switch(pDecl
->getNodeType())
93 return (AstInterface
*)(pDecl
);
96 return (AstService
*)(pDecl
);
99 return (AstModule
*)(pDecl
);
101 return (AstConstants
*)(pDecl
);
103 return (AstException
*)(pDecl
);
105 return (AstUnion
*)(pDecl
);
107 return (AstStruct
*)(pDecl
);
109 return (AstEnum
*)(pDecl
);
111 return (AstOperation
*)(pDecl
);
117 static void SAL_CALL
predefineXInterface(AstModule
* pRoot
)
119 // define the modules com::sun::star::uno
120 AstModule
* pParentScope
= pRoot
;
121 AstModule
* pModule
= new AstModule(OString("com"), pParentScope
);
122 pModule
->setPredefined(true);
123 pParentScope
->addDeclaration(pModule
);
124 pParentScope
= pModule
;
125 pModule
= new AstModule(OString("sun"), pParentScope
);
126 pModule
->setPredefined(true);
127 pParentScope
->addDeclaration(pModule
);
128 pParentScope
= pModule
;
129 pModule
= new AstModule(OString("star"), pParentScope
);
130 pModule
->setPredefined(true);
131 pParentScope
->addDeclaration(pModule
);
132 pParentScope
= pModule
;
133 pModule
= new AstModule(OString("uno"), pParentScope
);
134 pModule
->setPredefined(true);
135 pParentScope
->addDeclaration(pModule
);
136 pParentScope
= pModule
;
139 AstInterface
* pInterface
= new AstInterface(OString("XInterface"), NULL
, pParentScope
);
140 pInterface
->setDefined();
141 pInterface
->setPredefined(true);
142 pInterface
->setPublished();
143 pParentScope
->addDeclaration(pInterface
);
145 // define XInterface::queryInterface
146 AstOperation
* pOp
= new AstOperation(0, (AstType
*)(pRoot
->lookupPrimitiveType(ET_any
)),
147 OString("queryInterface"), pInterface
);
148 AstParameter
* pParam
= new AstParameter(DIR_IN
, false,
149 (AstType
*)(pRoot
->lookupPrimitiveType(ET_type
)),
150 OString("aType"), pOp
);
151 pOp
->addDeclaration(pParam
);
152 pInterface
->addMember(pOp
);
154 // define XInterface::acquire
155 pOp
= new AstOperation(1, (AstType
*)(pRoot
->lookupPrimitiveType(ET_void
)),
156 OString("acquire"), pInterface
);
157 pInterface
->addMember(pOp
);
159 // define XInterface::release
160 pOp
= new AstOperation(1, (AstType
*)(pRoot
->lookupPrimitiveType(ET_void
)),
161 OString("release"), pInterface
);
162 pInterface
->addMember(pOp
);
165 static void SAL_CALL
initializePredefinedTypes(AstModule
* pRoot
)
167 AstBaseType
* pPredefined
= NULL
;
170 pPredefined
= new AstBaseType(ET_long
, OString("long"), pRoot
);
171 pRoot
->addDeclaration(pPredefined
);
173 pPredefined
= new AstBaseType(ET_ulong
, OString("unsigned long"), pRoot
);
174 pRoot
->addDeclaration(pPredefined
);
176 pPredefined
= new AstBaseType(ET_hyper
, OString("hyper"), pRoot
);
177 pRoot
->addDeclaration(pPredefined
);
179 pPredefined
= new AstBaseType(ET_uhyper
, OString("unsigned hyper"), pRoot
);
180 pRoot
->addDeclaration(pPredefined
);
182 pPredefined
= new AstBaseType(ET_short
, OString("short"), pRoot
);
183 pRoot
->addDeclaration(pPredefined
);
185 pPredefined
= new AstBaseType(ET_ushort
, OString("unsigned short"), pRoot
);
186 pRoot
->addDeclaration(pPredefined
);
188 pPredefined
= new AstBaseType(ET_float
, OString("float"), pRoot
);
189 pRoot
->addDeclaration(pPredefined
);
191 pPredefined
= new AstBaseType(ET_double
, OString("double"), pRoot
);
192 pRoot
->addDeclaration(pPredefined
);
194 pPredefined
= new AstBaseType(ET_char
, OString("char"), pRoot
);
195 pRoot
->addDeclaration(pPredefined
);
197 pPredefined
= new AstBaseType(ET_byte
, OString("byte"), pRoot
);
198 pRoot
->addDeclaration(pPredefined
);
200 pPredefined
= new AstBaseType(ET_any
, OString("any"), pRoot
);
201 pRoot
->addDeclaration(pPredefined
);
203 pPredefined
= new AstBaseType(ET_string
, OString("string"), pRoot
);
204 pRoot
->addDeclaration(pPredefined
);
206 pPredefined
= new AstBaseType(ET_type
, OString("type"), pRoot
);
207 pRoot
->addDeclaration(pPredefined
);
209 pPredefined
= new AstBaseType(ET_boolean
, OString("boolean"), pRoot
);
210 pRoot
->addDeclaration(pPredefined
);
212 pPredefined
= new AstBaseType(ET_void
, OString("void"), pRoot
);
213 pRoot
->addDeclaration(pPredefined
);
217 Idlc::Idlc(Options
* pOptions
)
218 : m_pOptions(pOptions
)
219 , m_bIsDocValid(sal_False
)
220 , m_bIsInMainfile(sal_True
)
225 , m_parseState(PS_NoState
)
227 m_pScopes
= new AstStack();
228 // init root object after construction
230 m_pErrorHandler
= new ErrorHandler();
231 m_bGenerateDoc
= m_pOptions
->isValid("-C");
241 delete m_pErrorHandler
;
249 m_pRoot
= new AstModule(NT_root
, OString(), NULL
);
251 // push the root node on the stack
252 m_pScopes
->push(m_pRoot
);
253 initializePredefinedTypes(m_pRoot
);
254 predefineXInterface(m_pRoot
);
259 m_bIsDocValid
= sal_False
;
260 m_bIsInMainfile
= sal_True
;
266 m_parseState
= PS_NoState
;
268 m_fileName
= OString();
269 m_mainFileName
= OString();
270 m_realFileName
= OString();
271 m_documentation
= OString();
277 m_pRoot
= new AstModule(NT_root
, OString(), NULL
);
279 // push the root node on the stack
280 m_pScopes
->push(m_pRoot
);
281 initializePredefinedTypes(m_pRoot
);
284 sal_Bool
Idlc::isDocValid()
286 if ( m_bGenerateDoc
)
287 return m_bIsDocValid
;
291 static Idlc
* pStaticIdlc
= NULL
;
293 Idlc
* SAL_CALL
idlc()
298 Idlc
* SAL_CALL
setIdlc(Options
* pOptions
)
304 pStaticIdlc
= new Idlc(pOptions
);
309 AstDeclaration
const * resolveTypedefs(AstDeclaration
const * type
) {
311 while (type
->getNodeType() == NT_typedef
) {
312 type
= static_cast< AstTypeDef
const * >(type
)->getBaseType();
318 AstDeclaration
const * deconstructAndResolveTypedefs(
319 AstDeclaration
const * type
, sal_Int32
* rank
)
326 switch (type
->getNodeType()) {
328 type
= static_cast< AstTypeDef
const * >(type
)->getBaseType();
332 type
= static_cast< AstSequence
const * >(type
)->getMemberType();
340 AstInterface
const * resolveInterfaceTypedefs(AstType
const * type
) {
341 AstDeclaration
const * decl
= resolveTypedefs(type
);
342 OSL_ASSERT(decl
->getNodeType() == NT_interface
);
343 return static_cast< AstInterface
const * >(decl
);