diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-18 18:22:51 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-18 18:22:51 +0100 |
commit | 0463affed4d6ca08c0554974130aba83af13efa5 (patch) | |
tree | e747076b29d4765eca401ec8fc50cb5dd343ba5c /src/core | |
parent | a30e627ffccf36384689295ce54af32e38ef5ef8 (diff) |
Parsing struct attributes, added ability to reference other typesystems from a typesystem
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/model/Typesystem.cpp | 6 | ||||
-rw-r--r-- | src/core/model/Typesystem.hpp | 22 | ||||
-rw-r--r-- | src/core/parser/Scope.hpp | 89 |
3 files changed, 106 insertions, 11 deletions
diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp index 2be564d..6daa7fe 100644 --- a/src/core/model/Typesystem.cpp +++ b/src/core/model/Typesystem.cpp @@ -526,6 +526,7 @@ void Typesystem::doResolve(ResolutionState &state) { continueResolveComposita(constants, constants.getIndex(), state); continueResolveComposita(types, constants.getIndex(), state); + continueResolveReferences(typesystems, state); } bool Typesystem::doValidate(Logger &logger) const @@ -542,6 +543,11 @@ Rooted<StructType> Typesystem::createStructType(const std::string &name) return structType; } +void Typesystem::includeTypesystem(Handle<Typesystem> typesystem) +{ + typesystems.push_back(typesystem); +} + /* Class SystemTypesystem */ SystemTypesystem::SystemTypesystem(Manager &mgr) diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index 1b54a07..803d0e8 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -679,8 +679,8 @@ public: */ static Rooted<StructType> createValidated( Manager &mgr, std::string name, Handle<Typesystem> system, - Handle<StructType> parentStructure, const NodeVector<Attribute> &attributes, - Logger &logger); + Handle<StructType> parentStructure, + const NodeVector<Attribute> &attributes, Logger &logger); /** * Returns a handle pointing at the parent type. @@ -945,6 +945,11 @@ private: */ NodeVector<Constant> constants; + /** + * List containing references to other referenced typesystems. + */ + NodeVector<Typesystem> typesystems; + protected: void doResolve(ResolutionState &state) override; @@ -958,7 +963,10 @@ public: * @param name is the name of the typesystem. */ Typesystem(Manager &mgr, std::string name) - : Node(mgr, std::move(name)), types(this), constants(this) + : Node(mgr, std::move(name)), + types(this), + constants(this), + typesystems(this) { } @@ -972,6 +980,14 @@ public: Rooted<StructType> createStructType(const std::string &name); /** + * Adds a reference to the given typesystem class. + * + * @param typesystem is the typesystem that should be added to the + * referenced typesystems list. + */ + void includeTypesystem(Handle<Typesystem> typesystem); + + /** * Adds the given type to the to the type list. * * @param type is the Type that should be stored in this Typesystem diff --git a/src/core/parser/Scope.hpp b/src/core/parser/Scope.hpp index c99aa65..20a189a 100644 --- a/src/core/parser/Scope.hpp +++ b/src/core/parser/Scope.hpp @@ -25,6 +25,7 @@ #include <core/common/Logger.hpp> #include <core/common/Rtti.hpp> +#include <core/common/Utils.hpp> #include <core/model/Node.hpp> /** @@ -52,7 +53,8 @@ using ResolutionImposterCallback = std::function<Rooted<Node>()>; * Callback function type called whenever the result of a resolution is * available. */ -using ResolutionResultCallback = std::function<void(Handle<Node>, Logger &logger)>; +using ResolutionResultCallback = + std::function<void(Handle<Node>, Logger &logger)>; /** * The GuardedScope class takes care of pushing a Node instance into the @@ -329,7 +331,7 @@ public: * temporary) and another time if the resolution turned out to because * successful at a later point in time. * - * @tparam is the type of the node that should be resolved. + * @tparam T is the type of the node that should be resolved. * @param path is the path for which a node should be resolved. * @param logger is the logger instance into which resolution problems * should be logged. @@ -352,7 +354,7 @@ public: template <class T> bool resolve(const std::vector<std::string> &path, Logger &logger, std::function<Rooted<T>()> imposterCallback, - std::function<void(Handle<T>, Logger&)> resultCallback, + std::function<void(Handle<T>, Logger &)> resultCallback, const SourceLocation &location = SourceLocation{}) { return resolve( @@ -360,7 +362,8 @@ public: [imposterCallback]() -> Rooted<Node> { return imposterCallback(); }, [resultCallback](Handle<Node> node, Logger &logger) { resultCallback(node.cast<T>(), logger); - }, location); + }, + location); } /** @@ -369,7 +372,7 @@ public: * The "resultCallback" is called when the resolution was successful, which * may be at a later point in time. * - * @tparam is the type of the node that should be resolved. + * @tparam T is the type of the node that should be resolved. * @param path is the path for which a node should be resolved. * @param logger is the logger instance into which resolution problems * should be logged. @@ -384,13 +387,83 @@ public: */ template <class T> bool resolve(const std::vector<std::string> &path, Logger &logger, - std::function<void(Handle<T>, Logger&)> resultCallback, + std::function<void(Handle<T>, Logger &)> resultCallback, const SourceLocation &location = SourceLocation{}) { return resolve(path, typeOf<T>(), logger, [resultCallback](Handle<Node> node, Logger &logger) { - resultCallback(node.cast<T>(), logger); - }, location); + resultCallback(node.cast<T>(), logger); + }, + location); + } + + /** + * Tries to resolve a node for the given type and path for all nodes + * currently on the stack, starting with the topmost node on the stack. + * Calls the "imposterCallback" function for obtaining a temporary result if + * a node cannot be resolved right now. The "resultCallback" is at most + * called twice: Once when this method is called (probably with the + * temporary) and another time if the resolution turned out to because + * successful at a later point in time. + * + * @tparam T is the type of the node that should be resolved. + * @param name is the path for which a node should be resolved. The name is + * split at '.' to form a path. + * @param logger is the logger instance into which resolution problems + * should be logged. + * @param imposterCallback is the callback function that is called if + * the node cannot be resolved at this moment. It gives the caller the + * possibility to create an imposter (a temporary object) that may be used + * later in the resolution process. + * @param resultCallback is the callback function to which the result of + * the resolution process is passed. This function is called at least once + * either with the imposter (if the resolution was not successful) or the + * resolved object directly when this function is called. If the resolution + * was not successful the first time, it may be called another time later + * in the context of the "performDeferredResolution" function. + * @param location is the location in the current source file in which the + * resolution was triggered. + * @return true if the resolution was immediately successful. This does not + * mean, that the resolved object does not exist, as it may be resolved + * later. + */ + template <class T> + bool resolve(const std::string &name, Logger &logger, + std::function<Rooted<T>()> imposterCallback, + std::function<void(Handle<T>, Logger &)> resultCallback, + const SourceLocation &location = SourceLocation{}) + { + return resolve<T>(Utils::split(name, '.'), logger, imposterCallback, + resultCallback, location); + } + + /** + * Tries to resolve a node for the given type and path for all nodes + * currently on the stack, starting with the topmost node on the stack. + * The "resultCallback" is called when the resolution was successful, which + * may be at a later point in time. + * + * @tparam T is the type of the node that should be resolved. + * @param name is the path for which a node should be resolved. The name is + * split at '.' to form a path. + * @param logger is the logger instance into which resolution problems + * should be logged. + * @param resultCallback is the callback function to which the result of + * the resolution process is passed. This function is called once the + * resolution was successful. + * @param location is the location in the current source file in which the + * resolution was triggered. + * @return true if the resolution was immediately successful. This does not + * mean, that the resolved object does not exist, as it may be resolved + * later. + */ + template <class T> + bool resolve(const std::string &name, Logger &logger, + std::function<void(Handle<T>, Logger &)> resultCallback, + const SourceLocation &location = SourceLocation{}) + { + return resolve<T>(Utils::split(name, '.'), logger, resultCallback, + location); } /** |