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 : using namespace ::rtl;
27 :
28 12059 : AstStruct::AstStruct(
29 : const OString& name, std::vector< OString > const & typeParameters,
30 : AstStruct* pBaseType, AstScope* pScope)
31 : : AstType(NT_struct, name, pScope)
32 : , AstScope(NT_struct)
33 12059 : , m_pBaseType(pBaseType)
34 : {
35 36603 : for (std::vector< OString >::const_iterator i(typeParameters.begin());
36 24402 : i != typeParameters.end(); ++i)
37 : {
38 : m_typeParameters.push_back(
39 142 : new AstDeclaration(NT_type_parameter, *i, 0));
40 : }
41 12059 : }
42 :
43 13594 : AstStruct::AstStruct(const NodeType type,
44 : const OString& name,
45 : AstStruct* pBaseType,
46 : AstScope* pScope)
47 : : AstType(type, name, pScope)
48 : , AstScope(type)
49 13594 : , m_pBaseType(pBaseType)
50 : {
51 13594 : }
52 :
53 0 : AstStruct::~AstStruct()
54 : {
55 0 : for (DeclList::iterator i(m_typeParameters.begin());
56 0 : i != m_typeParameters.end(); ++i)
57 : {
58 0 : delete *i;
59 : }
60 0 : }
61 :
62 8631 : AstDeclaration const * AstStruct::findTypeParameter(OString const & name)
63 : const
64 : {
65 25953 : for (DeclList::const_iterator i(m_typeParameters.begin());
66 17302 : i != m_typeParameters.end(); ++i)
67 : {
68 112 : if ((*i)->getLocalName() == name) {
69 92 : return *i;
70 : }
71 : }
72 8539 : return 0;
73 : }
74 :
75 13788 : bool AstStruct::isType() const {
76 13788 : return getNodeType() == NT_struct
77 13788 : ? getTypeParameterCount() == 0 : AstDeclaration::isType();
78 : }
79 :
80 743 : sal_Bool AstStruct::dump(RegistryKey& rKey)
81 : {
82 743 : RegistryKey localKey;
83 743 : if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
84 : {
85 : fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
86 0 : idlc()->getOptions()->getProgramName().getStr(),
87 0 : getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
88 0 : return sal_False;
89 : }
90 :
91 743 : if (m_typeParameters.size() > SAL_MAX_UINT16) {
92 : fprintf(
93 : stderr,
94 : ("%s: polymorphic struct type template %s has too many type"
95 : " parameters\n"),
96 0 : idlc()->getOptions()->getProgramName().getStr(),
97 0 : getScopedName().getStr());
98 0 : return false;
99 : }
100 :
101 743 : sal_uInt16 nMember = getNodeCount(NT_member);
102 :
103 743 : RTTypeClass typeClass = RT_TYPE_STRUCT;
104 743 : if ( getNodeType() == NT_exception )
105 276 : typeClass = RT_TYPE_EXCEPTION;
106 :
107 1486 : OUString emptyStr;
108 : typereg::Writer aBlob(
109 743 : (m_typeParameters.empty() && !m_bPublished
110 : ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1),
111 743 : getDocumentation(), emptyStr, typeClass, m_bPublished,
112 743 : OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
113 : m_pBaseType == 0 ? 0 : 1, nMember, 0,
114 2972 : static_cast< sal_uInt16 >(m_typeParameters.size()));
115 743 : if (m_pBaseType != 0) {
116 : aBlob.setSuperTypeName(
117 : 0,
118 : OStringToOUString(
119 359 : m_pBaseType->getRelativName(), RTL_TEXTENCODING_UTF8));
120 : }
121 :
122 743 : if ( nMember > 0 )
123 : {
124 569 : DeclList::const_iterator iter = getIteratorBegin();
125 569 : DeclList::const_iterator end = getIteratorEnd();
126 569 : AstDeclaration* pDecl = NULL;
127 569 : AstMember* pMember = NULL;
128 569 : sal_uInt16 index = 0;
129 2820 : while ( iter != end )
130 : {
131 1682 : pDecl = *iter;
132 1682 : if ( pDecl->getNodeType() == NT_member )
133 : {
134 1682 : pMember = (AstMember*)pDecl;
135 1682 : RTFieldAccess flags = RT_ACCESS_READWRITE;
136 1682 : OString typeName;
137 1682 : if (pMember->getType()->getNodeType() == NT_type_parameter) {
138 24 : flags |= RT_ACCESS_PARAMETERIZED_TYPE;
139 24 : typeName = pMember->getType()->getLocalName();
140 : } else {
141 1658 : typeName = pMember->getType()->getRelativName();
142 : }
143 : aBlob.setFieldData(
144 1682 : index++, pMember->getDocumentation(), emptyStr, flags,
145 : OStringToOUString(
146 1682 : pMember->getLocalName(), RTL_TEXTENCODING_UTF8),
147 : OStringToOUString(typeName, RTL_TEXTENCODING_UTF8),
148 5046 : RTConstValue());
149 : }
150 1682 : ++iter;
151 : }
152 : }
153 :
154 743 : sal_uInt16 index = 0;
155 2334 : for (DeclList::iterator i(m_typeParameters.begin());
156 1556 : i != m_typeParameters.end(); ++i)
157 : {
158 : aBlob.setReferenceData(
159 : index++, emptyStr, RT_REF_TYPE_PARAMETER, RT_ACCESS_INVALID,
160 : OStringToOUString(
161 35 : (*i)->getLocalName(), RTL_TEXTENCODING_UTF8));
162 : }
163 :
164 : sal_uInt32 aBlobSize;
165 743 : void const * pBlob = aBlob.getBlob(&aBlobSize);
166 :
167 743 : if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
168 743 : (RegValue)pBlob, aBlobSize))
169 : {
170 : fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
171 0 : idlc()->getOptions()->getProgramName().getStr(),
172 0 : getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
173 0 : return sal_False;
174 : }
175 :
176 1486 : return sal_True;
177 : }
178 :
179 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|