File: | idlc/source/idlc.cxx |
Location: | line 112, column 5 |
Description: | Called C++ object pointer is null |
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/idlc.hxx> | |||
21 | #include <idlc/errorhandler.hxx> | |||
22 | #include <idlc/astscope.hxx> | |||
23 | #include <idlc/astmodule.hxx> | |||
24 | #include <idlc/astservice.hxx> | |||
25 | #include <idlc/astconstants.hxx> | |||
26 | #include <idlc/astexception.hxx> | |||
27 | #include <idlc/astunion.hxx> | |||
28 | #include <idlc/astenum.hxx> | |||
29 | #include <idlc/astinterface.hxx> | |||
30 | #include <idlc/astoperation.hxx> | |||
31 | #include <idlc/astbasetype.hxx> | |||
32 | #include "idlc/astdeclaration.hxx" | |||
33 | #include "idlc/astparameter.hxx" | |||
34 | #include "idlc/astsequence.hxx" | |||
35 | #include "idlc/asttype.hxx" | |||
36 | #include "idlc/asttypedef.hxx" | |||
37 | ||||
38 | #include <osl/diagnose.h> | |||
39 | #include <osl/file.hxx> | |||
40 | #include <osl/thread.h> | |||
41 | ||||
42 | using namespace ::rtl; | |||
43 | ||||
44 | AstDeclaration* SAL_CALL scopeAsDecl(AstScope* pScope) | |||
45 | { | |||
46 | if (pScope == NULL__null) return NULL__null; | |||
47 | ||||
48 | switch( pScope->getScopeNodeType() ) | |||
49 | { | |||
50 | case NT_service: | |||
51 | case NT_singleton: | |||
52 | return (AstService*)(pScope); | |||
53 | case NT_module: | |||
54 | case NT_root: | |||
55 | return (AstModule*)(pScope); | |||
56 | case NT_constants: | |||
57 | return (AstConstants*)(pScope); | |||
58 | case NT_interface: | |||
59 | return (AstInterface*)(pScope); | |||
60 | case NT_operation: | |||
61 | return (AstOperation*)(pScope); | |||
62 | case NT_exception: | |||
63 | return (AstException*)(pScope); | |||
64 | case NT_union: | |||
65 | return (AstUnion*)(pScope); | |||
66 | case NT_struct: | |||
67 | return (AstStruct*)(pScope); | |||
68 | case NT_enum: | |||
69 | return (AstEnum*)(pScope); | |||
70 | default: | |||
71 | return NULL__null; | |||
72 | } | |||
73 | } | |||
74 | ||||
75 | AstScope* SAL_CALL declAsScope(AstDeclaration* pDecl) | |||
76 | { | |||
77 | if (pDecl == NULL__null) return NULL__null; | |||
78 | ||||
79 | switch(pDecl->getNodeType()) | |||
80 | { | |||
81 | case NT_interface: | |||
82 | return (AstInterface*)(pDecl); | |||
83 | case NT_service: | |||
84 | case NT_singleton: | |||
85 | return (AstService*)(pDecl); | |||
86 | case NT_module: | |||
87 | case NT_root: | |||
88 | return (AstModule*)(pDecl); | |||
89 | case NT_constants: | |||
90 | return (AstConstants*)(pDecl); | |||
91 | case NT_exception: | |||
92 | return (AstException*)(pDecl); | |||
93 | case NT_union: | |||
94 | return (AstUnion*)(pDecl); | |||
95 | case NT_struct: | |||
96 | return (AstStruct*)(pDecl); | |||
97 | case NT_enum: | |||
98 | return (AstEnum*)(pDecl); | |||
99 | case NT_operation: | |||
100 | return (AstOperation*)(pDecl); | |||
101 | default: | |||
102 | return NULL__null; | |||
103 | } | |||
104 | } | |||
105 | ||||
106 | static void SAL_CALL predefineXInterface(AstModule* pRoot) | |||
107 | { | |||
108 | // define the modules com::sun::star::uno | |||
109 | AstModule* pParentScope = pRoot; | |||
110 | AstModule* pModule = new AstModule(OString("com"), pParentScope); | |||
111 | pModule->setPredefined(true); | |||
112 | pParentScope->addDeclaration(pModule); | |||
| ||||
113 | pParentScope = pModule; | |||
114 | pModule = new AstModule(OString("sun"), pParentScope); | |||
115 | pModule->setPredefined(true); | |||
116 | pParentScope->addDeclaration(pModule); | |||
117 | pParentScope = pModule; | |||
118 | pModule = new AstModule(OString("star"), pParentScope); | |||
119 | pModule->setPredefined(true); | |||
120 | pParentScope->addDeclaration(pModule); | |||
121 | pParentScope = pModule; | |||
122 | pModule = new AstModule(OString("uno"), pParentScope); | |||
123 | pModule->setPredefined(true); | |||
124 | pParentScope->addDeclaration(pModule); | |||
125 | pParentScope = pModule; | |||
126 | ||||
127 | // define XInterface | |||
128 | AstInterface* pInterface = new AstInterface(OString("XInterface"), NULL__null, pParentScope); | |||
129 | pInterface->setDefined(); | |||
130 | pInterface->setPredefined(true); | |||
131 | pInterface->setPublished(); | |||
132 | pParentScope->addDeclaration(pInterface); | |||
133 | ||||
134 | // define XInterface::queryInterface | |||
135 | AstOperation* pOp = new AstOperation(0, (AstType*)(pRoot->lookupPrimitiveType(ET_any)), | |||
136 | OString("queryInterface"), pInterface); | |||
137 | AstParameter* pParam = new AstParameter(DIR_IN, false, | |||
138 | (AstType*)(pRoot->lookupPrimitiveType(ET_type)), | |||
139 | OString("aType"), pOp); | |||
140 | pOp->addDeclaration(pParam); | |||
141 | pInterface->addMember(pOp); | |||
142 | ||||
143 | // define XInterface::acquire | |||
144 | pOp = new AstOperation(1, (AstType*)(pRoot->lookupPrimitiveType(ET_void)), | |||
145 | OString("acquire"), pInterface); | |||
146 | pInterface->addMember(pOp); | |||
147 | ||||
148 | // define XInterface::release | |||
149 | pOp = new AstOperation(1, (AstType*)(pRoot->lookupPrimitiveType(ET_void)), | |||
150 | OString("release"), pInterface); | |||
151 | pInterface->addMember(pOp); | |||
152 | } | |||
153 | ||||
154 | static void SAL_CALL initializePredefinedTypes(AstModule* pRoot) | |||
155 | { | |||
156 | AstBaseType* pPredefined = NULL__null; | |||
157 | if ( pRoot ) | |||
158 | { | |||
159 | pPredefined = new AstBaseType(ET_long, OString("long"), pRoot); | |||
160 | pRoot->addDeclaration(pPredefined); | |||
161 | ||||
162 | pPredefined = new AstBaseType(ET_ulong, OString("unsigned long"), pRoot); | |||
163 | pRoot->addDeclaration(pPredefined); | |||
164 | ||||
165 | pPredefined = new AstBaseType(ET_hyper, OString("hyper"), pRoot); | |||
166 | pRoot->addDeclaration(pPredefined); | |||
167 | ||||
168 | pPredefined = new AstBaseType(ET_uhyper, OString("unsigned hyper"), pRoot); | |||
169 | pRoot->addDeclaration(pPredefined); | |||
170 | ||||
171 | pPredefined = new AstBaseType(ET_short, OString("short"), pRoot); | |||
172 | pRoot->addDeclaration(pPredefined); | |||
173 | ||||
174 | pPredefined = new AstBaseType(ET_ushort, OString("unsigned short"), pRoot); | |||
175 | pRoot->addDeclaration(pPredefined); | |||
176 | ||||
177 | pPredefined = new AstBaseType(ET_float, OString("float"), pRoot); | |||
178 | pRoot->addDeclaration(pPredefined); | |||
179 | ||||
180 | pPredefined = new AstBaseType(ET_double, OString("double"), pRoot); | |||
181 | pRoot->addDeclaration(pPredefined); | |||
182 | ||||
183 | pPredefined = new AstBaseType(ET_char, OString("char"), pRoot); | |||
184 | pRoot->addDeclaration(pPredefined); | |||
185 | ||||
186 | pPredefined = new AstBaseType(ET_byte, OString("byte"), pRoot); | |||
187 | pRoot->addDeclaration(pPredefined); | |||
188 | ||||
189 | pPredefined = new AstBaseType(ET_any, OString("any"), pRoot); | |||
190 | pRoot->addDeclaration(pPredefined); | |||
191 | ||||
192 | pPredefined = new AstBaseType(ET_string, OString("string"), pRoot); | |||
193 | pRoot->addDeclaration(pPredefined); | |||
194 | ||||
195 | pPredefined = new AstBaseType(ET_type, OString("type"), pRoot); | |||
196 | pRoot->addDeclaration(pPredefined); | |||
197 | ||||
198 | pPredefined = new AstBaseType(ET_boolean, OString("boolean"), pRoot); | |||
199 | pRoot->addDeclaration(pPredefined); | |||
200 | ||||
201 | pPredefined = new AstBaseType(ET_void, OString("void"), pRoot); | |||
202 | pRoot->addDeclaration(pPredefined); | |||
203 | } | |||
204 | } | |||
205 | ||||
206 | Idlc::Idlc(Options* pOptions) | |||
207 | : m_pOptions(pOptions) | |||
208 | , m_bIsDocValid(sal_False((sal_Bool)0)) | |||
209 | , m_bIsInMainfile(sal_True((sal_Bool)1)) | |||
210 | , m_published(false) | |||
211 | , m_errorCount(0) | |||
212 | , m_warningCount(0) | |||
213 | , m_lineNumber(0) | |||
214 | , m_offsetStart(0) | |||
215 | , m_offsetEnd(0) | |||
216 | , m_parseState(PS_NoState) | |||
217 | { | |||
218 | m_pScopes = new AstStack(); | |||
219 | // init root object after construction | |||
220 | m_pRoot = NULL__null; | |||
221 | m_pErrorHandler = new ErrorHandler(); | |||
222 | m_bGenerateDoc = m_pOptions->isValid("-C"); | |||
223 | } | |||
224 | ||||
225 | Idlc::~Idlc() | |||
226 | { | |||
227 | if (m_pRoot) | |||
228 | delete m_pRoot; | |||
229 | if (m_pScopes) | |||
230 | delete m_pScopes; | |||
231 | if (m_pErrorHandler) | |||
232 | delete m_pErrorHandler; | |||
233 | } | |||
234 | ||||
235 | void Idlc::init() | |||
236 | { | |||
237 | if ( m_pRoot ) | |||
238 | delete m_pRoot; | |||
239 | ||||
240 | m_pRoot = new AstModule(NT_root, OString(), NULL__null); | |||
241 | ||||
242 | // push the root node on the stack | |||
243 | m_pScopes->push(m_pRoot); | |||
244 | initializePredefinedTypes(m_pRoot); | |||
245 | predefineXInterface(m_pRoot); | |||
246 | } | |||
247 | ||||
248 | void Idlc::reset() | |||
249 | { | |||
250 | m_bIsDocValid = sal_False((sal_Bool)0); | |||
251 | m_bIsInMainfile = sal_True((sal_Bool)1); | |||
252 | m_published = false; | |||
253 | ||||
254 | m_errorCount = 0; | |||
255 | m_warningCount = 0; | |||
256 | m_lineNumber = 0; | |||
257 | m_parseState = PS_NoState; | |||
258 | ||||
259 | m_fileName = OString(); | |||
260 | m_mainFileName = OString(); | |||
261 | m_realFileName = OString(); | |||
262 | m_documentation = OString(); | |||
263 | ||||
264 | m_pScopes->clear(); | |||
265 | if ( m_pRoot) | |||
266 | delete m_pRoot; | |||
267 | ||||
268 | m_pRoot = new AstModule(NT_root, OString(), NULL__null); | |||
269 | ||||
270 | // push the root node on the stack | |||
271 | m_pScopes->push(m_pRoot); | |||
272 | initializePredefinedTypes(m_pRoot); | |||
273 | } | |||
274 | ||||
275 | sal_Bool Idlc::isDocValid() | |||
276 | { | |||
277 | if ( m_bGenerateDoc ) | |||
278 | return m_bIsDocValid; | |||
279 | return sal_False((sal_Bool)0);; | |||
280 | } | |||
281 | ||||
282 | static void lcl_writeString(::osl::File & rFile, ::osl::FileBase::RC & o_rRC, | |||
283 | ::rtl::OString const& rString) | |||
284 | { | |||
285 | sal_uInt64 nWritten(0); | |||
286 | if (::osl::FileBase::E_None == o_rRC) { | |||
287 | o_rRC = rFile.write(rString.getStr(), rString.getLength(), nWritten); | |||
288 | if (static_cast<sal_uInt64>(rString.getLength()) != nWritten) { | |||
289 | o_rRC = ::osl::FileBase::E_INVAL; //? | |||
290 | } | |||
291 | } | |||
292 | } | |||
293 | ||||
294 | struct WriteDep | |||
295 | { | |||
296 | ::osl::File& m_rFile; | |||
297 | ::osl::FileBase::RC & m_rRC; | |||
298 | explicit WriteDep(::osl::File & rFile, ::osl::FileBase::RC & rRC) | |||
299 | : m_rFile(rFile), m_rRC(rRC) { } | |||
300 | void operator() (::rtl::OString const& rEntry) | |||
301 | { | |||
302 | lcl_writeString(m_rFile, m_rRC, " \\\n "); | |||
303 | lcl_writeString(m_rFile, m_rRC, rEntry); | |||
304 | } | |||
305 | }; | |||
306 | ||||
307 | // write a dummy target for one included file, so the incremental build does | |||
308 | // not break with "No rule to make target" if the included file is removed | |||
309 | struct WriteDummy | |||
310 | { | |||
311 | ::osl::File& m_rFile; | |||
312 | ::osl::FileBase::RC & m_rRC; | |||
313 | explicit WriteDummy(::osl::File & rFile, ::osl::FileBase::RC & rRC) | |||
314 | : m_rFile(rFile), m_rRC(rRC) { } | |||
315 | void operator() (::rtl::OString const& rEntry) | |||
316 | { | |||
317 | lcl_writeString(m_rFile, m_rRC, rEntry); | |||
318 | lcl_writeString(m_rFile, m_rRC, ":\n\n"); | |||
319 | } | |||
320 | }; | |||
321 | ||||
322 | bool | |||
323 | Idlc::dumpDeps(::rtl::OString const& rDepFile, ::rtl::OString const& rTarget) | |||
324 | { | |||
325 | ::osl::File depFile( | |||
326 | ::rtl::OStringToOUString(rDepFile, osl_getThreadTextEncoding())); | |||
327 | ::osl::FileBase::RC rc = | |||
328 | depFile.open(osl_File_OpenFlag_Write0x00000002L | osl_File_OpenFlag_Create0x00000004L); | |||
329 | if (::osl::FileBase::E_None != rc) { | |||
330 | return false; | |||
331 | } | |||
332 | lcl_writeString(depFile, rc, rTarget); | |||
333 | if (::osl::FileBase::E_None != rc) { | |||
334 | return false; | |||
335 | } | |||
336 | lcl_writeString(depFile, rc, " :"); | |||
337 | if (::osl::FileBase::E_None != rc) { | |||
338 | return false; | |||
339 | } | |||
340 | m_includes.erase(getRealFileName()); // eeek, that is a temp file... | |||
341 | ::std::for_each(m_includes.begin(), m_includes.end(), | |||
342 | WriteDep(depFile, rc)); | |||
343 | lcl_writeString(depFile, rc, "\n\n"); | |||
344 | ::std::for_each(m_includes.begin(), m_includes.end(), | |||
345 | WriteDummy(depFile, rc)); | |||
346 | if (::osl::FileBase::E_None != rc) { | |||
347 | return false; | |||
348 | } | |||
349 | rc = depFile.close(); | |||
350 | return ::osl::FileBase::E_None == rc; | |||
351 | } | |||
352 | ||||
353 | static Idlc* pStaticIdlc = NULL__null; | |||
354 | ||||
355 | Idlc* SAL_CALL idlc() | |||
356 | { | |||
357 | return pStaticIdlc; | |||
358 | } | |||
359 | ||||
360 | Idlc* SAL_CALL setIdlc(Options* pOptions) | |||
361 | { | |||
362 | if ( pStaticIdlc ) | |||
| ||||
363 | { | |||
364 | delete pStaticIdlc; | |||
365 | } | |||
366 | pStaticIdlc = new Idlc(pOptions); | |||
367 | pStaticIdlc->init(); | |||
368 | return pStaticIdlc; | |||
369 | } | |||
370 | ||||
371 | AstDeclaration const * resolveTypedefs(AstDeclaration const * type) { | |||
372 | if (type != 0) { | |||
373 | while (type->getNodeType() == NT_typedef) { | |||
374 | type = static_cast< AstTypeDef const * >(type)->getBaseType(); | |||
375 | } | |||
376 | } | |||
377 | return type; | |||
378 | } | |||
379 | ||||
380 | AstDeclaration const * deconstructAndResolveTypedefs( | |||
381 | AstDeclaration const * type, sal_Int32 * rank) | |||
382 | { | |||
383 | *rank = 0; | |||
384 | for (;;) { | |||
385 | if (type == 0) { | |||
386 | return 0; | |||
387 | } | |||
388 | switch (type->getNodeType()) { | |||
389 | case NT_typedef: | |||
390 | type = static_cast< AstTypeDef const * >(type)->getBaseType(); | |||
391 | break; | |||
392 | case NT_sequence: | |||
393 | ++(*rank); | |||
394 | type = static_cast< AstSequence const * >(type)->getMemberType(); | |||
395 | break; | |||
396 | default: | |||
397 | return type; | |||
398 | } | |||
399 | } | |||
400 | } | |||
401 | ||||
402 | AstInterface const * resolveInterfaceTypedefs(AstType const * type) { | |||
403 | AstDeclaration const * decl = resolveTypedefs(type); | |||
404 | OSL_ASSERT(decl->getNodeType() == NT_interface)do { if (true && (!(decl->getNodeType() == NT_interface ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/idlc/source/idlc.cxx" ":" "404" ": "), "OSL_ASSERT: %s", "decl->getNodeType() == NT_interface" ); } } while (false); | |||
405 | return static_cast< AstInterface const * >(decl); | |||
406 | } | |||
407 | ||||
408 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |