tools/icheck/parser/src/shared/cplusplus/Names.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_NAMES_H
       
    62 #define CPLUSPLUS_NAMES_H
       
    63 
       
    64 #include "CPlusPlusForwardDeclarations.h"
       
    65 #include "Name.h"
       
    66 #include "FullySpecifiedType.h"
       
    67 #include <vector>
       
    68 
       
    69 namespace CPlusPlus {
       
    70 
       
    71 class CPLUSPLUS_EXPORT QualifiedNameId: public Name
       
    72 {
       
    73 public:
       
    74     template <typename _Iterator>
       
    75     QualifiedNameId(_Iterator first, _Iterator last, bool isGlobal = false)
       
    76         : _names(first, last), _isGlobal(isGlobal) {}
       
    77 
       
    78     virtual ~QualifiedNameId();
       
    79 
       
    80     virtual const Identifier *identifier() const;
       
    81 
       
    82     unsigned nameCount() const;
       
    83     const Name *nameAt(unsigned index) const;
       
    84     const Name *unqualifiedNameId() const;
       
    85     const Name *const *names() const { return &_names[0]; } // ### remove me
       
    86     bool isGlobal() const;
       
    87 
       
    88     virtual bool isEqualTo(const Name *other) const;
       
    89 
       
    90     virtual const QualifiedNameId *asQualifiedNameId() const
       
    91     { return this; }
       
    92 
       
    93     typedef std::vector<const Name *>::const_iterator NameIterator;
       
    94 
       
    95     NameIterator firstName() const { return _names.begin(); }
       
    96     NameIterator lastName() const { return _names.end(); }
       
    97 
       
    98 protected:
       
    99     virtual void accept0(NameVisitor *visitor) const;
       
   100 
       
   101 private:
       
   102     std::vector<const Name *> _names;
       
   103     bool _isGlobal;
       
   104 };
       
   105 
       
   106 class CPLUSPLUS_EXPORT NameId: public Name
       
   107 {
       
   108 public:
       
   109     NameId(const Identifier *identifier);
       
   110     virtual ~NameId();
       
   111 
       
   112     virtual const Identifier *identifier() const;
       
   113 
       
   114     virtual bool isEqualTo(const Name *other) const;
       
   115 
       
   116     virtual const NameId *asNameId() const
       
   117     { return this; }
       
   118 
       
   119 protected:
       
   120     virtual void accept0(NameVisitor *visitor) const;
       
   121 
       
   122 private:
       
   123     const Identifier *_identifier;
       
   124 };
       
   125 
       
   126 class CPLUSPLUS_EXPORT DestructorNameId: public Name
       
   127 {
       
   128 public:
       
   129     DestructorNameId(const Identifier *identifier);
       
   130     virtual ~DestructorNameId();
       
   131 
       
   132     virtual const Identifier *identifier() const;
       
   133 
       
   134     virtual bool isEqualTo(const Name *other) const;
       
   135 
       
   136     virtual const DestructorNameId *asDestructorNameId() const
       
   137     { return this; }
       
   138 
       
   139 protected:
       
   140     virtual void accept0(NameVisitor *visitor) const;
       
   141 
       
   142 private:
       
   143     const Identifier *_identifier;
       
   144 };
       
   145 
       
   146 class CPLUSPLUS_EXPORT TemplateNameId: public Name
       
   147 {
       
   148 public:
       
   149     template <typename _Iterator>
       
   150     TemplateNameId(const Identifier *identifier, _Iterator first, _Iterator last)
       
   151         : _identifier(identifier), _templateArguments(first, last) {}
       
   152 
       
   153     virtual ~TemplateNameId();
       
   154 
       
   155     virtual const Identifier *identifier() const;
       
   156 
       
   157     // ### find a better name
       
   158     unsigned templateArgumentCount() const;
       
   159     const FullySpecifiedType &templateArgumentAt(unsigned index) const;
       
   160 
       
   161     virtual bool isEqualTo(const Name *other) const;
       
   162 
       
   163     virtual const TemplateNameId *asTemplateNameId() const
       
   164     { return this; }
       
   165 
       
   166     typedef std::vector<FullySpecifiedType>::const_iterator TemplateArgumentIterator;
       
   167 
       
   168     TemplateArgumentIterator firstTemplateArgument() const { return _templateArguments.begin(); }
       
   169     TemplateArgumentIterator lastTemplateArgument() const { return _templateArguments.end(); }
       
   170 
       
   171 protected:
       
   172     virtual void accept0(NameVisitor *visitor) const;
       
   173 
       
   174 private:
       
   175     const Identifier *_identifier;
       
   176     std::vector<FullySpecifiedType> _templateArguments;
       
   177 };
       
   178 
       
   179 class CPLUSPLUS_EXPORT OperatorNameId: public Name
       
   180 {
       
   181 public:
       
   182     /*
       
   183         new  delete    new[]     delete[]
       
   184         +    -    *    /    %    ^    &    |    ~
       
   185         !    =    <    >    +=   -=   *=   /=   %=
       
   186         ^=   &=   |=   <<   >>   >>=  <<=  ==   !=
       
   187         <=   >=   &&   ||   ++   --   ,    ->*  ->
       
   188         ()   []
       
   189      */
       
   190     enum Kind {
       
   191         InvalidOp,
       
   192         NewOp,
       
   193         DeleteOp,
       
   194         NewArrayOp,
       
   195         DeleteArrayOp,
       
   196         PlusOp,
       
   197         MinusOp,
       
   198         StarOp,
       
   199         SlashOp,
       
   200         PercentOp,
       
   201         CaretOp,
       
   202         AmpOp,
       
   203         PipeOp,
       
   204         TildeOp,
       
   205         ExclaimOp,
       
   206         EqualOp,
       
   207         LessOp,
       
   208         GreaterOp,
       
   209         PlusEqualOp,
       
   210         MinusEqualOp,
       
   211         StarEqualOp,
       
   212         SlashEqualOp,
       
   213         PercentEqualOp,
       
   214         CaretEqualOp,
       
   215         AmpEqualOp,
       
   216         PipeEqualOp,
       
   217         LessLessOp,
       
   218         GreaterGreaterOp,
       
   219         LessLessEqualOp,
       
   220         GreaterGreaterEqualOp,
       
   221         EqualEqualOp,
       
   222         ExclaimEqualOp,
       
   223         LessEqualOp,
       
   224         GreaterEqualOp,
       
   225         AmpAmpOp,
       
   226         PipePipeOp,
       
   227         PlusPlusOp,
       
   228         MinusMinusOp,
       
   229         CommaOp,
       
   230         ArrowStarOp,
       
   231         ArrowOp,
       
   232         FunctionCallOp,
       
   233         ArrayAccessOp
       
   234     };
       
   235 
       
   236 public:
       
   237     OperatorNameId(int kind);
       
   238     virtual ~OperatorNameId();
       
   239 
       
   240     int kind() const;
       
   241 
       
   242     virtual const Identifier *identifier() const;
       
   243     virtual bool isEqualTo(const Name *other) const;
       
   244 
       
   245     virtual const OperatorNameId *asOperatorNameId() const
       
   246     { return this; }
       
   247 
       
   248 protected:
       
   249     virtual void accept0(NameVisitor *visitor) const;
       
   250 
       
   251 private:
       
   252     int _kind;
       
   253 };
       
   254 
       
   255 class CPLUSPLUS_EXPORT ConversionNameId: public Name
       
   256 {
       
   257 public:
       
   258     ConversionNameId(const FullySpecifiedType &type);
       
   259     virtual ~ConversionNameId();
       
   260 
       
   261     FullySpecifiedType type() const;
       
   262 
       
   263     virtual const Identifier *identifier() const;
       
   264     virtual bool isEqualTo(const Name *other) const;
       
   265 
       
   266     virtual const ConversionNameId *asConversionNameId() const
       
   267     { return this; }
       
   268 
       
   269 protected:
       
   270     virtual void accept0(NameVisitor *visitor) const;
       
   271 
       
   272 private:
       
   273     FullySpecifiedType _type;
       
   274 };
       
   275 
       
   276 class CPLUSPLUS_EXPORT SelectorNameId: public Name
       
   277 {
       
   278 public:
       
   279     template <typename _Iterator>
       
   280     SelectorNameId(_Iterator first, _Iterator last, bool hasArguments)
       
   281         : _names(first, last), _hasArguments(hasArguments) {}
       
   282 
       
   283     virtual ~SelectorNameId();
       
   284 
       
   285     virtual const Identifier *identifier() const;
       
   286 
       
   287     unsigned nameCount() const;
       
   288     const Name *nameAt(unsigned index) const;
       
   289     bool hasArguments() const;
       
   290 
       
   291     virtual bool isEqualTo(const Name *other) const;
       
   292 
       
   293     virtual const SelectorNameId *asSelectorNameId() const
       
   294     { return this; }
       
   295 
       
   296     typedef std::vector<const Name *>::const_iterator NameIterator;
       
   297 
       
   298     NameIterator firstName() const { return _names.begin(); }
       
   299     NameIterator lastName() const { return _names.end(); }
       
   300 
       
   301 protected:
       
   302     virtual void accept0(NameVisitor *visitor) const;
       
   303 
       
   304 private:
       
   305     std::vector<const Name *> _names;
       
   306     bool _hasArguments;
       
   307 };
       
   308 
       
   309 } // end of namespace CPlusPlus
       
   310 
       
   311 #endif // CPLUSPLUS_NAMES_H