Closed timjroberts closed 1 year ago
The core work for this is now complete. I've identified some future work to support both 'include ...'
quotation styles, but landing this PR will close the loop on integrating the Workspace Manager with the Analyzer, and allow other features to progress.
This PR addresses #15 by accumulating included file paths during preprocessing, and then resolving them as part of the background processing of files. Because included paths are resolved via the Workspaces, the process is entirely recursive.
Tasks
FileId
).2. Consider how best to report errors (i.e., if a file is physically not present on the underlying file system).3. Think about what happens when an'#include ...'
line get removed.Task Notes
While not using on demand inputs directly, I have used the
on_demand_inputs
page as inspiration, I have extended theDb
trait with a newresolve_path(...)
function that will return an absolute path by joining a given base, and a target path. This function is then used by thepreprocess(...)
function when computing a newFileId
for an included path. This keeps all referenced paths known to the FileSystem in an absolute form, and (more importantly) unique when stored asFileId
s in the Salsa database.The
Analyzer
will report a missing file through its diagnostics. This is all done separately to the workspace manager which will set anErr(IndexError::NotFound)
against theFile
instance.We don't need to worry about this anymore. If an
'#include ...'
line is removed then the accumulated dependencies for the associatedFileId
simply won't include it anymore as part of its new Salsa revision. It will still be present in the Workspace Manager, but that is OK. The Workspace Manager mirrors what is on the 'disk' rather than what the Analyzer currently needs to parse.The
Analyzer::preprocessed(...)
function will now call a newrequire_fn
for anyIncludeDependency
for whichis_resolved
is false. This results in the dependency being loaded in the background and set in the Analyzer.Future Work
Currently the preprocessor only considers relative paths, and it also doesn't consider the quotation style. As such, an include in the form
'#include "core.p4"'
will be resolved relative to the file that contains it. This is correct behavior. Future work is required to support the angle bracket quotation style, and in turn, support for multiple paths while resolving. As outlined in the P4_16 specification, the quotation style simply determines the order in which the preprocessor will need to consider these file paths:'"..."'
using the relative path ahead of any additional include path list, and'<...>'
using the relative path last.