Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,40 +142,47 @@ object AddDependencies
isAbsolute
).map(addDependencies (a)).getOrElse(Right(a))

private def addDependenciesHelper(a: Analysis, specLoc: Ast.SpecLoc, file: File): Result = {
val dependencyFileSet = a.dependencyFileSet + file
val directDependencyFileSet = a.level match {
case 1 => a.directDependencyFileSet + file
case _ => a.directDependencyFileSet
}
val a1 = a.copy(
dependencyFileSet = dependencyFileSet,
directDependencyFileSet = directDependencyFileSet
)
private def addDependenciesForFile(a: Analysis, file: File): Result =
val scopeNameList = a.scopeNameList
val result = for {
tu <- Parser.parseFile (Parser.transUnit) (None) (file)
pair <- ResolveSpecInclude.transUnit(a1, tu)
a2 <- ComputeDependencies.tuList(
pair._1.copy(
(a, tu) <- ResolveSpecInclude.transUnit(a, tu)
a <- ComputeDependencies.tuList(
a.copy(
scopeNameList = Nil,
dependencyTuMap = pair._1.dependencyTuMap + (file -> pair._2)
dependencyTuMap = a.dependencyTuMap + (file -> tu)
),
List(pair._2)
List(tu)
)
} yield a2.copy(scopeNameList = a1.scopeNameList)
} yield a.copy(scopeNameList = scopeNameList)
result match {
case Left(FileError.CannotOpen(_, _)) => {
val a = a1.copy(missingDependencyFileSet = a1.missingDependencyFileSet + file)
Right(a)
val missingDependencyFileSet = a.missingDependencyFileSet + file
Right(a.copy(missingDependencyFileSet = missingDependencyFileSet))
}
case _ => result
}
}

private def updateDirectDependencyFileSet(a: Analysis, file: File) =
val directDependencyFileSet = a.directDependencyFileSet + file
a.copy(directDependencyFileSet = directDependencyFileSet)

private def updateDependencyFileSet(a: Analysis, file: File) =
val dependencyFileSet = a.dependencyFileSet + file
a.copy(dependencyFileSet = dependencyFileSet)

private def addDependencies (a: Analysis) (specLoc: Ast.SpecLoc): Result = {
val file = getFile(specLoc)
if !a.inputFileSet.contains(file) && !a.dependencyFileSet.contains(file)
then addDependenciesHelper(a, specLoc, file)
if !a.inputFileSet.contains(file)
then
val a1 = if a.level == 1
then updateDirectDependencyFileSet(a, file)
else a
if !a1.dependencyFileSet.contains(file)
then
val a2 = updateDependencyFileSet(a1, file)
addDependenciesForFile(a2, file)
else Right(a1)
else Right(a)
}

Expand Down
9 changes: 9 additions & 0 deletions compiler/tools/fpp-depend/test/direct_already_seen.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Test direct dependencies already seen at a lower level
# The dependency on b exists in direct_already_seen_a.fpp at level 2
# But it should be reported here as a direct dependency

locate constant a at "direct_already_seen_a.fpp"
locate constant b at "direct_already_seen_b.fpp"

constant c = a
constant d = b
2 changes: 2 additions & 0 deletions compiler/tools/fpp-depend/test/direct_already_seen.ref.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ local path prefix ]/compiler/tools/fpp-depend/test/direct_already_seen_a.fpp
[ local path prefix ]/compiler/tools/fpp-depend/test/direct_already_seen_b.fpp
1 change: 1 addition & 0 deletions compiler/tools/fpp-depend/test/direct_already_seen_a.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
constant a = b
1 change: 1 addition & 0 deletions compiler/tools/fpp-depend/test/direct_already_seen_b.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
constant b = 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ local path prefix ]/compiler/tools/fpp-depend/test/direct_already_seen_a.fpp
[ local path prefix ]/compiler/tools/fpp-depend/test/direct_already_seen_b.fpp
9 changes: 9 additions & 0 deletions compiler/tools/fpp-depend/test/run
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ direct()
test $run_test_status -eq 0
}

direct_already_seen()
{
run_test '-d tmp.out.txt' direct_already_seen
run_test_status=$?
remove_path_prefix < tmp.out.txt > direct_already_seen_output.out.txt
compare direct_already_seen_output && \
test $run_test_status -eq 0
}

