From 8e7be30a309ccd84684033ea854c574b32282495 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Thu, 22 Jan 2015 02:42:29 +0100 Subject: Added Location.cpp (empty, but verifies that the header has no errors) --- src/core/common/Location.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/core/common/Location.cpp (limited to 'src/core/common/Location.cpp') diff --git a/src/core/common/Location.cpp b/src/core/common/Location.cpp new file mode 100644 index 0000000..6f9250a --- /dev/null +++ b/src/core/common/Location.cpp @@ -0,0 +1,23 @@ +/* + Ousía + Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "Location.hpp" + +namespace ousia { +} + -- cgit v1.2.3 From 6dbb4d19a860937ec1c78df01b1371272e1de8de Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 23 Jan 2015 12:08:42 +0100 Subject: Improved SourceLocation class. --- src/core/common/Location.cpp | 9 +++++++++ src/core/common/Location.hpp | 29 +++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src/core/common/Location.cpp') diff --git a/src/core/common/Location.cpp b/src/core/common/Location.cpp index 6f9250a..7a75347 100644 --- a/src/core/common/Location.cpp +++ b/src/core/common/Location.cpp @@ -19,5 +19,14 @@ #include "Location.hpp" namespace ousia { + +/* Global Functions */ + +const SourceLocation NullSourceLocation; + +void SourceContext NullSourceContextCallback(const SourceLocation &location) +{ + return SourceContext{}; +} } diff --git a/src/core/common/Location.hpp b/src/core/common/Location.hpp index 4ce01a8..57892cc 100644 --- a/src/core/common/Location.hpp +++ b/src/core/common/Location.hpp @@ -29,6 +29,7 @@ #define _OUSIA_LOCATION_HPP_ #include +#include #include #include @@ -272,7 +273,7 @@ public: /** * Default constructor. */ - SourceLocation() : sourceId(InvalidSourceId) {}; + SourceLocation() : sourceId(InvalidSourceId){}; /** * Constructor, binds the SourceLocation to the given source file. @@ -346,6 +347,11 @@ public: } }; +/** + * NullSourceLocation is an empty SourceLocation instance. + */ +extern const SourceLocation NullSourceLocation; + /** * Represents the context of a SourceLocation instance. Used to build error * messages. @@ -435,6 +441,11 @@ struct SourceContext { */ bool isValid() const { return range.isValid() && hasLine() && hasColumn(); } + /** + * Returns true if a valid (non-empty) filename is set. + */ + bool hasFile() const { return !filename.empty(); } + /** * Returns true, if the start line number is valid, false otherwise. * @@ -455,10 +466,20 @@ struct SourceContext { * location. * * @param location is the location for which the context should be looked up. - * @param data is used defined data associated with the callback. + * @return the corresponding SourceContext. */ -using SourceContextCallback = SourceContext (*)(const SourceLocation &location, - void *data); +using SourceContextCallback = + std::function; + +/** + * Function to be used as default value for the SourceContextCallback. Returns + * an invalid SourceContext. + * + * @param location is the location for which the context should be looked up. + * @return an empty, invalid SourceContext. + */ +void SourceContext NullSourceContextCallback(const SourceLocation &location); + } #endif /* _OUSIA_LOCATION_HPP_ */ -- cgit v1.2.3 From 9e084e8e7f657112436c3e07f12a2319373b1909 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 23 Jan 2015 15:26:47 +0100 Subject: typo --- src/core/common/Location.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/common/Location.cpp') diff --git a/src/core/common/Location.cpp b/src/core/common/Location.cpp index 7a75347..7fe5ea5 100644 --- a/src/core/common/Location.cpp +++ b/src/core/common/Location.cpp @@ -24,9 +24,10 @@ namespace ousia { const SourceLocation NullSourceLocation; -void SourceContext NullSourceContextCallback(const SourceLocation &location) +SourceContext NullSourceContextCallback(const SourceLocation &location) { return SourceContext{}; } + } -- cgit v1.2.3