fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / idlc / source / aststruct.cxx
blobd2232990e615251ee6e3bbd5cde99d22826b5d57
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/aststruct.hxx>
21 #include <idlc/astmember.hxx>
23 #include <registry/version.h>
24 #include <registry/writer.hxx>
26 AstStruct::AstStruct(
27 const OString& name, std::vector< OString > const & typeParameters,
28 AstStruct const* pBaseType, AstScope* pScope)
29 : AstType(NT_struct, name, pScope)
30 , AstScope(NT_struct)
31 , m_pBaseType(pBaseType)
33 for (std::vector< OString >::const_iterator i(typeParameters.begin());
34 i != typeParameters.end(); ++i)
36 m_typeParameters.push_back(
37 new AstType(NT_type_parameter, *i, 0));
41 AstStruct::AstStruct(const NodeType type,
42 const OString& name,
43 AstStruct const* pBaseType,
44 AstScope* pScope)
45 : AstType(type, name, pScope)
46 , AstScope(type)
47 , m_pBaseType(pBaseType)
51 AstStruct::~AstStruct()
53 for (DeclList::iterator i(m_typeParameters.begin());
54 i != m_typeParameters.end(); ++i)
56 delete *i;
60 AstDeclaration const * AstStruct::findTypeParameter(OString const & name)
61 const
63 for (DeclList::const_iterator i(m_typeParameters.begin());
64 i != m_typeParameters.end(); ++i)
66 if ((*i)->getLocalName() == name) {
67 return *i;
70 return 0;
73 bool AstStruct::isType() const {
74 return getNodeType() == NT_struct
75 ? getTypeParameterCount() == 0 : AstDeclaration::isType();
78 bool AstStruct::dump(RegistryKey& rKey)
80 RegistryKey localKey;
81 if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey) != RegError::NO_ERROR)
83 fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
84 idlc()->getOptions()->getProgramName().getStr(),
85 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
86 return false;
89 if (m_typeParameters.size() > SAL_MAX_UINT16) {
90 fprintf(
91 stderr,
92 ("%s: polymorphic struct type template %s has too many type"
93 " parameters\n"),
94 idlc()->getOptions()->getProgramName().getStr(),
95 getScopedName().getStr());
96 return false;
99 sal_uInt16 nMember = getNodeCount(NT_member);
101 RTTypeClass typeClass = RT_TYPE_STRUCT;
102 if ( getNodeType() == NT_exception )
103 typeClass = RT_TYPE_EXCEPTION;
105 OUString emptyStr;
106 typereg::Writer aBlob(
107 (m_typeParameters.empty() && !m_bPublished
108 ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1),
109 getDocumentation(), emptyStr, typeClass, m_bPublished,
110 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
111 m_pBaseType == 0 ? 0 : 1, nMember, 0,
112 static_cast< sal_uInt16 >(m_typeParameters.size()));
113 if (m_pBaseType != 0) {
114 aBlob.setSuperTypeName(
116 OStringToOUString(
117 m_pBaseType->getRelativName(), RTL_TEXTENCODING_UTF8));
120 if ( nMember > 0 )
122 DeclList::const_iterator iter = getIteratorBegin();
123 DeclList::const_iterator end = getIteratorEnd();
124 AstMember* pMember = NULL;
125 sal_uInt16 index = 0;
126 while ( iter != end )
128 AstDeclaration* pDecl = *iter;
129 if ( pDecl->getNodeType() == NT_member )
131 pMember = static_cast<AstMember*>(pDecl);
132 RTFieldAccess flags = RTFieldAccess::READWRITE;
133 OString typeName;
134 if (pMember->getType()->getNodeType() == NT_type_parameter) {
135 flags |= RTFieldAccess::PARAMETERIZED_TYPE;
136 typeName = pMember->getType()->getLocalName();
137 } else {
138 typeName = pMember->getType()->getRelativName();
140 aBlob.setFieldData(
141 index++, pMember->getDocumentation(), emptyStr, flags,
142 OStringToOUString(
143 pMember->getLocalName(), RTL_TEXTENCODING_UTF8),
144 OStringToOUString(typeName, RTL_TEXTENCODING_UTF8),
145 RTConstValue());
147 ++iter;
151 sal_uInt16 index = 0;
152 for (DeclList::iterator i(m_typeParameters.begin());
153 i != m_typeParameters.end(); ++i)
155 aBlob.setReferenceData(
156 index++, emptyStr, RTReferenceType::TYPE_PARAMETER, RTFieldAccess::INVALID,
157 OStringToOUString(
158 (*i)->getLocalName(), RTL_TEXTENCODING_UTF8));
161 sal_uInt32 aBlobSize;
162 void const * pBlob = aBlob.getBlob(&aBlobSize);
164 if (localKey.setValue(emptyStr, RegValueType::BINARY,
165 const_cast<RegValue>(pBlob), aBlobSize) != RegError::NO_ERROR)
167 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
168 idlc()->getOptions()->getProgramName().getStr(),
169 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
170 return false;
173 return true;
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */