diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-02 00:34:04 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-02 00:34:04 +0100 |
commit | e4071ff5894d13e95f72457aac68899610e5d7eb (patch) | |
tree | 41f5235c3d757bd2bf97d1248ec38da0e2d2a879 /src/core/common/Variant.cpp | |
parent | 28fc6ac92cf8b058da22c54c939fc225779ac26d (diff) |
Allowing to store SourceLocation from which a Variant was parsed along with the Variant
Diffstat (limited to 'src/core/common/Variant.cpp')
-rw-r--r-- | src/core/common/Variant.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/core/common/Variant.cpp b/src/core/common/Variant.cpp index 9b22b71..0c7fceb 100644 --- a/src/core/common/Variant.cpp +++ b/src/core/common/Variant.cpp @@ -20,6 +20,7 @@ #include <core/managed/Managed.hpp> +#include "Location.hpp" #include "Logger.hpp" #include "Utils.hpp" #include "Variant.hpp" @@ -29,6 +30,42 @@ namespace ousia { +/* Struct VariantMetadata */ + +bool VariantMetadata::hasLocation() const +{ + return locationSourceId != InvalidSourceId; +} + +SourceLocation VariantMetadata::getLocation() const +{ + if (locationOffset == InvalidLocationOffset) { + return SourceLocation(locationSourceId); + } + if (locationLength == InvalidLocationLength) { + return SourceLocation(locationSourceId, locationOffset); + } + return SourceLocation(locationSourceId, locationOffset, + static_cast<size_t>(locationOffset) + + static_cast<size_t>(locationLength)); +} + +void VariantMetadata::setLocation(const SourceLocation &location) +{ + // Copy the location members + const SourceId sourceId = location.getSourceId(); + const size_t offset = location.getStart(); + const size_t length = location.getLength(); + + // Copy the location, mark values that cannot be stored as invalid + locationSourceId = + sourceId < InvalidLocationSourceId ? sourceId : InvalidLocationSourceId; + locationOffset = + offset < InvalidLocationOffset ? offset : InvalidLocationOffset; + locationLength = + length < InvalidLocationLength ? length : InvalidLocationLength; +} + /* Class Variant::TypeException */ Variant::TypeException::TypeException(VariantType actualType, @@ -155,7 +192,7 @@ Variant::cardinalityType Variant::toCardinality() const const Rtti &Variant::getRtti() const { - switch (type) { + switch (meta.getType()) { case VariantType::NULLPTR: return RttiTypes::Nullptr; case VariantType::BOOL: |