java - The Ceylon Typechecker: How to obtain the typed syntax tree? -
im trying programmatically use / embed ceylon typechecker analyse ceylon source code. in use case want access information compiler consume. im not going compile , im not going add dependency on compiler.
it seem me main.main entry point in ceylon/typechecker/src/main/main.java not appropriate entry point use case (obtaining typed tree , attached models), because information, collected visitors in 3 checker passes discarded, , errors printed.
so, question is:
how can parse , typecheck compilation unit , obtain 1. typed syntax tree, , 2. associated model objects of types analysis visitors encounter in tree, linked tree.
edited:
there (and is) confusion on side 3 different asts there are.
in readme in ceylon /ceylon.ast said:
¨ ... ceylon.ast.core – ceylon classes represent ceylon ast. pure ceylon (backend-independent). ... ceylon.ast.redhat – transforms ceylon.ast.core ast + redhat compiler (ceylon-spec ast, , contains functions compile ceylon.ast.core ast code string (using redhat compiler) ... ¨.
so there 3 asts: 1. 1 generated antlr, 2. ceylon.ast.core, , 3. ceylon.ast.redhat. why?
in short, you'll want to:
- configure
typecheckerbuilder
source files want typecheck, - obtain
typechecker
builder (builder.typechecker
), - invoke typechecker (
typechecker.process()
), - process results available
typechecker.phasedunits
. specifically,typechecker.getphasedunits().getphasedunits()
givelist<phasedunit>
, , eachphasedunit
, can callgetcompilationunit()
obtaintree.compilationunit
, root of ast. ast nodes include getters model objects.
for detailed example, can review code dart backend, working forwards , backwards the call process()
in compiledart()
function.
see testcompile example code calls compiledart()
.
Comments
Post a Comment