1*ff7655f0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*ff7655f0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*ff7655f0SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*ff7655f0SAndrew Rist * distributed with this work for additional information
6*ff7655f0SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*ff7655f0SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*ff7655f0SAndrew Rist * "License"); you may not use this file except in compliance
9*ff7655f0SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*ff7655f0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*ff7655f0SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*ff7655f0SAndrew Rist * software distributed under the License is distributed on an
15*ff7655f0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ff7655f0SAndrew Rist * KIND, either express or implied. See the License for the
17*ff7655f0SAndrew Rist * specific language governing permissions and limitations
18*ff7655f0SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*ff7655f0SAndrew Rist *************************************************************/
21*ff7655f0SAndrew Rist
22*ff7655f0SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_codemaker.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "sal/config.h"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "codemaker/codemaker.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "codemaker/options.hxx"
32cdf0e10cSrcweir #include "codemaker/typemanager.hxx"
33cdf0e10cSrcweir #include "codemaker/unotype.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include "osl/diagnose.h"
36cdf0e10cSrcweir #include "registry/reader.hxx"
37cdf0e10cSrcweir #include "registry/types.h"
38cdf0e10cSrcweir #include "rtl/strbuf.h"
39cdf0e10cSrcweir #include "rtl/string.h"
40cdf0e10cSrcweir #include "rtl/string.hxx"
41cdf0e10cSrcweir #include "rtl/ustring.hxx"
42cdf0e10cSrcweir #include "sal/types.h"
43cdf0e10cSrcweir
44cdf0e10cSrcweir #include <vector>
45cdf0e10cSrcweir
46cdf0e10cSrcweir namespace {
47cdf0e10cSrcweir
checkNoTypeArguments(std::vector<rtl::OString> const & arguments)48cdf0e10cSrcweir void checkNoTypeArguments(std::vector< rtl::OString > const & arguments) {
49cdf0e10cSrcweir if (!arguments.empty()) {
50cdf0e10cSrcweir throw CannotDumpException(
51cdf0e10cSrcweir rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
52cdf0e10cSrcweir //TODO
53cdf0e10cSrcweir }
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
56cdf0e10cSrcweir }
57cdf0e10cSrcweir
58cdf0e10cSrcweir namespace codemaker {
59cdf0e10cSrcweir
convertString(rtl::OUString const & string)60cdf0e10cSrcweir rtl::OString convertString(rtl::OUString const & string) {
61cdf0e10cSrcweir rtl::OString s;
62cdf0e10cSrcweir if (!string.convertToString(
63cdf0e10cSrcweir &s, RTL_TEXTENCODING_UTF8,
64cdf0e10cSrcweir (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
65cdf0e10cSrcweir | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
66cdf0e10cSrcweir {
67cdf0e10cSrcweir throw CannotDumpException(
68cdf0e10cSrcweir rtl::OString(
69cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM(
70cdf0e10cSrcweir "Failure converting string from UTF-16 to UTF-8")));
71cdf0e10cSrcweir }
72cdf0e10cSrcweir return s;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
errorMsg(rtl::OString const & desc,rtl::OString const & type)75cdf0e10cSrcweir rtl::OString errorMsg(rtl::OString const & desc, rtl::OString const & type) {
76cdf0e10cSrcweir rtl::OStringBuffer msg(128);
77cdf0e10cSrcweir msg.append(desc);
78cdf0e10cSrcweir msg.append(type);
79cdf0e10cSrcweir return msg.makeStringAndClear();
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
decomposeAndResolve(TypeManager const & manager,rtl::OString const & type,bool resolveTypedefs,bool allowVoid,bool allowExtraEntities,RTTypeClass * typeClass,rtl::OString * name,sal_Int32 * rank,std::vector<rtl::OString> * arguments)82cdf0e10cSrcweir codemaker::UnoType::Sort decomposeAndResolve(
83cdf0e10cSrcweir TypeManager const & manager, rtl::OString const & type,
84cdf0e10cSrcweir bool resolveTypedefs, bool allowVoid, bool allowExtraEntities,
85cdf0e10cSrcweir RTTypeClass * typeClass, rtl::OString * name, sal_Int32 * rank,
86cdf0e10cSrcweir std::vector< rtl::OString > * arguments)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir OSL_ASSERT(typeClass != 0 && name != 0 && rank != 0 && arguments != 0);
89cdf0e10cSrcweir *rank = 0;
90cdf0e10cSrcweir for (rtl::OString t(type);;) {
91cdf0e10cSrcweir sal_Int32 n = 0;
92cdf0e10cSrcweir *name = codemaker::UnoType::decompose(t, &n, arguments);
93cdf0e10cSrcweir if (n > SAL_MAX_INT32 - *rank) {
94cdf0e10cSrcweir throw CannotDumpException(
95cdf0e10cSrcweir errorMsg(rtl::OString(
96cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
97cdf0e10cSrcweir type));
98cdf0e10cSrcweir //TODO
99cdf0e10cSrcweir }
100cdf0e10cSrcweir *rank += n;
101cdf0e10cSrcweir if (n > 0) {
102cdf0e10cSrcweir allowVoid = false;
103cdf0e10cSrcweir allowExtraEntities = false;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir codemaker::UnoType::Sort sort = codemaker::UnoType::getSort(*name);
106cdf0e10cSrcweir switch (sort) {
107cdf0e10cSrcweir case codemaker::UnoType::SORT_VOID:
108cdf0e10cSrcweir if (!allowVoid) {
109cdf0e10cSrcweir throw CannotDumpException(
110cdf0e10cSrcweir errorMsg(rtl::OString(
111cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
112cdf0e10cSrcweir type));
113cdf0e10cSrcweir //TODO
114cdf0e10cSrcweir }
115cdf0e10cSrcweir default:
116cdf0e10cSrcweir checkNoTypeArguments(*arguments);
117cdf0e10cSrcweir *typeClass = RT_TYPE_INVALID;
118cdf0e10cSrcweir return sort;
119cdf0e10cSrcweir
120cdf0e10cSrcweir case codemaker::UnoType::SORT_COMPLEX:
121cdf0e10cSrcweir typereg::Reader reader(manager.getTypeReader(*name));
122cdf0e10cSrcweir *typeClass = reader.getTypeClass();
123cdf0e10cSrcweir switch (*typeClass) {
124cdf0e10cSrcweir case RT_TYPE_ENUM:
125cdf0e10cSrcweir case RT_TYPE_INTERFACE:
126cdf0e10cSrcweir checkNoTypeArguments(*arguments);
127cdf0e10cSrcweir return sort;
128cdf0e10cSrcweir
129cdf0e10cSrcweir case RT_TYPE_STRUCT:
130cdf0e10cSrcweir if (!(allowExtraEntities && arguments->empty())
131cdf0e10cSrcweir && (arguments->size() > SAL_MAX_UINT16
132cdf0e10cSrcweir || (static_cast< sal_uInt16 >(arguments->size())
133cdf0e10cSrcweir != reader.getReferenceCount())))
134cdf0e10cSrcweir {
135cdf0e10cSrcweir throw CannotDumpException(
136cdf0e10cSrcweir errorMsg(rtl::OString(
137cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
138cdf0e10cSrcweir type));
139cdf0e10cSrcweir //TODO
140cdf0e10cSrcweir }
141cdf0e10cSrcweir return sort;
142cdf0e10cSrcweir
143cdf0e10cSrcweir case RT_TYPE_MODULE:
144cdf0e10cSrcweir case RT_TYPE_EXCEPTION:
145cdf0e10cSrcweir case RT_TYPE_SERVICE:
146cdf0e10cSrcweir case RT_TYPE_SINGLETON:
147cdf0e10cSrcweir case RT_TYPE_CONSTANTS:
148cdf0e10cSrcweir if (!allowExtraEntities) {
149cdf0e10cSrcweir throw CannotDumpException(
150cdf0e10cSrcweir errorMsg(rtl::OString(
151cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
152cdf0e10cSrcweir type));
153cdf0e10cSrcweir //TODO
154cdf0e10cSrcweir }
155cdf0e10cSrcweir checkNoTypeArguments(*arguments);
156cdf0e10cSrcweir //TODO: check reader for consistency
157cdf0e10cSrcweir return sort;
158cdf0e10cSrcweir
159cdf0e10cSrcweir case RT_TYPE_TYPEDEF:
160cdf0e10cSrcweir checkNoTypeArguments(*arguments);
161cdf0e10cSrcweir if (reader.getSuperTypeCount() == 1
162cdf0e10cSrcweir && reader.getFieldCount() == 0
163cdf0e10cSrcweir && reader.getMethodCount() == 0
164cdf0e10cSrcweir && reader.getReferenceCount() == 0)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir if (resolveTypedefs) {
167cdf0e10cSrcweir t = convertString(reader.getSuperTypeName(0));
168cdf0e10cSrcweir continue;
169cdf0e10cSrcweir } else {
170cdf0e10cSrcweir return sort;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir }
173cdf0e10cSrcweir default:
174cdf0e10cSrcweir throw CannotDumpException(
175cdf0e10cSrcweir errorMsg(rtl::OString(
176cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
177cdf0e10cSrcweir type));
178cdf0e10cSrcweir //TODO
179cdf0e10cSrcweir }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir }
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
184cdf0e10cSrcweir }
185