tools/icheck/parser/src/libs/cplusplus/CppBindings.h
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    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 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef CPPBINDINGS_H
       
    43 #define CPPBINDINGS_H
       
    44 
       
    45 #include "CppDocument.h"
       
    46 
       
    47 #include <QtCore/QList>
       
    48 #include <QtCore/QSharedPointer>
       
    49 #include <QtCore/QString>
       
    50 #include <QtCore/QByteArray>
       
    51 
       
    52 namespace CPlusPlus {
       
    53 
       
    54 class Location;
       
    55 class Binding;
       
    56 class NamespaceBinding;
       
    57 class ClassBinding;
       
    58 
       
    59 typedef QSharedPointer<Binding> BindingPtr;
       
    60 typedef QSharedPointer<ClassBinding> ClassBindingPtr;
       
    61 typedef QSharedPointer<NamespaceBinding> NamespaceBindingPtr;
       
    62 
       
    63 class CPLUSPLUS_EXPORT Location
       
    64 {
       
    65 public:
       
    66     Location();
       
    67     Location(Symbol *symbol);
       
    68     Location(const StringLiteral *fileId, unsigned sourceLocation);
       
    69 
       
    70     inline bool isValid() const
       
    71     { return _fileId != 0; }
       
    72 
       
    73     inline operator bool() const
       
    74     { return _fileId != 0; }
       
    75 
       
    76     inline const StringLiteral *fileId() const
       
    77     { return _fileId; }
       
    78 
       
    79     inline unsigned sourceLocation() const
       
    80     { return _sourceLocation; }
       
    81 
       
    82 private:
       
    83     const StringLiteral *_fileId;
       
    84     unsigned _sourceLocation;
       
    85 };
       
    86 
       
    87 class CPLUSPLUS_EXPORT Binding
       
    88 {
       
    89     Q_DISABLE_COPY(Binding)
       
    90 
       
    91 public:
       
    92     Binding() {}
       
    93     virtual ~Binding() {}
       
    94 
       
    95     virtual QByteArray qualifiedId() const = 0;
       
    96     virtual NamespaceBinding *asNamespaceBinding() { return 0; }
       
    97     virtual ClassBinding *asClassBinding() { return 0; }
       
    98 
       
    99     virtual ClassBinding *findClassBinding(const Name *name, QSet<Binding *> *processed) = 0;
       
   100     virtual Binding *findClassOrNamespaceBinding(const Identifier *id, QSet<Binding *> *processed) = 0;
       
   101 };
       
   102 
       
   103 class CPLUSPLUS_EXPORT NamespaceBinding: public Binding
       
   104 {
       
   105 public:
       
   106     /// Constructs a binding with the given parent.
       
   107     NamespaceBinding(NamespaceBinding *parent = 0);
       
   108 
       
   109     /// Destroys the binding.
       
   110     virtual ~NamespaceBinding();
       
   111 
       
   112     /// Returns this binding's name.
       
   113     const NameId *name() const;
       
   114 
       
   115     /// Returns this binding's identifier.
       
   116     const Identifier *identifier() const;
       
   117 
       
   118     /// Returns the binding for the global namespace (aka ::).
       
   119     NamespaceBinding *globalNamespaceBinding();
       
   120 
       
   121     /// Returns the binding for the given namespace symbol.
       
   122     NamespaceBinding *findNamespaceBinding(const Name *name);
       
   123 
       
   124     /// Returns the binding associated with the given symbol.
       
   125     NamespaceBinding *findOrCreateNamespaceBinding(Namespace *symbol);
       
   126 
       
   127     NamespaceBinding *resolveNamespace(const Location &loc,
       
   128                                        const Name *name,
       
   129                                        bool lookAtParent = true);
       
   130 
       
   131     virtual ClassBinding *findClassBinding(const Name *name, QSet<Binding *> *processed);
       
   132     virtual Binding *findClassOrNamespaceBinding(const Identifier *id, QSet<Binding *> *processed);
       
   133 
       
   134     /// Helpers.
       
   135     virtual QByteArray qualifiedId() const;
       
   136     void dump();
       
   137 
       
   138     virtual NamespaceBinding *asNamespaceBinding() { return this; }
       
   139 
       
   140     static NamespaceBinding *find(Namespace *symbol, NamespaceBinding *binding);
       
   141     static ClassBinding *find(Class *symbol, NamespaceBinding *binding);
       
   142 
       
   143 private:
       
   144     NamespaceBinding *findNamespaceBindingForNameId(const NameId *name,
       
   145                                                     bool lookAtParentNamespace);
       
   146 
       
   147     NamespaceBinding *findNamespaceBindingForNameId_helper(const NameId *name,
       
   148                                                            bool lookAtParentNamespace,
       
   149                                                            QSet<NamespaceBinding *> *processed);
       
   150 
       
   151 public: // attributes
       
   152     /// This binding's parent.
       
   153     NamespaceBinding *parent;
       
   154 
       
   155     /// Binding for anonymous namespace symbols.
       
   156     NamespaceBinding *anonymousNamespaceBinding;
       
   157 
       
   158     /// This binding's connections.
       
   159     QList<NamespaceBinding *> children;
       
   160 
       
   161     /// This binding's list of using namespaces.
       
   162     QList<NamespaceBinding *> usings;
       
   163 
       
   164     /// This binding's namespace symbols.
       
   165     QList<Namespace *> symbols;
       
   166 
       
   167     QList<ClassBinding *> classBindings;
       
   168 };
       
   169 
       
   170 class CPLUSPLUS_EXPORT ClassBinding: public Binding
       
   171 {
       
   172 public:
       
   173     ClassBinding(NamespaceBinding *parent);
       
   174     ClassBinding(ClassBinding *parentClass);
       
   175     virtual ~ClassBinding();
       
   176 
       
   177     virtual ClassBinding *asClassBinding() { return this; }
       
   178 
       
   179     /// Returns this binding's name.
       
   180     const Name *name() const;
       
   181 
       
   182     /// Returns this binding's identifier.
       
   183     const Identifier *identifier() const;
       
   184     virtual QByteArray qualifiedId() const;
       
   185 
       
   186     virtual ClassBinding *findClassBinding(const Name *name, QSet<Binding *> *processed);
       
   187     virtual Binding *findClassOrNamespaceBinding(const Identifier *id, QSet<Binding *> *processed);
       
   188 
       
   189     void dump();
       
   190 
       
   191 public: // attributes
       
   192     Binding *parent;
       
   193 
       
   194     QList<ClassBinding *> children;
       
   195 
       
   196     /// This binding's class symbols.
       
   197     QList<Class *> symbols;
       
   198 
       
   199     /// Bindings for the base classes.
       
   200     QList<ClassBinding *> baseClassBindings;
       
   201 };
       
   202 
       
   203 CPLUSPLUS_EXPORT NamespaceBindingPtr bind(Document::Ptr doc, Snapshot snapshot);
       
   204 
       
   205 } // end of namespace CPlusPlus
       
   206 
       
   207 #endif // CPPBINDINGS_H