xref: /trunk/main/idlc/source/fehelper.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_idlc.hxx"
30 #include <idlc/fehelper.hxx>
31 #include <idlc/errorhandler.hxx>
32 #include <idlc/astarray.hxx>
33 #include "idlc/idlc.hxx"
34 
35 using namespace ::rtl;
36 
37 FeDeclarator::FeDeclarator(const OString& name, DeclaratorType declType, AstDeclaration* pComplPart)
38     : m_pComplexPart(pComplPart)
39     , m_name(name)
40     , m_declType(declType)
41 {
42 }
43 
44 FeDeclarator::~FeDeclarator()
45 {
46 }
47 
48 sal_Bool FeDeclarator::checkType(AstDeclaration const * type)
49 {
50     OString tmp(m_name);
51     sal_Int32 count = m_name.lastIndexOf( ':' );
52     if( count != -1 )
53         tmp = m_name.copy( count+1 );
54 
55     if (tmp == type->getLocalName())
56         return sal_False;
57     else
58         return sal_True;
59 }
60 
61 AstType const * FeDeclarator::compose(AstDeclaration const * pDecl)
62 {
63     AstArray*   pArray;
64     AstType*    pType;
65 
66     if ( pDecl == 0 )
67     {
68         return NULL;
69     }
70     if ( !pDecl->isType() )
71     {
72         idlc()->error()->noTypeError(pDecl);
73         return NULL;
74     }
75     pType = (AstType*)pDecl;
76     if (m_declType == FD_simple || m_pComplexPart == NULL)
77         return pType;
78 
79     if (m_pComplexPart->getNodeType() == NT_array)
80     {
81         pArray = (AstArray*)m_pComplexPart;
82         pArray->setType(pType);
83 
84         // insert array type in global scope
85         AstScope* pScope = idlc()->scopes()->bottom();
86         if ( pScope )
87         {
88             AstDeclaration* pDecl2 = pScope->addDeclaration(pArray);
89             if ( (AstDeclaration*)pArray != pDecl2 )
90             {
91                 delete m_pComplexPart;
92                 m_pComplexPart = pDecl2;
93             }
94         }
95         return pArray;
96     }
97 
98     return NULL; // return through this statement should not happen
99 }
100 
101 FeInheritanceHeader::FeInheritanceHeader(
102     NodeType nodeType, ::rtl::OString* pName, ::rtl::OString* pInherits,
103     std::vector< rtl::OString > * typeParameters)
104     : m_nodeType(nodeType)
105     , m_pName(pName)
106     , m_pInherits(NULL)
107 {
108     if (typeParameters != 0) {
109         m_typeParameters = *typeParameters;
110     }
111     initializeInherits(pInherits);
112 }
113 
114 void FeInheritanceHeader::initializeInherits(::rtl::OString* pInherits)
115 {
116     if ( pInherits )
117     {
118         AstScope* pScope = idlc()->scopes()->topNonNull();
119         AstDeclaration* pDecl = pScope->lookupByName(*pInherits);
120         if ( pDecl )
121         {
122             AstDeclaration const * resolved = resolveTypedefs(pDecl);
123             if ( resolved->getNodeType() == getNodeType()
124                  && (resolved->getNodeType() != NT_interface
125                      || static_cast< AstInterface const * >(
126                          resolved)->isDefined()) )
127             {
128                 if ( idlc()->error()->checkPublished( pDecl ) )
129                 {
130                     m_pInherits = pDecl;
131                 }
132             }
133             else
134             {
135                 idlc()->error()->inheritanceError(
136                     getNodeType(), getName(), pDecl);
137             }
138         }
139         else
140         {
141             idlc()->error()->lookupError(*pInherits);
142         }
143     }
144 }
145