Skip to content

Commit

Permalink
Merge pull request #6 from Tensegritics/cgrand-wip
Browse files Browse the repository at this point in the history
back to main line
  • Loading branch information
cgrand authored Mar 4, 2022
2 parents fa6aa21 + da74cfb commit 5e67b65
Show file tree
Hide file tree
Showing 9 changed files with 3,622 additions and 1,155 deletions.
28 changes: 18 additions & 10 deletions bin/analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ final Set<String> libsToDo = {};

final Set<String> libsDone = {};

String addLibIdentifierIfNotContains(Set<String> to, String libPath) {
if (!to.contains(libPath)) to.add(libPath);
return libPath;
}

final Map<String, String> packages = {};

String libPathToPackageName(String path) {
Expand Down Expand Up @@ -100,6 +95,7 @@ class TopLevelVisitor extends ThrowingElementVisitor {
Map<String,dynamic> classData =
{':kind': ':class',
':lib': '"${libPathToPackageName(e.library.identifier)}"',
':const': e.unnamedConstructor?.isConst,
':type-parameters': e.typeParameters.map(emitTypeParameter),
':super': fnil(emitType,e.supertype,null),
':mixins': e.mixins.map(emitType),
Expand All @@ -117,6 +113,7 @@ class TopLevelVisitor extends ThrowingElementVisitor {
for(final c in e.constructors.where(isPublic)) {
classData["\"${c.displayName}\""]=
M({':kind': ':constructor',
':return-type': emitType(c.returnType),
':parameters': c.parameters.map(emitParameter),
':type-parameters': c.typeParameters.map(emitTypeParameter)
});
Expand All @@ -142,7 +139,14 @@ class TopLevelVisitor extends ThrowingElementVisitor {
print("; typedef ${e.displayName}");
}
void visitFunctionElement(FunctionElement e) {
print("; function ${e.displayName} ${e.type.typeFormals}");
print("\"${e.displayName}\"");
Map<String,dynamic> classData =
{':kind': ':function',
':lib': '"${libPathToPackageName(e.library.identifier)}"',
':parameters': e.parameters.map(emitParameter),
':return-type': emitType(e.returnType),
':type-parameters': e.typeParameters.map(emitTypeParameter)};
print(M(classData));
}
void visitExtensionElement(ExtensionElement e) {
print("; extension ${e.displayName}");
Expand All @@ -152,11 +156,15 @@ class TopLevelVisitor extends ThrowingElementVisitor {
Future<void> analyzePaths (session, List<String> paths) async {
for (final p in paths) {
final libraryElementResult = await session.getLibraryByUri(p);
if (libsDone.contains(p)) continue;
libsDone.add(p);
if (!libsDone.add(p)) continue;
if (libraryElementResult is LibraryElementResult) {
final libraryElement = (libraryElementResult as LibraryElementResult).element;
print("\"${addLibIdentifierIfNotContains(libsDone, libPathToPackageName(libraryElement.identifier))}\" {"); // open 1
final packageName = libPathToPackageName(libraryElement.identifier);
if (packageName != p) {
libsToDo.add(packageName);
continue;
}
print("\"$p\" {"); // open 1
for (final top in libraryElement.topLevelElements) {
if (top.isPublic) top.accept(TopLevelVisitor());
}
Expand All @@ -166,7 +174,7 @@ Future<void> analyzePaths (session, List<String> paths) async {
for (final ex in libraryElement.exports) {
if (ex.exportedLibrary != null) {
var n = ex.exportedLibrary?.identifier as String;
addLibIdentifierIfNotContains(libsToDo, n);
libsToDo.add(n);
for (final comb in ex.combinators) {
if (comb is ShowElementCombinator) {
print(M({":lib": "\"${libPathToPackageName(n)}\"", ':shown': comb.shownNames.map((name) => "\"${name}\"").toList()}));
Expand Down
16 changes: 8 additions & 8 deletions clj/src/cljd/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
(println "== Compiling core.cljd -> core.dart ===")
(compile-core)
(loop []
(doseq [n namespaces]
(try (compiler/compile-namespace n)
(catch Exception e
(st/print-stack-trace e))))
(when watch
(println "Press ENTER to recompile files :")
(when (pos? (.read (System/in)))
(recur))))))
(doseq [n namespaces]
(try (compiler/compile-namespace n)
(catch Exception e
(st/print-stack-trace e))))
(when watch
(println "Press ENTER to recompile files :")
(when (pos? (.read (System/in)))
(recur))))))


;; TODO : handle errors of processes
Expand Down
Loading

0 comments on commit 5e67b65

Please sign in to comment.