tools/icheck/parser/src/shared/cplusplus/Symbol.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 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
       
    42 //
       
    43 // Permission is hereby granted, free of charge, to any person obtaining a copy
       
    44 // of this software and associated documentation files (the "Software"), to deal
       
    45 // in the Software without restriction, including without limitation the rights
       
    46 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       
    47 // copies of the Software, and to permit persons to whom the Software is
       
    48 // furnished to do so, subject to the following conditions:
       
    49 //
       
    50 // The above copyright notice and this permission notice shall be included in
       
    51 // all copies or substantial portions of the Software.
       
    52 //
       
    53 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
       
    54 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
       
    55 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
       
    56 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
       
    57 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
       
    58 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
       
    59 // THE SOFTWARE.
       
    60 
       
    61 #ifndef CPLUSPLUS_SYMBOL_H
       
    62 #define CPLUSPLUS_SYMBOL_H
       
    63 
       
    64 #include "CPlusPlusForwardDeclarations.h"
       
    65 
       
    66 
       
    67 namespace CPlusPlus {
       
    68 
       
    69 class CPLUSPLUS_EXPORT Symbol
       
    70 {
       
    71     Symbol(const Symbol &other);
       
    72     void operator =(const Symbol &other);
       
    73 
       
    74 public:
       
    75     /// Storage class specifier
       
    76     enum Storage {
       
    77         NoStorage = 0,
       
    78         Friend,
       
    79         Register,
       
    80         Static,
       
    81         Extern,
       
    82         Mutable,
       
    83         Typedef
       
    84     };
       
    85 
       
    86     /// Access specifier.
       
    87     enum Visibility {
       
    88         Public,
       
    89         Protected,
       
    90         Private,
       
    91         Package
       
    92     };
       
    93 
       
    94 public:
       
    95     /// Constructs a Symbol with the given source location, name and translation unit.
       
    96     Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
       
    97 
       
    98     /// Destroy this Symbol.
       
    99     virtual ~Symbol();
       
   100 
       
   101     /// Returns this Symbol's Control object.
       
   102     Control *control() const;
       
   103 
       
   104     /// Returns this Symbol's source location.
       
   105     unsigned sourceLocation() const;
       
   106 
       
   107     /// Returns this Symbol's source offset.
       
   108     unsigned sourceOffset() const;
       
   109 
       
   110     /// Returns this Symbol's line number.
       
   111     unsigned line() const;
       
   112 
       
   113     /// Returns this Symbol's column number.
       
   114     unsigned column() const;
       
   115 
       
   116     /// Returns this Symbol's file name.
       
   117     const StringLiteral *fileId() const;
       
   118 
       
   119     /// Returns this Symbol's file name.
       
   120     const char *fileName() const;
       
   121 
       
   122     /// Returns this Symbol's file name length.
       
   123     unsigned fileNameLength() const;
       
   124 
       
   125     unsigned startOffset() const;
       
   126     void setStartOffset(unsigned offset);
       
   127 
       
   128     unsigned endOffset() const;
       
   129     void setEndOffset(unsigned offset);
       
   130 
       
   131     void getPosition(unsigned *line, unsigned *column = 0, const StringLiteral **fileId = 0) const;
       
   132     void getStartPosition(unsigned *line, unsigned *column = 0, const StringLiteral **fileId = 0) const;
       
   133     void getEndPosition(unsigned *line, unsigned *column = 0, const StringLiteral **fileId = 0) const;
       
   134 
       
   135     /// Returns this Symbol's name.
       
   136     const Name *name() const;
       
   137 
       
   138     /// Sets this Symbol's name.
       
   139     void setName(const Name *name); // ### dangerous
       
   140 
       
   141     /// Returns this Symbol's (optional) identifier
       
   142     const Identifier *identifier() const;
       
   143 
       
   144     /// Returns this Symbol's storage class specifier.
       
   145     int storage() const;
       
   146 
       
   147     /// Sets this Symbol's storage class specifier.
       
   148     void setStorage(int storage);
       
   149 
       
   150     /// Returns this Symbol's visibility.
       
   151     int visibility() const;
       
   152 
       
   153     /// Sets this Symbol's visibility.
       
   154     void setVisibility(int visibility);
       
   155 
       
   156     /// Returns this Symbol's scope.
       
   157     Scope *scope() const;
       
   158 
       
   159     /// Returns the next chained Symbol.
       
   160     Symbol *next() const;
       
   161 
       
   162     /// Returns true if this Symbol has friend storage specifier.
       
   163     bool isFriend() const;
       
   164 
       
   165     /// Returns true if this Symbol has register storage specifier.
       
   166     bool isRegister() const;
       
   167 
       
   168     /// Returns true if this Symbol has static storage specifier.
       
   169     bool isStatic() const;
       
   170 
       
   171     /// Returns true if this Symbol has extern storage specifier.
       
   172     bool isExtern() const;
       
   173 
       
   174     /// Returns true if this Symbol has mutable storage specifier.
       
   175     bool isMutable() const;
       
   176 
       
   177     /// Returns true if this Symbol has typedef storage specifier.
       
   178     bool isTypedef() const;
       
   179 
       
   180     /// Returns true if this Symbol's visibility is public.
       
   181     bool isPublic() const;
       
   182 
       
   183     /// Returns true if this Symbol's visibility is protected.
       
   184     bool isProtected() const;
       
   185 
       
   186     /// Returns true if this Symbol's visibility is private.
       
   187     bool isPrivate() const;
       
   188 
       
   189     /// Returns true if this Symbol is a ScopedSymbol.
       
   190     bool isScopedSymbol() const;
       
   191 
       
   192     /// Returns true if this Symbol is an Enum.
       
   193     bool isEnum() const;
       
   194 
       
   195     /// Returns true if this Symbol is an Function.
       
   196     bool isFunction() const;
       
   197 
       
   198     /// Returns true if this Symbol is a Namespace.
       
   199     bool isNamespace() const;
       
   200 
       
   201     /// Returns true if this Symbol is a Class.
       
   202     bool isClass() const;
       
   203 
       
   204     /// Returns true if this Symbol is a Block.
       
   205     bool isBlock() const;
       
   206 
       
   207     /// Returns true if this Symbol is a UsingNamespaceDirective.
       
   208     bool isUsingNamespaceDirective() const;
       
   209 
       
   210     /// Returns true if this Symbol is a UsingDeclaration.
       
   211     bool isUsingDeclaration() const;
       
   212 
       
   213     /// Returns true if this Symbol is a Declaration.
       
   214     bool isDeclaration() const;
       
   215 
       
   216     /// Returns true if this Symbol is an Argument.
       
   217     bool isArgument() const;
       
   218 
       
   219     /// Returns true if this Symbol is a Typename argument.
       
   220     bool isTypenameArgument() const;
       
   221 
       
   222     /// Returns true if this Symbol is a BaseClass.
       
   223     bool isBaseClass() const;
       
   224 
       
   225     /// Returns true if this Symbol is a ForwardClassDeclaration.
       
   226     bool isForwardClassDeclaration() const;
       
   227 
       
   228     bool isObjCBaseClass() const;
       
   229     bool isObjCBaseProtocol() const;
       
   230 
       
   231     /// Returns true if this Symbol is an Objective-C Class declaration.
       
   232     bool isObjCClass() const;
       
   233 
       
   234     /// Returns true if this Symbol is an Objective-C Class forward declaration.
       
   235     bool isObjCForwardClassDeclaration() const;
       
   236 
       
   237     /// Returns true if this Symbol is an Objective-C Protocol declaration.
       
   238     bool isObjCProtocol() const;
       
   239 
       
   240     /// Returns true if this Symbol is an Objective-C Protocol forward declaration.
       
   241     bool isObjCForwardProtocolDeclaration() const;
       
   242 
       
   243     /// Returns true if this Symbol is an Objective-C method declaration.
       
   244     bool isObjCMethod() const;
       
   245 
       
   246     /// Returns true if this Symbol is an Objective-C @property declaration.
       
   247     bool isObjCPropertyDeclaration() const;
       
   248 
       
   249     virtual const ScopedSymbol *asScopedSymbol() const { return 0; }
       
   250     virtual const Enum *asEnum() const { return 0; }
       
   251     virtual const Function *asFunction() const { return 0; }
       
   252     virtual const Namespace *asNamespace() const { return 0; }
       
   253     virtual const Class *asClass() const { return 0; }
       
   254     virtual const Block *asBlock() const { return 0; }
       
   255     virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const { return 0; }
       
   256     virtual const UsingDeclaration *asUsingDeclaration() const { return 0; }
       
   257     virtual const Declaration *asDeclaration() const { return 0; }
       
   258     virtual const Argument *asArgument() const { return 0; }
       
   259     virtual const TypenameArgument *asTypenameArgument() const { return 0; }
       
   260     virtual const BaseClass *asBaseClass() const { return 0; }
       
   261     virtual const ForwardClassDeclaration *asForwardClassDeclaration() const { return 0; }
       
   262     virtual const ObjCBaseClass *asObjCBaseClass() const { return 0; }
       
   263     virtual const ObjCBaseProtocol *asObjCBaseProtocol() const { return 0; }
       
   264     virtual const ObjCClass *asObjCClass() const { return 0; }
       
   265     virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() const { return 0; }
       
   266     virtual const ObjCProtocol *asObjCProtocol() const { return 0; }
       
   267     virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() const { return 0; }
       
   268     virtual const ObjCMethod *asObjCMethod() const { return 0; }
       
   269     virtual const ObjCPropertyDeclaration *asObjCPropertyDeclaration() const { return 0; }
       
   270 
       
   271     virtual ScopedSymbol *asScopedSymbol() { return 0; }
       
   272     virtual Enum *asEnum() { return 0; }
       
   273     virtual Function *asFunction() { return 0; }
       
   274     virtual Namespace *asNamespace() { return 0; }
       
   275     virtual Class *asClass() { return 0; }
       
   276     virtual Block *asBlock() { return 0; }
       
   277     virtual UsingNamespaceDirective *asUsingNamespaceDirective() { return 0; }
       
   278     virtual UsingDeclaration *asUsingDeclaration() { return 0; }
       
   279     virtual Declaration *asDeclaration() { return 0; }
       
   280     virtual Argument *asArgument() { return 0; }
       
   281     virtual TypenameArgument *asTypenameArgument() { return 0; }
       
   282     virtual BaseClass *asBaseClass() { return 0; }
       
   283     virtual ForwardClassDeclaration *asForwardClassDeclaration() { return 0; }
       
   284     virtual ObjCBaseClass *asObjCBaseClass() { return 0; }
       
   285     virtual ObjCBaseProtocol *asObjCBaseProtocol() { return 0; }
       
   286     virtual ObjCClass *asObjCClass() { return 0; }
       
   287     virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() { return 0; }
       
   288     virtual ObjCProtocol *asObjCProtocol() { return 0; }
       
   289     virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() { return 0; }
       
   290     virtual ObjCMethod *asObjCMethod() { return 0; }
       
   291     virtual ObjCPropertyDeclaration *asObjCPropertyDeclaration() { return 0; }
       
   292 
       
   293     /// Returns this Symbol's type.
       
   294     virtual FullySpecifiedType type() const = 0;
       
   295 
       
   296     /// Returns this Symbol's hash value.
       
   297     unsigned hashCode() const;
       
   298 
       
   299     /// Returns this Symbol's index.
       
   300     unsigned index() const;
       
   301 
       
   302     const Name *identity() const;
       
   303 
       
   304     bool isGenerated() const;
       
   305 
       
   306     Symbol *enclosingSymbol() const;
       
   307 
       
   308     /// Returns the eclosing namespace scope.
       
   309     Scope *enclosingNamespaceScope() const;
       
   310 
       
   311     /// Returns the enclosing class scope.
       
   312     Scope *enclosingClassScope() const;
       
   313 
       
   314     /// Returns the enclosing enum scope.
       
   315     Scope *enclosingEnumScope() const;
       
   316 
       
   317     /// Returns the enclosing function scope.
       
   318     Scope *enclosingFunctionScope() const;
       
   319 
       
   320     /// Returns the enclosing Block scope.
       
   321     Scope *enclosingBlockScope() const;
       
   322 
       
   323     void setScope(Scope *scope); // ### make me private
       
   324     void setSourceLocation(unsigned sourceLocation); // ### make me private
       
   325 
       
   326     void visitSymbol(SymbolVisitor *visitor);
       
   327     static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);
       
   328 
       
   329 protected:
       
   330     virtual void visitSymbol0(SymbolVisitor *visitor) = 0;
       
   331 
       
   332     TranslationUnit *translationUnit() const;
       
   333 
       
   334 private:
       
   335     Control *_control;
       
   336     unsigned _sourceLocation;
       
   337     unsigned _sourceOffset;
       
   338     unsigned _startOffset;
       
   339     unsigned _endOffset;
       
   340     const Name *_name;
       
   341     unsigned _hashCode;
       
   342     int _storage;
       
   343     int _visibility;
       
   344     Scope *_scope;
       
   345     unsigned _index;
       
   346     Symbol *_next;
       
   347 
       
   348     bool _isGenerated: 1;
       
   349 
       
   350     class IdentityForName;
       
   351     class HashCode;
       
   352 
       
   353     friend class Scope;
       
   354 };
       
   355 
       
   356 } // end of namespace CPlusPlus
       
   357 
       
   358 
       
   359 #endif // CPLUSPLUS_SYMBOL_H