update credits
[LibreOffice.git] / idlc / source / fehelper.cxx
blobfdfd8388d657f989a8b413622864e5b52c0cdda9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <idlc/fehelper.hxx>
21 #include <idlc/errorhandler.hxx>
22 #include <idlc/astarray.hxx>
23 #include "idlc/idlc.hxx"
25 using namespace ::rtl;
27 FeDeclarator::FeDeclarator(const OString& name, DeclaratorType declType, AstDeclaration* pComplPart)
28 : m_pComplexPart(pComplPart)
29 , m_name(name)
30 , m_declType(declType)
34 FeDeclarator::~FeDeclarator()
38 sal_Bool FeDeclarator::checkType(AstDeclaration const * type)
40 OString tmp(m_name);
41 sal_Int32 count = m_name.lastIndexOf( ':' );
42 if( count != -1 )
43 tmp = m_name.copy( count+1 );
45 if (tmp == type->getLocalName())
46 return sal_False;
47 else
48 return sal_True;
51 AstType const * FeDeclarator::compose(AstDeclaration const * pDecl)
53 AstArray* pArray;
54 AstType* pType;
56 if ( pDecl == 0 )
58 return NULL;
60 if ( !pDecl->isType() )
62 idlc()->error()->noTypeError(pDecl);
63 return NULL;
65 pType = (AstType*)pDecl;
66 if (m_declType == FD_simple || m_pComplexPart == NULL)
67 return pType;
69 if (m_pComplexPart->getNodeType() == NT_array)
71 pArray = (AstArray*)m_pComplexPart;
72 pArray->setType(pType);
74 // insert array type in global scope
75 AstScope* pScope = idlc()->scopes()->bottom();
76 if ( pScope )
78 AstDeclaration* pDecl2 = pScope->addDeclaration(pArray);
79 if ( (AstDeclaration*)pArray != pDecl2 )
81 delete m_pComplexPart;
82 m_pComplexPart = pDecl2;
85 return pArray;
88 return NULL; // return through this statement should not happen
91 FeInheritanceHeader::FeInheritanceHeader(
92 NodeType nodeType, OString* pName, OString* pInherits,
93 std::vector< OString > * typeParameters)
94 : m_nodeType(nodeType)
95 , m_pName(pName)
96 , m_pInherits(NULL)
98 if (typeParameters != 0) {
99 m_typeParameters = *typeParameters;
101 initializeInherits(pInherits);
104 void FeInheritanceHeader::initializeInherits(OString* pInherits)
106 if ( pInherits )
108 AstScope* pScope = idlc()->scopes()->topNonNull();
109 AstDeclaration* pDecl = pScope->lookupByName(*pInherits);
110 if ( pDecl )
112 AstDeclaration const * resolved = resolveTypedefs(pDecl);
113 if ( resolved->getNodeType() == getNodeType()
114 && (resolved->getNodeType() != NT_interface
115 || static_cast< AstInterface const * >(
116 resolved)->isDefined()) )
118 if ( idlc()->error()->checkPublished( pDecl ) )
120 m_pInherits = pDecl;
123 else
125 idlc()->error()->inheritanceError(
126 getNodeType(), getName(), pDecl);
129 else
131 idlc()->error()->lookupError(*pInherits);
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */