merge the formfield patch from ooo-build
[ooovba.git] / idlc / source / fehelper.cxx
blob0579398dfc5ac5d375672664712b5fec9ded46e8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fehelper.cxx,v $
10 * $Revision: 1.10 $
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/fehelper.hxx>
34 #include <idlc/errorhandler.hxx>
35 #include <idlc/astarray.hxx>
36 #include "idlc/idlc.hxx"
38 using namespace ::rtl;
40 FeDeclarator::FeDeclarator(const OString& name, DeclaratorType declType, AstDeclaration* pComplPart)
41 : m_pComplexPart(pComplPart)
42 , m_name(name)
43 , m_declType(declType)
47 FeDeclarator::~FeDeclarator()
51 sal_Bool FeDeclarator::checkType(AstDeclaration const * type)
53 OString tmp(m_name);
54 sal_Int32 count = m_name.lastIndexOf( ':' );
55 if( count != -1 )
56 tmp = m_name.copy( count+1 );
58 if (tmp == type->getLocalName())
59 return sal_False;
60 else
61 return sal_True;
64 AstType const * FeDeclarator::compose(AstDeclaration const * pDecl)
66 AstArray* pArray;
67 AstType* pType;
69 if ( pDecl == 0 )
71 return NULL;
73 if ( !pDecl->isType() )
75 idlc()->error()->noTypeError(pDecl);
76 return NULL;
78 pType = (AstType*)pDecl;
79 if (m_declType == FD_simple || m_pComplexPart == NULL)
80 return pType;
82 if (m_pComplexPart->getNodeType() == NT_array)
84 pArray = (AstArray*)m_pComplexPart;
85 pArray->setType(pType);
87 // insert array type in global scope
88 AstScope* pScope = idlc()->scopes()->bottom();
89 if ( pScope )
91 AstDeclaration* pDecl2 = pScope->addDeclaration(pArray);
92 if ( (AstDeclaration*)pArray != pDecl2 )
94 delete m_pComplexPart;
95 m_pComplexPart = pDecl2;
98 return pArray;
101 return NULL; // return through this statement should not happen
104 FeInheritanceHeader::FeInheritanceHeader(
105 NodeType nodeType, ::rtl::OString* pName, ::rtl::OString* pInherits,
106 std::vector< rtl::OString > * typeParameters)
107 : m_nodeType(nodeType)
108 , m_pName(pName)
109 , m_pInherits(NULL)
111 if (typeParameters != 0) {
112 m_typeParameters = *typeParameters;
114 initializeInherits(pInherits);
117 void FeInheritanceHeader::initializeInherits(::rtl::OString* pInherits)
119 if ( pInherits )
121 AstScope* pScope = idlc()->scopes()->topNonNull();
122 AstDeclaration* pDecl = pScope->lookupByName(*pInherits);
123 if ( pDecl )
125 AstDeclaration const * resolved = resolveTypedefs(pDecl);
126 if ( resolved->getNodeType() == getNodeType()
127 && (resolved->getNodeType() != NT_interface
128 || static_cast< AstInterface const * >(
129 resolved)->isDefined()) )
131 if ( idlc()->error()->checkPublished( pDecl ) )
133 m_pInherits = pDecl;
136 else
138 idlc()->error()->inheritanceError(
139 getNodeType(), getName(), pDecl);
142 else
144 idlc()->error()->lookupError(*pInherits);