From 9b80537bc0272a9caf93f146d8964d9bdd4a407e Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 4 Feb 2019 17:30:51 -0500 Subject: Feature/view path (#824) * Use 'is' over 'as' where appropriate. * dynamic_cast -> dynamicCast * Replace 'dynamicCast' with 'as' where has no change in behavior/ambiguity. * Replace dynamicCast with as where doesn't change behavior/non ambiguous. * Keep a per view path to the file loaded - such that diagnostic messages always display the path to the requested file. * Add simplifyPath to ISlangFileSystemExt Simplify (if possible) paths that are set on SourceFile and SourcView - doing so makes reading paths simpler. * Fix small typo. * Improve documentation in source for getFileUniqueIdentity * Fix override warning. --- source/slang/source-loc.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'source/slang/source-loc.h') diff --git a/source/slang/source-loc.h b/source/slang/source-loc.h index aa0623e3d..ad0453d0e 100644 --- a/source/slang/source-loc.h +++ b/source/slang/source-loc.h @@ -194,7 +194,7 @@ public: protected: - SourceManager * m_sourceManager; ///< The source manager this belongs to + SourceManager* m_sourceManager; ///< The source manager this belongs to PathInfo m_pathInfo; ///< The path The logical file path to report for locations inside this span. ComPtr m_contentBlob; ///< A blob that owns the storage for the file contents. If nullptr, there is no contents UnownedStringSlice m_content; ///< The actual contents of the file. @@ -281,14 +281,24 @@ class SourceView PathInfo getPathInfo(SourceLoc loc, SourceLocType type = SourceLocType::Nominal); /// Ctor - SourceView(SourceFile* sourceFile, SourceRange range): + SourceView(SourceFile* sourceFile, SourceRange range, const String* viewPath): m_range(range), m_sourceFile(sourceFile) { + if (viewPath) + { + m_viewPath = *viewPath; + } } protected: - PathInfo _getPathInfo(StringSlicePool::Handle pathHandle) const; + /// Get the pathInfo from a string handle. If it's 0, it will return the _getPathInfo + PathInfo _getPathInfoFromHandle(StringSlicePool::Handle pathHandle) const; + /// Gets the pathInfo for this view. It may be different from the m_sourceFile's if the path has been + /// overridden by m_viewPath + PathInfo _getPathInfo() const; + + String m_viewPath; ///< Path to this view. If empty the path is the path to the SourceView SourceRange m_range; ///< The range that this SourceView applies to SourceFile* m_sourceFile; ///< The source file. Can hold the line breaks @@ -315,7 +325,9 @@ struct SourceManager PathInfo getPathInfo(SourceLoc loc, SourceLocType type = SourceLocType::Nominal); /// Create a new source view from a file - SourceView* createSourceView(SourceFile* sourceFile); + /// @param sourceFile is the source file that contains the source + /// @param pathInfo is path used to read the file from + SourceView* createSourceView(SourceFile* sourceFile, const PathInfo* pathInfo); /// Find a view by a source file location. /// If not found in this manager will look in the parent SourceManager -- cgit v1.2.3