Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[r302]: cmajor++ / Cm / Cm.Core / FunctionSet.hpp Maximize Restore History

Download this file

FunctionSet.hpp    130 lines (109 with data), 5.3 kB

  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
/*========================================================================
Copyright (c) 2012-2013 Seppo Laakko
http://sourceforge.net/projects/cmajor/
Distributed under the GNU General Public License, version 3 (GPLv3).
(See accompanying LICENSE.txt or http://www.gnu.org/licenses/gpl.html)
========================================================================*/
#ifndef CM_CORE_FUNCTIONSET_INCLUDED
#define CM_CORE_FUNCTIONSET_INCLUDED
#include <Cm.Core/Argument.hpp>
#include <Cm.Core/Scope.hpp>
#include <Cm.Core/Type.hpp>
namespace Cm { namespace Core {
enum class ResolutionOption
{
deny_conversions, deny_left_conversion, allow_trivial_conversions, allow_conversions
};
enum class ConversionOption
{
explicit_, implicit
};
enum class ResolutionFlags
{
none = 0, throw_ = 1, bind_only_members = 2, bind_only_member_functions = 4
};
inline ResolutionFlags operator&(ResolutionFlags left, ResolutionFlags right)
{
return ResolutionFlags(int(left) & int(right));
}
inline ResolutionFlags operator|(ResolutionFlags left, ResolutionFlags right)
{
return ResolutionFlags(int(left) | int(right));
}
class Function;
typedef std::shared_ptr<Function> FunctionPtr;
class FunctionCall;
typedef std::shared_ptr<FunctionCall> FunctionCallPtr;
typedef std::vector<FunctionPtr> FunctionVec;
typedef std::vector<FunctionPtr> FunctionList;
class FunctionSet: public Object
{
public:
FunctionSet(const std::string& name_, const Position& pos_, const ScopePtr& enclosingScope_, const ScopePtr& fileScope_);
virtual void Dispose();
virtual ObjectPtr Clone(CloneContext& context) const;
virtual bool IsFunctionSet() const { return true; }
virtual bool IsImportObject() const { return true; }
const FunctionVec& Overloads() const { return overloadVec; }
void AddOverload(const FunctionPtr& overload);
FunctionPtr GetOverload(const ArgumentVector& arguments, const ScopeLookupSet& scopes);
FunctionPtr GetOverload(const std::string& overloadName, const ScopeLookupSet& scopes);
FunctionCallPtr ResolveOverload(const ArgumentVector& arguments, const ScopeLookupSet& scopes, ResolutionOption resolution, const Position& callPosition,
ResolutionFlags flags, Function* ownerFunction);
FunctionCallPtr ResolveOverload(const ArgumentVector& arguments, const ScopeLookupSet& scopes, ResolutionOption resolution, ConversionOption conversion,
const Position& callPosition, ResolutionFlags flags, Function* ownerFunction);
FunctionCallPtr ResolveOverload(const ArgumentVector& arguments, const ScopeLookupSet& scopes, ResolutionOption resolution, FunctionList& conversions,
const Position& callPosition, ResolutionFlags flags, Function* ownerFunction);
FunctionCallPtr ResolveOverload(const ArgumentVector& arguments, const ScopeLookupSet& scopes, ResolutionOption resolution, ConversionOption conversion,
FunctionList& conversions, const Position& callPosition, ResolutionFlags flags, Function* ownerFunction);
virtual void TypeCheckSignature(TypeCheckContext& context);
virtual void TypeCheckBody(TypeCheckContext& context);
virtual ObjectPtr Instantiate(ExpressionList& templateArguments, TypeCheckContext& context);
virtual void Print(CodeFormatter&) {}
private:
FunctionVec overloadVec;
};
typedef std::shared_ptr<FunctionSet> FunctionSetPtr;
class FunctionSetLink: public Object
{
public:
FunctionSetLink(const std::string& name_, const Position& pos_, const ScopePtr& enclosingScope_, const ScopePtr& fileScope_, const FunctionSetPtr& linkedFunctionSet_);
virtual bool IsImportObject() const { return true; }
virtual void TypeCheckSignature(TypeCheckContext& context);
virtual void TypeCheckBody(TypeCheckContext& context);
virtual void Dispose();
virtual ObjectPtr Clone(CloneContext& context) const;
virtual bool IsFunctionSetLink() const { return true; }
FunctionSetPtr GetFunctionSet() const { return linkedFunctionSet; }
virtual bool HasTypeCheckReplacement(TypeCheckContext& context) const;
virtual ObjectPtr GetTypeCheckReplacement(TypeCheckContext& context) const;
virtual void Print(CodeFormatter&) {}
private:
FunctionSetPtr linkedFunctionSet;
};
typedef std::shared_ptr<FunctionSetLink> FunctionSetLinkPtr;
class FunctionSetTable;
typedef std::shared_ptr<FunctionSetTable> FunctionSetTablePtr;
class FunctionSetTable
{
public:
FunctionSetPtr GetFunctionSet(const std::string& functionSetName) const;
~FunctionSetTable();
void AddFunctionSet(const FunctionSetPtr& functionSet);
static void Init();
static void Done();
static FunctionSetTablePtr Instance();
void TypeCheck(TypeCheckContext& context);
private:
FunctionSetTable();
static FunctionSetTablePtr instance;
static std::stack<FunctionSetTablePtr> instanceStack;
typedef std::map<std::string, FunctionSetPtr> FunctionSetMap;
typedef FunctionSetMap::const_iterator FunctionSetMapIt;
FunctionSetMap functionSetMap;
std::vector<FunctionSetPtr> functionSets;
};
void FunctionSetInit();
void FunctionSetDone();
} } // namespace Cm::Core
#endif // CM_CORE_FUNCTIONSET_INCLUDED