Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <idlc/aststruct.hxx>
21 : #include <idlc/astmember.hxx>
22 :
23 : #include <registry/version.h>
24 : #include <registry/writer.hxx>
25 :
26 130 : 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 130 : , m_pBaseType(pBaseType)
32 : {
33 615 : for (std::vector< OString >::const_iterator i(typeParameters.begin());
34 410 : i != typeParameters.end(); ++i)
35 : {
36 : m_typeParameters.push_back(
37 75 : new AstType(NT_type_parameter, *i, 0));
38 : }
39 130 : }
40 :
41 40 : 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 40 : , m_pBaseType(pBaseType)
48 : {
49 40 : }
50 :
51 0 : AstStruct::~AstStruct()
52 : {
53 0 : for (DeclList::iterator i(m_typeParameters.begin());
54 0 : i != m_typeParameters.end(); ++i)
55 : {
56 0 : delete *i;
57 : }
58 0 : }
59 :
60 42 : AstDeclaration const * AstStruct::findTypeParameter(OString const & name)
61 : const
62 : {
63 132 : for (DeclList::const_iterator i(m_typeParameters.begin());
64 88 : i != m_typeParameters.end(); ++i)
65 : {
66 28 : if ((*i)->getLocalName() == name) {
67 26 : return *i;
68 : }
69 : }
70 16 : return 0;
71 : }
72 :
73 5 : bool AstStruct::isType() const {
74 5 : return getNodeType() == NT_struct
75 5 : ? getTypeParameterCount() == 0 : AstDeclaration::isType();
76 : }
77 :
78 79 : bool AstStruct::dump(RegistryKey& rKey)
79 : {
80 79 : RegistryKey localKey;
81 79 : if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey) != RegError::NO_ERROR)
82 : {
83 : fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
84 0 : idlc()->getOptions()->getProgramName().getStr(),
85 0 : getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
86 0 : return false;
87 : }
88 :
89 79 : 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 0 : idlc()->getOptions()->getProgramName().getStr(),
95 0 : getScopedName().getStr());
96 0 : return false;
97 : }
98 :
99 79 : sal_uInt16 nMember = getNodeCount(NT_member);
100 :
101 79 : RTTypeClass typeClass = RT_TYPE_STRUCT;
102 79 : if ( getNodeType() == NT_exception )
103 26 : typeClass = RT_TYPE_EXCEPTION;
104 :
105 158 : OUString emptyStr;
106 : typereg::Writer aBlob(
107 79 : (m_typeParameters.empty() && !m_bPublished
108 : ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1),
109 79 : getDocumentation(), emptyStr, typeClass, m_bPublished,
110 79 : OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
111 : m_pBaseType == 0 ? 0 : 1, nMember, 0,
112 316 : static_cast< sal_uInt16 >(m_typeParameters.size()));
113 79 : if (m_pBaseType != 0) {
114 : aBlob.setSuperTypeName(
115 : 0,
116 : OStringToOUString(
117 7 : m_pBaseType->getRelativName(), RTL_TEXTENCODING_UTF8));
118 : }
119 :
120 79 : if ( nMember > 0 )
121 : {
122 56 : DeclList::const_iterator iter = getIteratorBegin();
123 56 : DeclList::const_iterator end = getIteratorEnd();
124 56 : AstMember* pMember = NULL;
125 56 : sal_uInt16 index = 0;
126 168 : while ( iter != end )
127 : {
128 56 : AstDeclaration* pDecl = *iter;
129 56 : if ( pDecl->getNodeType() == NT_member )
130 : {
131 56 : pMember = static_cast<AstMember*>(pDecl);
132 56 : RTFieldAccess flags = RTFieldAccess::READWRITE;
133 56 : OString typeName;
134 56 : if (pMember->getType()->getNodeType() == NT_type_parameter) {
135 15 : flags |= RTFieldAccess::PARAMETERIZED_TYPE;
136 15 : typeName = pMember->getType()->getLocalName();
137 : } else {
138 41 : typeName = pMember->getType()->getRelativName();
139 : }
140 : aBlob.setFieldData(
141 56 : index++, pMember->getDocumentation(), emptyStr, flags,
142 : OStringToOUString(
143 56 : pMember->getLocalName(), RTL_TEXTENCODING_UTF8),
144 : OStringToOUString(typeName, RTL_TEXTENCODING_UTF8),
145 168 : RTConstValue());
146 : }
147 56 : ++iter;
148 : }
149 : }
150 :
151 79 : sal_uInt16 index = 0;
152 312 : for (DeclList::iterator i(m_typeParameters.begin());
153 208 : i != m_typeParameters.end(); ++i)
154 : {
155 : aBlob.setReferenceData(
156 : index++, emptyStr, RTReferenceType::TYPE_PARAMETER, RTFieldAccess::INVALID,
157 : OStringToOUString(
158 25 : (*i)->getLocalName(), RTL_TEXTENCODING_UTF8));
159 : }
160 :
161 : sal_uInt32 aBlobSize;
162 79 : void const * pBlob = aBlob.getBlob(&aBlobSize);
163 :
164 79 : if (localKey.setValue(emptyStr, RegValueType::BINARY,
165 79 : const_cast<RegValue>(pBlob), aBlobSize) != RegError::NO_ERROR)
166 : {
167 : fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
168 0 : idlc()->getOptions()->getProgramName().getStr(),
169 0 : getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
170 0 : return false;
171 : }
172 :
173 158 : return true;
174 : }
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|