File indexing completed on 2024-04-21 04:35:52

0001 /* This file is part of KDevelop
0002  *
0003  * Copyright (C) 2011-2015 Miquel Sabaté Solà <mikisabate@gmail.com>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #ifndef RUBY_VARIABLE_DECLARATION_H
0020 #define RUBY_VARIABLE_DECLARATION_H
0021 
0022 #include <duchain/duchainexport.h>
0023 #include <language/duchain/declaration.h>
0024 #include <language/duchain/declarationdata.h>
0025 
0026 #include <parser/node.h>
0027 
0028 namespace ruby {
0029 
0030 class KDEVRUBYDUCHAIN_EXPORT VariableDeclarationData : public KDevelop::DeclarationData
0031 {
0032 public:
0033     VariableDeclarationData()
0034         : KDevelop::DeclarationData()
0035         , kind(flags_t::int_l)
0036     {
0037     }
0038 
0039     explicit VariableDeclarationData(const VariableDeclarationData &rhs)
0040         : KDevelop::DeclarationData(rhs)
0041     {
0042         kind = rhs.kind;
0043     }
0044 
0045     ~VariableDeclarationData()
0046     {
0047     }
0048 
0049     /// The kind of a variable declaration (i.e. constant, ivar, ...)
0050     int kind;
0051 };
0052 
0053 /**
0054  * @class VariableDeclaration
0055  *
0056  * Represents the declaration of a variable in ruby.
0057  */
0058 class KDEVRUBYDUCHAIN_EXPORT VariableDeclaration : public KDevelop::Declaration
0059 {
0060 public:
0061     VariableDeclaration(const KDevelop::RangeInRevision &range,
0062                         KDevelop::DUContext *context);
0063     VariableDeclaration(VariableDeclarationData &data,
0064                         const KDevelop::RangeInRevision &range);
0065     explicit VariableDeclaration(const VariableDeclaration &rhs);
0066     explicit VariableDeclaration(VariableDeclarationData &data);
0067     explicit VariableDeclaration(KDevelop::DeclarationData &data);
0068 
0069     /// Given a @p node, set the variable kind.
0070     void setVariableKind(const Node *node);
0071 
0072     /// Force the variable kind to the given @p kind.
0073     void setVariableKind(int kind);
0074 
0075     /// @returns the kind of this variable declaration.
0076     int variableKind() const;
0077 
0078     // Helper methods
0079 
0080     inline bool isNormal() const { return d_func()->kind == flags_t::var; }
0081     inline bool isGlobal() const { return d_func()->kind == flags_t::global; }
0082     inline bool isIvar() const { return d_func()->kind == flags_t::ivar; }
0083     inline bool isCvar() const { return d_func()->kind == flags_t::cvar; }
0084     inline bool isConstant() const { return d_func()->kind == flags_t::constant; }
0085 
0086     // Arguments
0087 
0088     inline bool hasStar() const { return d_func()->kind == flags_t::kwrest; }
0089     inline bool isBlock() const { return d_func()->kind == flags_t::block; }
0090     inline bool isOpt() const { return d_func()->kind == flags_t::opt; }
0091 
0092     enum { Identity = 47 /** The id of this Type. */ };
0093 
0094 private:
0095     DUCHAIN_DECLARE_DATA(VariableDeclaration)
0096 };
0097 
0098 }
0099 
0100 #endif // RUBY_VARIABLE_DECLARATION_H