summaryrefslogtreecommitdiff
path: root/source/slang/source-loc.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-01-21 16:41:54 -0500
committerGitHub <noreply@github.com>2019-01-21 16:41:54 -0500
commitbd815f02d846a50e16dab67e6512db2a6215c41f (patch)
tree01e391757bdb8f2d15bdc010227d522bddac3936 /source/slang/source-loc.h
parent0a3ef7b4ae02983ea3f986ba8211e7c6af9d254b (diff)
Feature/file unique identity (#789)
* * Fix memory bug around expanding va_args - needed buffer to have space for terminating 0 * Fix problem with FileWriter defaults being globals, as memory they allocate, will only be freed after return from main - work around by making StdWriters RefObject derived, and kept in scope such the writers are destroyed before checks for leaks is found * Added SimplifyPathAndHash mode for CacheFileSystem - will simplify the path and see if simplified path is in cache before reading file (limiting amout of underlying file requests) * * Added calcReplaceChar * Renamed DefaultFileSystem to OSFileSystem * Made OSFileSystem convert windows \ to / on linux * Simplified logic for caching in CacheFileSystem. * Added pragma-once-c to add extra test, but also so there is an 'include' directory in preprocessor tests. * Small fixes in pragma once test. * Simplified cache handling path, so that paths/simplified paths area always added. * Improve naming of methods for different caches. * Removed references to 'canonicalPath' and made 'uniqueIdentity' * * Re-add support for canonicalPath to ISlangFileSystem -> not for uniqueIdentifier but as a way to display 'canonicalPath' * Added peliminary support for being able to display verbose paths in a diagnostic * Added 'clearCache' support * Added verbose path support to SourceManager (now needs a ISlangFileSystemExt to do this) * Added support for '-verbose-path' option to slangc and slang-test.
Diffstat (limited to 'source/slang/source-loc.h')
-rw-r--r--source/slang/source-loc.h55
1 files changed, 34 insertions, 21 deletions
diff --git a/source/slang/source-loc.h b/source/slang/source-loc.h
index ee4049473..aa0623e3d 100644
--- a/source/slang/source-loc.h
+++ b/source/slang/source-loc.h
@@ -44,32 +44,32 @@ struct PathInfo
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')
+ Normal, ///< Normal has both path and uniqueIdentity
+ FoundPath, ///< Just has a found path (uniqueIdentity 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; }
+ SLANG_FORCE_INLINE bool hasUniqueIdentity() const { return type == Type::Normal && uniqueIdentity.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;
+ /// Returns the 'most unique' identity for the path. If has a 'uniqueIdentity' returns that, else the foundPath, else "".
+ const String getMostUniqueIdentity() 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", String() }; }
static PathInfo makeTokenPaste() { return PathInfo{ Type::TokenPaste, "token paste", String()}; }
- 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 makeNormal(const String& foundPathIn, const String& uniqueIdentity) { SLANG_ASSERT(uniqueIdentity.Length() > 0 && foundPathIn.Length() > 0); return PathInfo { Type::Normal, foundPathIn, uniqueIdentity }; }
static PathInfo makePath(const String& pathIn) { SLANG_ASSERT(pathIn.Length() > 0); return PathInfo { Type::FoundPath, pathIn, String()}; }
static PathInfo makeTypeParse() { return PathInfo { Type::TypeParse, "type string", String() }; }
static PathInfo makeCommandLine() { return PathInfo { Type::CommandLine, "command line", String() }; }
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
+ String uniqueIdentity; ///< The unique identity of the file on the path found
};
class SourceLoc
@@ -139,6 +139,9 @@ struct SourceRange
SourceLoc end;
};
+// Pre-declare
+struct SourceManager;
+
// A logical or physical storage object for a range of input code
// that has logically contiguous source locations.
class SourceFile
@@ -178,13 +181,20 @@ public:
/// Set the content as a string
void setContents(const String& content);
+ /// Calculate a display path -> can canonicalize if necessary
+ String calcVerbosePath() const;
+
+ /// Get the source manager this was created on
+ SourceManager* getSourceManager() const { return m_sourceManager; }
+
/// Ctor
- SourceFile(const PathInfo& pathInfo, size_t contentSize);
+ SourceFile(SourceManager* sourceManager, const PathInfo& pathInfo, size_t contentSize);
/// Dtor
~SourceFile();
protected:
+ 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<ISlangBlob> 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.
@@ -210,8 +220,6 @@ struct HumaneSourceLoc
Int column = 0;
};
-// Pre-declare
-struct SourceManager;
/* A SourceView maps to a single span of SourceLoc range and is equivalent to a single include or more precisely use of a source file.
It is distinct from a SourceFile - because a SourceFile may be included multiple times, with different interpretations (depending
@@ -257,7 +265,7 @@ class SourceView
/// Get the source file holds the contents this view
SourceFile* getSourceFile() const { return m_sourceFile; }
/// Get the source manager
- SourceManager* getSourceManager() const { return m_sourceManager; }
+ SourceManager* getSourceManager() const { return m_sourceFile->getSourceManager(); }
/// Get the associated 'content' (the source text)
const UnownedStringSlice& getContent() const { return m_sourceFile->getContent(); }
@@ -273,8 +281,7 @@ class SourceView
PathInfo getPathInfo(SourceLoc loc, SourceLocType type = SourceLocType::Nominal);
/// Ctor
- SourceView(SourceManager* sourceManager, SourceFile* sourceFile, SourceRange range):
- m_sourceManager(sourceManager),
+ SourceView(SourceFile* sourceFile, SourceRange range):
m_range(range),
m_sourceFile(sourceFile)
{
@@ -283,7 +290,6 @@ class SourceView
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
SourceFile* m_sourceFile; ///< The source file. Can hold the line breaks
List<Entry> m_entries; ///< An array entries describing how we should interpret a range, starting from the start location.
@@ -292,7 +298,7 @@ class SourceView
struct SourceManager
{
// Initialize a source manager, with an optional parent
- void initialize(SourceManager* parent);
+ void initialize(SourceManager* parent, ISlangFileSystemExt* fileSystemExt);
/// Allocate a range of SourceLoc locations, these can be used to identify a specific location in the source
SourceRange allocateSourceRange(UInt size);
@@ -322,12 +328,17 @@ struct SourceManager
/// Searches this manager, and then the parent to see if can find a match for path.
/// If not found returns nullptr.
- SourceFile* findSourceFileRecursively(const String& canonicalPath) const;
+ SourceFile* findSourceFileRecursively(const String& uniqueIdentity) const;
/// Find if the source file is defined on this manager.
- SourceFile* findSourceFile(const String& canonicalPath) const;
+ SourceFile* findSourceFile(const String& uniqueIdentity) const;
- /// Add a source file, path must be unique for this manager AND any parents
- void addSourceFile(const String& canonicalPath, SourceFile* sourceFile);
+ /// Get the file system associated with this source manager
+ ISlangFileSystemExt* getFileSystemExt() const { return m_fileSystemExt; }
+ /// Get the file system associated with this source manager
+ void setFileSystemExt(ISlangFileSystemExt* fileSystemExt) { m_fileSystemExt = fileSystemExt; }
+
+ /// Add a source file, uniqueIdentity must be unique for this manager AND any parents
+ void addSourceFile(const String& uniqueIdentity, SourceFile* sourceFile);
/// Get the slice pool
StringSlicePool& getStringSlicePool() { return m_slicePool; }
@@ -374,8 +385,10 @@ struct SourceManager
// Can be used for storing the decoded contents of Token. Content for example.
MemoryArena m_memoryArena;
- // Maps canonical paths to source files
- Dictionary<String, SourceFile*> m_sourceFileMap;
+ // Maps uniqueIdentities to source files
+ Dictionary<String, SourceFile*> m_sourceFileMap;
+
+ ComPtr<ISlangFileSystemExt> m_fileSystemExt;
};
} // namespace Slang