diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-10-16 18:49:11 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-16 18:49:11 -0400 |
| commit | 3e74d39f24fdfaa547ce900be177863e2bfe2dea (patch) | |
| tree | 9a5143e6de4caa27b23fc870003011e96129905f /source/slang/source-loc.h | |
| parent | 204fb3c75b520a2cbb1c25f995a8c424ec2753f3 (diff) | |
Feature/include refactor (#675)
* Refactor of path handling.
* Added PathInfo
* Changed ISlangFileSystem - such that has separate concepts of reading a file, getting a relative path and getting a canonical path
* Added support for getting a canonical path for windows/linux
* Made maps/testing around canonicalPaths
* User output remains around 'foundPath' - which is the same as before
* Small improvements around PathInfo
* Added a type and make constructors to make clear the different 'path' uses
* Fixed bug in findViewRecursively
* Checking and reporting for ignored #pragma once.
* Removed SLANG_PATH_TYPE_NONE as doesn't serve any useful purpose.
* Improve comments in slang.h aroung ISlangFileSystem
* Remove the need for <windows.h> in slang-io.cpp
* Ran premake5.
* Improvements and fixes around PathInfo.
* Fix typo on linix GetCanonical
* Make the ISlangFileSystem the same as before, and ISlangFileSystem contain the new methods.
Internally it always uses the ISlangFileSystemExt, and will wrap a ISlangFileSystem with WrapFileSystem, if it is determined (via queryInterface) that it doesn't implement the full interface.
Diffstat (limited to 'source/slang/source-loc.h')
| -rw-r--r-- | source/slang/source-loc.h | 58 |
1 files changed, 48 insertions, 10 deletions
diff --git a/source/slang/source-loc.h b/source/slang/source-loc.h index 48b7791c7..8f6b8f7cb 100644 --- a/source/slang/source-loc.h +++ b/source/slang/source-loc.h @@ -38,6 +38,40 @@ SourceViews are created, with unique SourceRanges. This is so that it is possibl interpretation for that lex/parse. */ +struct PathInfo +{ + /// To be more rigorous about where a path comes from, the type identifies what a paths origin is + enum class Type + { + Unknown, ///< The path is not known + Normal, ///< Normal has both path and canonical path + FoundPath, ///< Just has a found path (canonical path is unknown, or even 'unknowable') + TokenPaste, ///< No paths, just created to do a macro expansion + TypeParse, ///< No path, just created to do a type parse + CommandLine, ///< A macro constructed from the command line + }; + + /// True if has a canonical path + SLANG_FORCE_INLINE bool hasCanonicalPath() const { return type == Type::Normal && canonicalPath.Length() > 0; } + /// True if has a regular found path + SLANG_FORCE_INLINE bool hasFoundPath() const { return type == Type::Normal || type == Type::FoundPath; } + + /// The canonical path is unique, so return that if we have it. If not the regular path, otherwise the empty string. + const String getMostUniquePath() const; + + // So simplify construction. In normal usage it's safer to use make methods over constructing directly. + static PathInfo makeUnknown() { return PathInfo { Type::Unknown, "unknown" }; } + static PathInfo makeTokenPaste() { return PathInfo{ Type::TokenPaste, "token paste" }; } + static PathInfo makeNormal(const String& foundPathIn, const String& canonicalPathIn) { SLANG_ASSERT(canonicalPathIn.Length() > 0 && foundPathIn.Length() > 0); return PathInfo { Type::Normal, foundPathIn, canonicalPathIn }; } + static PathInfo makePath(const String& pathIn) { SLANG_ASSERT(pathIn.Length() > 0); return PathInfo { Type::FoundPath, pathIn }; } + static PathInfo makeTypeParse() { return PathInfo { Type::TypeParse, "type string" }; } + static PathInfo makeCommandLine() { return PathInfo { Type::CommandLine, "command line" }; } + + Type type; ///< The type of path + String foundPath; ///< The path where the file was found (might contain relative elements) + String canonicalPath; ///< Canonical version of the found path +}; + class SourceLoc { public: @@ -121,7 +155,7 @@ public: /// Calculate the offset for a line int calcColumnIndex(int line, int offset); - String path; ///< The logical file path to report for locations inside this span. + PathInfo pathInfo; ///< The path The logical file path to report for locations inside this span. ComPtr<ISlangBlob> contentBlob; ///< A blob that owns the storage for the file contents UnownedStringSlice content; ///< The actual contents of the file. @@ -141,7 +175,7 @@ enum class SourceLocType // A source location in a format a human might like to see struct HumaneSourceLoc { - String path; + PathInfo pathInfo; Int line = 0; Int column = 0; }; @@ -200,7 +234,7 @@ class SourceView: public RefObject HumaneSourceLoc getHumaneLoc(SourceLoc loc, SourceLocType type = SourceLocType::Nominal); /// Get the path associated with a location - String getPath(SourceLoc loc, SourceLocType type = SourceLocType::Nominal); + PathInfo getPathInfo(SourceLoc loc, SourceLocType type = SourceLocType::Nominal); /// Ctor SourceView(SourceManager* sourceManager, SourceFile* sourceFile, SourceRange range): @@ -211,7 +245,8 @@ class SourceView: public RefObject } protected: - + PathInfo _getPathInfo(StringSlicePool::Handle pathHandle) const; + SourceManager* m_sourceManager; /// Get the manager this belongs to SourceRange m_range; ///< The range that this SourceView applies to RefPtr<SourceFile> m_sourceFile; ///< The source file can hold the line breaks @@ -227,15 +262,15 @@ struct SourceManager SourceRange allocateSourceRange(UInt size); /// Create a SourceFile defined with the specified path, and content held within a blob - SourceFile* createSourceFile(String const& path, ISlangBlob* content); + SourceFile* createSourceFile(const PathInfo& pathInfo, ISlangBlob* content); /// Create a SourceFile with specified path. Create a Blob that contains the content. - SourceFile* createSourceFile(String const& path, String const& content); + SourceFile* createSourceFile(const PathInfo& pathInfo, String const& content); /// Get the humane source location HumaneSourceLoc getHumaneLoc(SourceLoc loc, SourceLocType type = SourceLocType::Nominal); /// Get the path associated with a location - String getPath(SourceLoc loc, SourceLocType type = SourceLocType::Nominal); + PathInfo getPathInfo(SourceLoc loc, SourceLocType type = SourceLocType::Nominal); /// Create a new source view from a file SourceView* createSourceView(SourceFile* sourceFile); @@ -251,10 +286,12 @@ struct SourceManager /// Searches this manager, and then the parent to see if can find a match for path. /// If not found returns nullptr. - SourceFile* findSourceFile(const String& path); + SourceFile* findSourceFileRecursively(const String& canonicalPath) const; + /// Find if the source file is defined on this manager. + SourceFile* findSourceFile(const String& canonicalPath) const; /// Add a source file, path must be unique for this manager AND any parents - void addSourceFile(const String& path, SourceFile* sourceFile); + void addSourceFile(const String& canonicalPath, SourceFile* sourceFile); /// Get the slice pool StringSlicePool& getStringSlicePool() { return m_slicePool; } @@ -283,7 +320,8 @@ struct SourceManager List<RefPtr<SourceView> > m_sourceViews; StringSlicePool m_slicePool; - Dictionary<String, RefPtr<SourceFile> > m_sourceFiles; + // Maps canonical paths to source files + Dictionary<String, RefPtr<SourceFile> > m_sourceFiles; }; } // namespace Slang |
