File: overloadresolutionhelper.h

package info (click to toggle)
kdevelop 4%3A4.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 18,844 kB
  • sloc: cpp: 91,758; python: 1,095; lex: 422; ruby: 120; sh: 114; xml: 42; makefile: 38
file content (129 lines) | stat: -rw-r--r-- 5,305 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* 
   Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef OVERLOADRESOLUTIONHELPER_H
#define OVERLOADRESOLUTIONHELPER_H

#include "cppduchainexport.h"
#include <QPair>
#include <QList>
#include "overloadresolution.h"
#include "viablefunctions.h"
#include <language/duchain/identifier.h>

namespace Cpp
{
  class ViableFunction;
  
  class KDEVCPPDUCHAIN_EXPORT OverloadResolutionFunction {
  public:

    OverloadResolutionFunction();
    OverloadResolutionFunction( int _matchedArguments, const ViableFunction& _viable );

    /**The count of arguments that are already matched in this OverloadResolutionFunction. The argument of the OverloadResolutionFunction at this offset is the next one to be matched.
     *This is variable, and needed so global binary overloaded operators and member binary
     *operators can be treated same(global operators take 2 arguments, local
     *operators only 1)
     * */
    int matchedArguments;

    ///Result of matching the OverloadResolutionFunction to available arguments. Also contains the declaration.
    ViableFunction function;
  };
  
  /**
   * Helps searching and revolving functions or operator-functions in a unified way, partially or completely.
   * The du-chain must be locked for the whole lifetime of this object.
   * */
  class KDEVCPPDUCHAIN_EXPORT OverloadResolutionHelper {
    public:
    typedef QPair<OverloadResolver::ParameterList, KDevelop::Declaration*> DeclarationWithArgument;

    OverloadResolutionHelper(const KDevelop::DUContextPointer& context, const KDevelop::TopDUContextPointer& topContext);

    /**
     * @param identifierForADL The identifier will be used for performing argument-dependent look-up.
     *                         This should only be non-empty if the function is not being called as a member.
     * */
    void setFunctionNameForADL( const KDevelop::QualifiedIdentifier& identifierForADL );
    
    /**
     * @param base Sets the base-type, which is used while searching overloaded operators as:
     * Container-class of member operators, or first argument of global operators.
     * @warning: If calling this, you _must_ also call setFunctionNameForADL with the full operator name,
     *           like "operator=".
     * */
    void setOperator( const OverloadResolver::Parameter& base );

    /**
     * Call this instead of setOperator to use the specified list of functions for overload-resolution
     * */
    void setFunctions( const QList<KDevelop::Declaration*>& functions );

    /**
     * Call this to set the already known parameter-types for the function-call,
     * or for the operator-call.(For operators, this should not include the base-type)
     * */
    void setKnownParameters( const OverloadResolver::ParameterList& parameters );

    /**
     * Call this to set the whether we are looking for a const or a non-const method.
     * By default, the constness is not taken into account.
     */
    void setConstness(OverloadResolver::Constness constness);

    /**
     * @param partial If partial is given, it is not required that all parameters of the functions have a value.
     *
     * This is relatively slow, and returns a list of all considered functions, sorted by viability.
     * 
     * The du-chain must be read-locked.
     * */
    QList<OverloadResolutionFunction> resolveToList( bool partial = false );

    /**
     * The du-chain must be read-locked.
     * 
     * Returns only the most viable matched function. If no function is viable, a nonviable
     * function will be returned.
     *
     * NOTE: you *must* call @c setFunctions before, if not looking for operators!
     *
     * @param forceIsInstance If this is true, all encountered class types will be considered _instances_
     *                        of the class.
     * */
    ViableFunction resolve( bool forceIsInstance = false );
    
    private:
      void initializeResolver(OverloadResolver& resolver);
      void log(const QString& str) const;
      KDevelop::DUContextPointer m_context;
      KDevelop::TopDUContextPointer m_topContext;
      OverloadResolver::Parameter m_baseType;
      bool m_isOperator;
      QList< DeclarationWithArgument > m_declarations; //Declarations are paired with the optional first argument for the declared functions
      OverloadResolver::ParameterList m_knownParameters;
      QMap<KDevelop::Declaration*, int> m_argumentCountMap; //Maps how many pre-defined arguments were given to which function
      QualifiedIdentifier m_identifierForADL;
      OverloadResolver::Constness m_constness;
  };

}

#endif