Branch data 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/astenum.hxx>
21 : :
22 : : #include "registry/version.h"
23 : : #include "registry/writer.hxx"
24 : :
25 : : using namespace ::rtl;
26 : :
27 : 5727 : AstEnum::AstEnum(const ::rtl::OString& name, AstScope* pScope)
28 : : : AstType(NT_enum, name, pScope)
29 : : , AstScope(NT_enum)
30 [ + - ]: 5727 : , m_enumValueCount(0)
31 : : {
32 : 5727 : }
33 : :
34 [ # # ]: 0 : AstEnum::~AstEnum()
35 : : {
36 [ # # ]: 0 : }
37 : :
38 : 78602 : AstConstant* AstEnum::checkValue(AstExpression* pExpr)
39 : : {
40 : 78602 : DeclList::const_iterator iter = getIteratorBegin();
41 : 78602 : DeclList::const_iterator end = getIteratorEnd();
42 : 78602 : AstConstant* pConst = NULL;
43 : 78602 : AstDeclaration* pDecl = NULL;
44 : :
45 [ + + ]: 1194617 : while ( iter != end)
46 : : {
47 : 1116015 : pDecl = *iter;
48 : 1116015 : pConst = (AstConstant*)pDecl;
49 : :
50 [ - + ][ + - ]: 1116015 : if (pConst->getConstValue()->compare(pExpr))
51 : 0 : return pConst;
52 : :
53 : 1116015 : ++iter;
54 : : }
55 : :
56 [ + + ]: 78602 : if ( pExpr->getExprValue()->u.lval > m_enumValueCount )
57 : 531 : m_enumValueCount = pExpr->getExprValue()->u.lval + 1;
58 : :
59 : 78602 : return NULL;
60 : : }
61 : :
62 : 261 : sal_Bool AstEnum::dump(RegistryKey& rKey)
63 : : {
64 [ + - ]: 261 : RegistryKey localKey;
65 [ + - ][ + - ]: 261 : if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
[ - + ]
66 : : {
67 : : fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
68 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
69 [ # # ][ # # ]: 0 : getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
70 : 0 : return sal_False;
71 : : }
72 : :
73 : 261 : OUString emptyStr;
74 [ + - ]: 261 : sal_uInt16 nConst = getNodeCount(NT_enum_val);
75 [ + - ]: 261 : if ( nConst > 0 )
76 : : {
77 : : typereg::Writer aBlob(
78 : : m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
79 : 261 : getDocumentation(), emptyStr, RT_TYPE_ENUM, m_bPublished,
80 [ + - ]: 261 : OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
81 [ + - + + ]: 522 : nConst, 0, 0);
[ + - ]
82 : :
83 : 261 : DeclList::const_iterator iter = getIteratorBegin();
84 : 261 : DeclList::const_iterator end = getIteratorEnd();
85 : 261 : AstDeclaration* pDecl = NULL;
86 : 261 : sal_uInt16 index = 0;
87 [ + + ]: 2182 : while ( iter != end )
88 : : {
89 : 1921 : pDecl = *iter;
90 [ + - ]: 1921 : if ( pDecl->getNodeType() == NT_enum_val )
91 [ + - ]: 1921 : ((AstConstant*)pDecl)->dumpBlob(aBlob, index++, false);
92 : :
93 : 1921 : ++iter;
94 : : }
95 : :
96 : : sal_uInt32 aBlobSize;
97 [ + - ]: 261 : void const * pBlob = aBlob.getBlob(&aBlobSize);
98 : :
99 [ - + ]: 261 : if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
100 [ + - ]: 261 : (RegValue)pBlob, aBlobSize))
101 : : {
102 : : fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
103 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
104 [ # # ][ # # ]: 0 : getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
105 : 261 : return sal_False;
106 [ + - ]: 261 : }
107 : : }
108 : :
109 [ + - ]: 261 : return sal_True;
110 : : }
111 : :
112 : 78602 : AstDeclaration* AstEnum::addDeclaration(AstDeclaration* pDecl)
113 : : {
114 : 78602 : return AstScope::addDeclaration(pDecl);
115 : : }
116 : :
117 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|