Skip to content

Commit

Permalink
check depends in compilerx
Browse files Browse the repository at this point in the history
  • Loading branch information
chunquedong committed Oct 12, 2021
1 parent 902128c commit 5b6c3e6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion compiler/compilerx/fan/Main.fan
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Main
if (options != null) {
options["pod_name"] = podName
options["pod_main"] = pod.types[0].qname
options["pod_depends"] = pod.depends.map { it.name }
options["pod_depends"] = pod.resolvedDepends.keys
}

return compiler.context.js
Expand Down
42 changes: 23 additions & 19 deletions compiler/compilerx/fan/checkType/ResolveDepends.fan
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,43 @@ class ResolveDepends : CompilerStep
// assume a dependency on sys
pod := compiler.pod
isSys := pod.name == "sys"
if (pod.depends.isEmpty && !isSys)
pod.depends.add(Depend.fromStr("sys 2"))
if (pod.depends.isEmpty) {
if (!isSys) {
pod.depends.add(Depend.fromStr("sys 2"))
if (pod.name != "std") {
pod.depends.add(Depend.fromStr("std 1"))
}
}
}

// we initialize the CNamespace.depends map
// as we process each dependency
compiler.pod.resolvedDepends = [Str:CPod][:]

// process each dependency
resolvePodDepend(pod)

// check that everything has a dependency on sys
//if (!isSys && !ns.depends.containsKey("sys"))
// err("All pods must have a dependency on 'sys'", loc)

// depends self
//ns.depends[pod.name] = pod
}

private Void resolvePodDepend(CPod pod) {
pod.depends.each |cdepend|
{
name := cdepend.name
if (name == compiler.pod.name) {
err("Cyclic dependency on self '$name' in ${pod.name}", loc)
}

dpod := compiler.pod.resolvedDepends[name]
if (dpod == null) {
dpod = resolveDepend(cdepend)
compiler.pod.resolvedDepends[name] = dpod
resolvePodDepend(pod)

dpod := resolveDepend(cdepend)
compiler.pod.resolvedDepends[name] = dpod

dpod.depends.each |podDepend|
{
if (podDepend.name == compiler.pod.name)
err("Cyclic dependency on '$compiler.pod.name'", loc)
}
}

// check that everything has a dependency on sys
if (!isSys && !compiler.pod.resolvedDepends.containsKey("sys"))
err("All pods must have a dependency on 'sys'", loc)

// depends self
//ns.depends[pod.name] = pod
}

**
Expand Down
2 changes: 1 addition & 1 deletion compiler/compilerx/fan/checkType/ResolveImports.fan
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class ResolveImports : CompilerStep
**
** Check that a pod name is in the dependency list.
**
private static Void checkUsingPod(CompilerContext cs, Str podName, Loc loc)
static Void checkUsingPod(CompilerContext cs, Str podName, Loc loc)
{
// scripts don't need dependencies
if (cs.input.isScript) return
Expand Down
1 change: 1 addition & 0 deletions compiler/compilerx/fan/checkType/ResolveType.fan
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class ResolveType : CompilerStep {
step.err("Unknow type '${type}'", type.loc)
type.resolveTo(step.ns.objType.typeDef)
}
ResolveImports.checkUsingPod(step.compiler, type.typeDef.podName, type.loc)
}
catch (Err e) {
step.err("Unknow type '${type}'", type.loc)
Expand Down
6 changes: 6 additions & 0 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## ChangeLog

### Build 4.1.3 (2021-10-12)
- native: fix Method reflect with default param
- native: Pod.file fallback
- native: fix Str without ConstantFolder
- compiler: check depends in compilerx

### Build 4.1.2 (2021-10-08)
- genC: add Field.size
- Uri field to method
Expand Down

0 comments on commit 5b6c3e6

Please sign in to comment.