Clarify FileReader interface.

This commit is contained in:
chriseth
2021-12-13 14:54:58 +01:00
parent 9131475b7c
commit 0e6388a907
4 changed files with 38 additions and 39 deletions
+2 -2
View File
@@ -84,7 +84,7 @@ void FileReader::allowDirectory(boost::filesystem::path _path)
m_allowedDirectories.insert(std::move(_path));
}
void FileReader::setSource(boost::filesystem::path const& _path, SourceCode _source)
void FileReader::addOrUpdateFile(boost::filesystem::path const& _path, SourceCode _source)
{
m_sourceCodes[cliPathToSourceUnitName(_path)] = std::move(_source);
}
@@ -94,7 +94,7 @@ void FileReader::setStdin(SourceCode _source)
m_sourceCodes["<stdin>"] = std::move(_source);
}
void FileReader::setSources(StringMap _sources)
void FileReader::setSourceUnits(StringMap _sources)
{
m_sourceCodes = std::move(_sources);
}
+7 -8
View File
@@ -61,18 +61,17 @@ public:
void allowDirectory(boost::filesystem::path _path);
FileSystemPathSet const& allowedDirectories() const noexcept { return m_allowedDirectories; }
StringMap const& sourceCodes() const noexcept { return m_sourceCodes; }
/// Retrieves the source code for a given source unit name.
SourceCode const& sourceCode(SourceUnitName const& _sourceUnitName) const { return m_sourceCodes.at(_sourceUnitName); }
/// @returns all sources by their internal source unit names.
StringMap const& sourceUnits() const noexcept { return m_sourceCodes; }
/// Resets all sources to the given map of source unit name to source codes.
/// Does not enforce @a allowedDirectories().
void setSources(StringMap _sources);
void setSourceUnits(StringMap _sources);
/// Adds the source code under a source unit name created by normalizing the file path.
/// Adds the source code under a source unit name created by normalizing the file path
/// or changes an existing source.
/// Does not enforce @a allowedDirectories().
void setSource(boost::filesystem::path const& _path, SourceCode _source);
void addOrUpdateFile(boost::filesystem::path const& _path, SourceCode _source);
/// Adds the source code under the source unit name of @a <stdin>.
/// Does not enforce @a allowedDirectories().
@@ -83,7 +82,7 @@ public:
/// The read will only succeed if the canonical path of the file is within one of the @a allowedDirectories().
/// @param _kind must be equal to "source". Other values are not supported.
/// @return Content of the loaded file or an error message. If the operation succeeds, a copy of
/// the content is retained in @a sourceCodes() under the key of @a _sourceUnitName. If the key
/// the content is retained in @a sourceUnits() under the key of @a _sourceUnitName. If the key
/// already exists, previous content is discarded.
frontend::ReadCallback::Result readFile(std::string const& _kind, std::string const& _sourceUnitName);