1*2fe1ca3dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2fe1ca3dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2fe1ca3dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2fe1ca3dSAndrew Rist * distributed with this work for additional information
6*2fe1ca3dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2fe1ca3dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2fe1ca3dSAndrew Rist * "License"); you may not use this file except in compliance
9*2fe1ca3dSAndrew Rist * with the License. You may obtain a copy of the License at
10*2fe1ca3dSAndrew Rist *
11*2fe1ca3dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2fe1ca3dSAndrew Rist *
13*2fe1ca3dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2fe1ca3dSAndrew Rist * software distributed under the License is distributed on an
15*2fe1ca3dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2fe1ca3dSAndrew Rist * KIND, either express or implied. See the License for the
17*2fe1ca3dSAndrew Rist * specific language governing permissions and limitations
18*2fe1ca3dSAndrew Rist * under the License.
19*2fe1ca3dSAndrew Rist *
20*2fe1ca3dSAndrew Rist *************************************************************/
21*2fe1ca3dSAndrew Rist
22*2fe1ca3dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_idlc.hxx"
26cdf0e10cSrcweir #include <idlc/fehelper.hxx>
27cdf0e10cSrcweir #include <idlc/errorhandler.hxx>
28cdf0e10cSrcweir #include <idlc/astarray.hxx>
29cdf0e10cSrcweir #include "idlc/idlc.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir using namespace ::rtl;
32cdf0e10cSrcweir
FeDeclarator(const OString & name,DeclaratorType declType,AstDeclaration * pComplPart)33cdf0e10cSrcweir FeDeclarator::FeDeclarator(const OString& name, DeclaratorType declType, AstDeclaration* pComplPart)
34cdf0e10cSrcweir : m_pComplexPart(pComplPart)
35cdf0e10cSrcweir , m_name(name)
36cdf0e10cSrcweir , m_declType(declType)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir }
39cdf0e10cSrcweir
~FeDeclarator()40cdf0e10cSrcweir FeDeclarator::~FeDeclarator()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir }
43cdf0e10cSrcweir
checkType(AstDeclaration const * type)44cdf0e10cSrcweir sal_Bool FeDeclarator::checkType(AstDeclaration const * type)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir OString tmp(m_name);
47cdf0e10cSrcweir sal_Int32 count = m_name.lastIndexOf( ':' );
48cdf0e10cSrcweir if( count != -1 )
49cdf0e10cSrcweir tmp = m_name.copy( count+1 );
50cdf0e10cSrcweir
51cdf0e10cSrcweir if (tmp == type->getLocalName())
52cdf0e10cSrcweir return sal_False;
53cdf0e10cSrcweir else
54cdf0e10cSrcweir return sal_True;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
compose(AstDeclaration const * pDecl)57cdf0e10cSrcweir AstType const * FeDeclarator::compose(AstDeclaration const * pDecl)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir AstArray* pArray;
60cdf0e10cSrcweir AstType* pType;
61cdf0e10cSrcweir
62cdf0e10cSrcweir if ( pDecl == 0 )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir return NULL;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir if ( !pDecl->isType() )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir idlc()->error()->noTypeError(pDecl);
69cdf0e10cSrcweir return NULL;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir pType = (AstType*)pDecl;
72cdf0e10cSrcweir if (m_declType == FD_simple || m_pComplexPart == NULL)
73cdf0e10cSrcweir return pType;
74cdf0e10cSrcweir
75cdf0e10cSrcweir if (m_pComplexPart->getNodeType() == NT_array)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir pArray = (AstArray*)m_pComplexPart;
78cdf0e10cSrcweir pArray->setType(pType);
79cdf0e10cSrcweir
80cdf0e10cSrcweir // insert array type in global scope
81cdf0e10cSrcweir AstScope* pScope = idlc()->scopes()->bottom();
82cdf0e10cSrcweir if ( pScope )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir AstDeclaration* pDecl2 = pScope->addDeclaration(pArray);
85cdf0e10cSrcweir if ( (AstDeclaration*)pArray != pDecl2 )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir delete m_pComplexPart;
88cdf0e10cSrcweir m_pComplexPart = pDecl2;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir }
91cdf0e10cSrcweir return pArray;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir return NULL; // return through this statement should not happen
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
FeInheritanceHeader(NodeType nodeType,::rtl::OString * pName,::rtl::OString * pInherits,std::vector<rtl::OString> * typeParameters)97cdf0e10cSrcweir FeInheritanceHeader::FeInheritanceHeader(
98cdf0e10cSrcweir NodeType nodeType, ::rtl::OString* pName, ::rtl::OString* pInherits,
99cdf0e10cSrcweir std::vector< rtl::OString > * typeParameters)
100cdf0e10cSrcweir : m_nodeType(nodeType)
101cdf0e10cSrcweir , m_pName(pName)
102cdf0e10cSrcweir , m_pInherits(NULL)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir if (typeParameters != 0) {
105cdf0e10cSrcweir m_typeParameters = *typeParameters;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir initializeInherits(pInherits);
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
initializeInherits(::rtl::OString * pInherits)110cdf0e10cSrcweir void FeInheritanceHeader::initializeInherits(::rtl::OString* pInherits)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir if ( pInherits )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir AstScope* pScope = idlc()->scopes()->topNonNull();
115cdf0e10cSrcweir AstDeclaration* pDecl = pScope->lookupByName(*pInherits);
116cdf0e10cSrcweir if ( pDecl )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir AstDeclaration const * resolved = resolveTypedefs(pDecl);
119cdf0e10cSrcweir if ( resolved->getNodeType() == getNodeType()
120cdf0e10cSrcweir && (resolved->getNodeType() != NT_interface
121cdf0e10cSrcweir || static_cast< AstInterface const * >(
122cdf0e10cSrcweir resolved)->isDefined()) )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir if ( idlc()->error()->checkPublished( pDecl ) )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir m_pInherits = pDecl;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir }
129cdf0e10cSrcweir else
130cdf0e10cSrcweir {
131cdf0e10cSrcweir idlc()->error()->inheritanceError(
132cdf0e10cSrcweir getNodeType(), getName(), pDecl);
133cdf0e10cSrcweir }
134cdf0e10cSrcweir }
135cdf0e10cSrcweir else
136cdf0e10cSrcweir {
137cdf0e10cSrcweir idlc()->error()->lookupError(*pInherits);
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir }
141