filenames()
{
run_test '-g filenames_generated_output.out.txt -u filenames_ut_output.out.txt' \
Expand Down
1 change: 1 addition & 0 deletions compiler/tools/fpp-depend/test/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def_system
dictionary
dictionary_no_deployment_top
direct
direct_already_seen
enum_constant
expr_array
expr_binop
Expand Down
5 changes: 5 additions & 0 deletions compiler/tools/fpp-depend/test/update-ref
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ direct() {
remove_path_prefix < tmp.out.txt > direct_output.ref.txt
}

direct_already_seen() {
update '-d tmp.out.txt' direct_already_seen
remove_path_prefix < tmp.out.txt > direct_already_seen_output.ref.txt
}

filenames() {
update '-g filenames_generated_output.ref.txt -u filenames_ut_output.ref.txt' \
../../fpp-filenames/test/ok filenames
Expand Down
38 changes: 21 additions & 17 deletions docs/wiki/Computing-Dependencies.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This algorithm computes dependencies for a list of translation units.
_a_. The
https://github.com/nasa/fpp/wiki/Analysis-Data-Structure[input file set]
of _a_ must record the set of files presented for analysis.
The level must be zero, and the scope name list must be empty.

. A list _tul_ of FPP translation units.

Expand All @@ -30,12 +31,14 @@ Run the <<dependency-algorithm,dependency algorithm>> on _tul_.
To run the dependency algorithm on a translation unit list _tul_, do the
following:

. *Increment the level:* Increment the level in _a_.

. *Resolve include specifiers:* Recursively resolve include specifiers in
_tul_.
Add the path of each included file to the included file set in _a_.
If the
https://github.com/nasa/fpp/wiki/Analysis-Data-Structure[level of _a_]
is zero, then add the path of each included file to the direct dependency
is one, then add the path of each included file to the direct dependency
file set in _a_.

. *Build the location specifier map:* Traverse each translation unit _tu_ in
Expand Down Expand Up @@ -133,46 +136,47 @@ file set, if _f_ appears in the dependency file set, then delete it
from the set.
The dependency is already recorded in the file that includes _f_.

. *Decrement the level:* Decrement the level in _a_.

[[adding-dependencies]]
=== Adding Dependencies for a Location Specifier

To add a dependency for a location specifier _s_, do the following:

. Compute the absolute path _p_ associated with _s_.

. If _p_ is in the
. If _p_ is not in the
https://github.com/nasa/fpp/wiki/Analysis-Data-Structure[input file set]
of _a_ or is already in the
https://github.com/nasa/fpp/wiki/Analysis-Data-Structure[dependency file set]
of _a_, then do nothing.
of _a_, then

. Otherwise

.. If the level of _a_ is zero, then add _p_ to the
.. If the level of _a_ is one, then add _p_ to the
https://github.com/nasa/fpp/wiki/Analysis-Data-Structure[direct dependency file set]
of _a_.

.. Add _p_ to the
.. If _p_ is not already in the
https://github.com/nasa/fpp/wiki/Analysis-Data-Structure[dependency file set]
of _a_, then

... Add _p_ to the
https://github.com/nasa/fpp/wiki/Analysis-Data-Structure[dependency file set]
of _a_.

.. If the file _f_ at _p_ exists, then
... If the file _f_ at _p_ exists, then

... Parse _f_, generating a translation unit _tu_.
.... Parse _f_, generating a translation unit _tu_.

... Recursively resolve include specifiers in _tu_.
.... Recursively resolve include specifiers in _tu_.
Add the path of each included file to the included file set in _a_.

... Add the mapping from _p_ to _tu_ to the
.... Add the mapping from _p_ to _tu_ to the
https://github.com/nasa/fpp/wiki/Analysis-Data-Structure[dependency
translation unit map] of _a_.

... Run the <<dependency-algorithm,dependency algorithm>> on the list _[ tu ]_
.... Run the <<dependency-algorithm,dependency algorithm>> on the list _[ tu ]_
with the value of _a_ computed so far,
but with an empty scope name list.
Restore the current level and scope name list and
let the result be the new _a_.
Restore the current scope name list and let the result be the new _a_.

.. Otherwise add _p_ to the
... Otherwise add _p_ to the
https://github.com/nasa/fpp/wiki/Analysis-Data-Structure[missing
dependency file set] of _a_.
Loading