xref: /trunk/main/idlc/source/fehelper.cxx (revision 2fe1ca3d)
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 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_idlc.hxx"
26 #include <idlc/fehelper.hxx>
27 #include <idlc/errorhandler.hxx>
28 #include <idlc/astarray.hxx>
29 #include "idlc/idlc.hxx"
30 
31 using namespace ::rtl;
32 
33 FeDeclarator::FeDeclarator(const OString& name, DeclaratorType declType, AstDeclaration* pComplPart)
34 	: m_pComplexPart(pComplPart)
35 	, m_name(name)
36 	, m_declType(declType)
37 {
38 }
39 
40 FeDeclarator::~FeDeclarator()
41 {
42 }
43 
44 sal_Bool FeDeclarator::checkType(AstDeclaration const * type)
45 {
46 	OString tmp(m_name);
47 	sal_Int32 count = m_name.lastIndexOf( ':' );
48     if( count != -1 )
49         tmp = m_name.copy( count+1 );
50 
51 	if (tmp == type->getLocalName())
52 		return sal_False;
53 	else
54 		return sal_True;
55 }
56 
57 AstType const * FeDeclarator::compose(AstDeclaration const * pDecl)
58 {
59 	AstArray*	pArray;
60 	AstType*	pType;
61 
62     if ( pDecl == 0 )
63     {
64         return NULL;
65     }
66 	if ( !pDecl->isType() )
67 	{
68 		idlc()->error()->noTypeError(pDecl);
69 		return NULL;
70 	}
71 	pType = (AstType*)pDecl;
72 	if (m_declType == FD_simple || m_pComplexPart == NULL)
73 		return pType;
74 
75 	if (m_pComplexPart->getNodeType() == NT_array)
76 	{
77 		pArray = (AstArray*)m_pComplexPart;
78 		pArray->setType(pType);
79 
80 		// insert array type in global scope
81 		AstScope* pScope = idlc()->scopes()->bottom();
82 		if ( pScope )
83 		{
84 			AstDeclaration* pDecl2 = pScope->addDeclaration(pArray);
85 			if ( (AstDeclaration*)pArray != pDecl2 )
86 			{
87 				delete m_pComplexPart;
88 				m_pComplexPart = pDecl2;
89 			}
90 		}
91 		return pArray;
92 	}
93 
94 	return NULL; // return through this statement should not happen
95 }
96 
97 FeInheritanceHeader::FeInheritanceHeader(
98     NodeType nodeType, ::rtl::OString* pName, ::rtl::OString* pInherits,
99     std::vector< rtl::OString > * typeParameters)
100 	: m_nodeType(nodeType)
101 	, m_pName(pName)
102 	, m_pInherits(NULL)
103 {
104     if (typeParameters != 0) {
105         m_typeParameters = *typeParameters;
106     }
107 	initializeInherits(pInherits);
108 }
109 
110 void FeInheritanceHeader::initializeInherits(::rtl::OString* pInherits)
111 {
112 	if ( pInherits )
113 	{
114 		AstScope* pScope = idlc()->scopes()->topNonNull();
115 		AstDeclaration* pDecl = pScope->lookupByName(*pInherits);
116         if ( pDecl )
117         {
118             AstDeclaration const * resolved = resolveTypedefs(pDecl);
119             if ( resolved->getNodeType() == getNodeType()
120                  && (resolved->getNodeType() != NT_interface
121                      || static_cast< AstInterface const * >(
122                          resolved)->isDefined()) )
123             {
124                 if ( idlc()->error()->checkPublished( pDecl ) )
125                 {
126                     m_pInherits = pDecl;
127                 }
128             }
129             else
130             {
131                 idlc()->error()->inheritanceError(
132                     getNodeType(), getName(), pDecl);
133             }
134         }
135         else
136         {
137             idlc()->error()->lookupError(*pInherits);
138         }
139 	}
140 }
141