OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / libs / cplusplus / LookupItem.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "LookupItem.h"
34 #include <FullySpecifiedType.h>
35 #include <Symbol.h>
36 #include <Control.h>
37
38 #include <QtDebug>
39
40 using namespace CPlusPlus;
41
42 uint CPlusPlus::qHash(const CPlusPlus::LookupItem &key)
43 {
44     const uint h1 = QT_PREPEND_NAMESPACE(qHash)(key.type().type());
45     const uint h2 = QT_PREPEND_NAMESPACE(qHash)(key.scope());
46     return ((h1 << 16) | (h1 >> 16)) ^ h2;
47 }
48
49 LookupItem::LookupItem()
50     : _scope(0), _declaration(0), _binding(0)
51 { }
52
53 FullySpecifiedType LookupItem::type() const
54 {
55     if (! _type && _declaration)
56         return _declaration->type();
57
58     return _type;
59 }
60
61 void LookupItem::setType(const FullySpecifiedType &type)
62 { _type = type; }
63
64 Symbol *LookupItem::declaration() const
65 { return _declaration; }
66
67 void LookupItem::setDeclaration(Symbol *declaration)
68 { _declaration = declaration; }
69
70 Scope *LookupItem::scope() const
71 {
72     if (! _scope && _declaration)
73         return _declaration->enclosingScope();
74
75     return _scope;
76 }
77
78 void LookupItem::setScope(Scope *scope)
79 { _scope = scope; }
80
81 ClassOrNamespace *LookupItem::binding() const
82 { return _binding; }
83
84 void LookupItem::setBinding(ClassOrNamespace *binding)
85 { _binding = binding; }
86
87 bool LookupItem::operator == (const LookupItem &other) const
88 {
89     if (_type == other._type && _declaration == other._declaration && _scope == other._scope
90             && _binding == other._binding)
91         return true;
92
93     return false;
94 }
95
96 bool LookupItem::operator != (const LookupItem &result) const
97 { return ! operator == (result); }