summaryrefslogtreecommitdiffstats
path: root/src/symbolresolver.h
blob: e00569d5ed92fb32fc6f5f0f23ba6c1313a2304e (plain)
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
/******************************************************************************
 *
 * Copyright (C) 1997-2020 by Dimitri van Heesch.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby
 * granted. No representations are made about the suitability of this software
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 *
 */

#ifndef SYMBOLRESOLVER_H
#define SYMBOLRESOLVER_H

#include <memory>
#include "qcstring.h"

class Definition;
class ClassDef;
class FileDef;
class MemberDef;

//! Helper class to find a class definition or check if
//! A symbol is accessible in a given scope.
class SymbolResolver
{
  public:
    explicit SymbolResolver(const FileDef *fileScope = 0);
   ~SymbolResolver();

    // actions

    /** Find the class definition matching name within
     *  the scope set.
     *  @param scope The scope to search from.
     *  @param name  The name of the symbol.
     *  @param maybeUnlinkable include unlinkable symbols in the search.
     *  @param myBeHidden include hidden symbols in the search.
     *  @note As a result of this call the getters getTypedef(),
     *  getTemplateSpec(), and getResolvedType() are set as well.
     */
    const ClassDef *resolveClass(const Definition *scope,
                                 const char *name,
                                 bool maybeUnlinkable=false,
                                 bool myBeHidden=false);

    /** Checks if symbol \a item is accessible from within \a scope.
     *  @returns -1 if \a item is not accessible or a number indicating how
     *  many scope levels up the nearest match was found.
     */
    int isAccessibleFrom(const Definition *scope,
                         const Definition *item);

    /** Check if symbol \a item is accessible from within \a scope,
     *  where it has to match the \a explicitScopePart.
     *  @returns -1 if \a item is not accessible or a number indicating how
     *  many scope levels up the nearest match was found.
     */
    int isAccessibleFromWithExpScope(const Definition *scope,
                                     const Definition *item,
                                     const QCString &explicitScopePart
                                    );

    /** Sets or updates the file scope using when resolving symbols. */
    void setFileScope(const FileDef *fd);

    // getters

    /** In case a call to resolveClass() resolves to a type member (e.g. an enum)
     *  this method will return it.
     */
    const MemberDef *getTypedef() const;

    /** In case a call to resolveClass() points to a template specialization, the
     *  template part is return via this method.
     */
    QCString   getTemplateSpec() const;

    /** In case a call to resolveClass() points to a typedef or using declaration.
     *  The type name it resolved to is returned via this method.
     */
    QCString   getResolvedType() const;

  private:
    struct Private;
    std::unique_ptr<Private> p;
};

#endif