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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#pragma once
#include "Core/TObject.h"
#include "Core/EnginePtr.h"
namespace storm {
STORM_PKG(core.lang);
class Named;
class NameLookup;
/**
* Class describing what parts of the system are able to access a specific named entity
* (ie. what parts of the system are visible to other parts). Instances of this class are not
* associated with specific Named entities, which means that it is possible to use one instance
* for multiple Named objects.
*
* This is an abstract class which is overridden with some default behaviours below, such as
* 'public', 'private', etc.
*
* Note: Virtual dispatch is resolved by examining if the overridden function is visible from
* the overriding function, not by examining all possible implementations from the *call
* site*. Furthermore, the system assumes that visibility for functions inside types are
* transitive with respect to inheritance. Ie. if A <- B <- C, then if A.foo is visible from
* C.foo, then A.foo must also be visible from B.foo, and B.foo must be visible from C.foo. If
* this constraint is not fullfilled, then the use of virtual dispatch will be unpredictable.
*/
class Visibility : public ObjectOn<Compiler> {
STORM_CLASS;
public:
// Create.
Visibility();
// Is 'check' visible to 'source'? Note that 'source' is not required to have a name, but it
// needs to reside somewhere in the name tree.
virtual Bool STORM_FN visible(Named *check, NameLookup *source);
};
/**
* Public visibility. Accessible to everyone.
*
* Access instances through the 'public()' function below.
*/
class Public : public Visibility {
STORM_CLASS;
public:
// Create.
Public();
// Check.
virtual Bool STORM_FN visible(Named *check, NameLookup *source);
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
};
/**
* Private visibility within a type. Accessible only to members of the same type.
*
* Access instances through the 'typePrivate()' function below.
*/
class TypePrivate : public Visibility {
STORM_CLASS;
public:
// Create.
TypePrivate();
// Check.
virtual Bool STORM_FN visible(Named *check, NameLookup *source);
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
};
/**
* Protected within a type. Accessible to members of the same type, and to members of a derived type.
*
* Access instances through the 'typeProtected()' function below.
*/
class TypeProtected : public Visibility {
STORM_CLASS;
public:
// Create.
TypeProtected();
// Check.
virtual Bool STORM_FN visible(Named *check, NameLookup *source);
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
};
/**
* Private within a package. Only the current package, or sub-packages, are able to access the type.
*
* Access instances through the 'packagePrivate()' function below.
*/
class PackagePrivate : public Visibility {
STORM_CLASS;
public:
// Create.
PackagePrivate();
// Check.
virtual Bool STORM_FN visible(Named *check, NameLookup *source);
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
};
/**
* Private access for free functions etc. Only allows access from entities that are located in
* the same file as this declaration.
*
* Access instances through the 'filePrivate()' function below.
*/
class FilePrivate : public Visibility {
STORM_CLASS;
public:
// Create.
FilePrivate();
// Check.
virtual Bool STORM_FN visible(Named *check, NameLookup *source);
// To string.
virtual void STORM_FN toS(StrBuf *to) const;
};
/**
* Access the shared instances of the above objects.
*/
Visibility *STORM_FN STORM_NAME(allPublic, public)(EnginePtr e) ON(Compiler);
Visibility *STORM_FN typePrivate(EnginePtr e) ON(Compiler);
Visibility *STORM_FN typeProtected(EnginePtr e) ON(Compiler);
Visibility *STORM_FN packagePrivate(EnginePtr e) ON(Compiler);
Visibility *STORM_FN filePrivate(EnginePtr e) ON(Compiler);
}
|