Synopsis - Cross-Reference
File: /Synopsis/Parsers/Cxx/Lookup.hh1// 2// Copyright (C) 2001 Stephen Davies 3// Copyright (C) 2001 Stefan Seefeld 4// All rights reserved. 5// Licensed to the public under the terms of the GNU LGPL (>= 2), 6// see the file COPYING for details. 7// 8 9#ifndef Lookup_hh_ 10#define Lookup_hh_ 11 12#include "ASG.hh" 13 14// Forward declare some Types::Type's 15namespace Types 16{ 17class Type; 18class Base; 19class Named; 20class Unknown; 21class TemplateType; 22class FuncPtr; 23} 24 25// Forward declare the Builder class 26class Builder; 27 28class ScopeInfo; 29typedef std::vector<ScopeInfo*> ScopeSearch; // TODO: move to common 30 31//. ASG Builder. 32//. This class manages the building of an ASG, including queries on the 33//. existing ASG such as name and type lookups. The building operations are 34//. called by SWalker as it walks the parse tree. 35class Lookup 36{ 37public: 38 //. Constructor 39 Lookup(Builder*); 40 41 //. Destructor. Recursively destroys all ASG objects 42 ~Lookup(); 43 44 //. Changes the current accessability for the current scope 45 void set_access(ASG::Access); 46 47 48 // 49 // ASG Methods 50 // 51 52 //. Returns the current scope 53 ASG::Scope* scope(); 54 55 //. Returns the global scope 56 ASG::Scope* global(); 57 58 59 // 60 // Type Methods 61 // 62 63 //. Looks up the name in the current scope. This method always succeeds -- 64 //. if the name is not found it forward declares it. 65 Types::Named* lookupType(const std::string& name, bool func_okay = false); 66 67 //. Looks up the qualified name in the current scope. This method always 68 //. succeeds -- if the name is not found it forwards declares it. 69 //. @param names The list of identifiers given 70 //. @param fuc_okay If true, multiple declarations will not cause an error (needs fixing) 71 //. @param scope If set determines the scope to start lookup from, else the 72 //. current scope is used 73 Types::Named* lookupType(const ScopedName& names, bool func_okay=false, ASG::Scope* scope=0); 74 75 //. Looks up the name in the scope of the given scope. This method may 76 //. return a 0 ptr if the lookup failed. 77 Types::Named* lookupType(const std::string& name, ASG::Scope* scope); 78 79 //. Looks up the function in the given scope with the given args. 80 ASG::Function* lookupFunc(const std::string& , ASG::Scope*, const std::vector<Types::Type*>&); 81 82 //. Looks up the function operator in the current scope with the given 83 //. types. May return 0 if builtin operator or no operator is found. 84 ASG::Function* lookupOperator(const std::string& oper, Types::Type* left_type, Types::Type* right_type); 85 86 //. Maps a scoped name into a vector of scopes and the final type. Returns 87 //. true on success. 88 bool mapName(const ScopedName& name, std::vector<ASG::Scope*>&, Types::Named*&); 89 90 //. Returns the types for an array operator on the given type with an 91 //. argument of the given type. If a function is used then it is stored in 92 //. the function ptr ref given, else the ptr is set to 0. 93 Types::Type* arrayOperator(Types::Type* object, Types::Type* arg, ASG::Function*&); 94 95 //. Resolves the final type of the given type. If the given type is an 96 //. Unknown, it checks to see if the type has been defined yet and returns 97 //. that instead. 98 Types::Named* resolveType(Types::Named* maybe_unknown); 99 100private: 101 //. Looks up the name in the current scope. This method may fail and 102 //. return a 0 ptr. 103 Types::Named* lookup(const std::string& name, bool func_okay = false); 104 105 //. Searches for name in the list of Scopes. This method may return 0 106 //. if the name is not found. 107 Types::Named* lookup(const std::string& name, const ScopeSearch&, bool func_okay = false) throw (); 108 109 //. Searches for name in the given qualified scope. This method may return 110 //. 0 if the name is not found. Lookup proceeds according to the spec: 111 //. if 'scope' is a Class scope, then scope and all base classes are 112 //. searched, else if it's a 'namespace' scope then all usings are checked. 113 Types::Named* lookupQual(const std::string& name, const ScopeInfo*, bool func_okay = false); 114 115 //. Return a ScopeInfo* for the given Declaration. This method first looks for 116 //. an existing Scope* in the Private map. 117 ScopeInfo* find_info(ASG::Scope*); 118 119 //. Utility class to add all functions with the given name in the given 120 //. Scope's dictionary to the given vector. May throw an error if the 121 //. types looked up are not functions. 122 void findFunctions(const std::string&, ScopeInfo*, std::vector<ASG::Function*>&); 123 124 //. Determines the best function from the given list for the given 125 //. arguments using heuristics. Returns the function and stores the cost 126 ASG::Function* bestFunction(const std::vector<ASG::Function*>&, const std::vector<Types::Type*>&, int& cost); 127 128 //. Formats the search of the given Scope for logging 129 std::string dumpSearch(ScopeInfo* scope); 130 131 //. A pointer to the Builder. 132 Builder* m_builder; 133 134}; 135 136#endif 137// vim: set ts=8 sts=4 sw=4 et: