外观
fanc
原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793259036/FIN+5.3.1+fanc 中文整理基于 FIN 5.3.1
导读: Fan 命令行编译器
以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。
目录(导读)
- mixins
- classes
- enums
- Slot Details
- indent
- m
- nl
- sp
- unindent
- w
- make
- andExpr
- asExpr
- assignExpr
- binaryExpr
- binaryOperator
- callExpr
- callMethodExpr
- closureExpr
- coerceExpr
- compareExpr
- compareNotNullExpr
- compareNullExpr
- condExpr
- cparen
- ctorExpr
- decimalLiteral
- doExpr
- durationLiteral
- elvisExpr
- expr
- falseLiteral
- fieldExpr
- floatLiteral
- intLiteral
- isExpr
- isTopExpr
- isnotExpr
- itExpr
- listLiteral
- localExpr
- mapLiteral
- notExpr
- notSameExpr
- nullLiteral
- oparen
- orExpr
- postfixLeaveExpr
- rangeLiteral
- safeCallExpr
- sameExpr
- shortcutAssignExpr
- shortcutExpr
- slotLiteral
- staticTargetExpr
- strLiteral
- superExpr
- ternaryExpr
- thisExpr
- throwExpr
- trapExpr
- trueLiteral
- typeLiteral
- unaryExpr
- unaryOperator
- uriLiteral
- aliases
- appName
- err
- find
- info
- list
- log
- name
- names
- printLine
- promptConfirm
- run
- summary
- fromStr
- isNo
- isYes
- no
- vals
- yes
- closure
- curMethod
- curType
- selfVar
- wrappers
- main
- block
- breakStmt
- continueStmt
- exprStmt
- forStmt
- ifStmt
- localDefStmt
- returnStmt
- stmt
- switchStmt
- throwStmt
- tryStmt
- whileStmt
- buildScriptMap
- compilePod
- compiler
- flattenPods
- genPod
- genType
- init
- outDir
- podNames
- pods
- stdCompilerInput
- transpile
- buildScript
- podFile
- toStr
- version
API 正文(英文)
enums
| JavaParameterize | JavaParameterize |
CodePrinter
mixin CodePrinter
Pretty print transpiled source code
Methods
| indent | Indent next lines |
| m | Class state |
| nl | Print newline |
| sp | Print space |
| unindent | Unindent next lines |
| w | Print object - must never include newline, use nl |
Slot Details
indent
This indent()
Indent next lines
m
abstract CodePrinterState m()
Class state
nl
This nl()
Print newline
sp
This sp()
Print space
unindent
This unindent()
Unindent next lines
w
This w(Obj o)
Print object - must never include newline, use nl
CodePrinterState
class CodePrinterState : Obj
CodePrinterState
Constructors
| make |
Slot Details
make
new make(OutStream out)
ExprPrinter
mixin ExprPrinter : CodePrinter
CodePrinter routing for Expr nodes
Methods
| andExpr | |
| asExpr | |
| assignExpr | |
| binaryExpr | Write binary expression with optional grouping parens |
| binaryOperator | Return operator if given method qname maps to binary operator or null |
| callExpr | Call expression handling |
| callMethodExpr | Normal call method |
| closureExpr | |
| coerceExpr | |
| compareExpr | |
| compareNotNullExpr | |
| compareNullExpr | |
| condExpr | Write list of cond with operator with optional grouping parens |
| cparen | Close paren only if not top expr |
| ctorExpr | Constructor call expression |
| decimalLiteral | |
| doExpr | |
| durationLiteral | |
| elvisExpr | |
| expr | |
| falseLiteral | |
| fieldExpr | |
| floatLiteral | |
| intLiteral | |
| isExpr | |
| isTopExpr | Top expr - if false might need to wrap some exprs in parens |
| isnotExpr | |
| itExpr | |
| listLiteral | |
| localExpr | |
| mapLiteral | |
| notExpr | |
| notSameExpr | |
| nullLiteral | |
| oparen | Open paren only if not top expr |
| orExpr | |
| postfixLeaveExpr | Handle postfix ++ or -- |
| rangeLiteral | |
| safeCallExpr | Null safe call expression handling |
| sameExpr | |
| shortcutAssignExpr | Handle special assign+math operators: += -= *= /= |
| shortcutExpr | Shortcut special handling for comparison, otherwise route to callExpr |
| slotLiteral | |
| staticTargetExpr | |
| strLiteral | |
| superExpr | |
| ternaryExpr | |
| thisExpr | |
| throwExpr | |
| trapExpr | Trap call expression handling |
| trueLiteral | |
| typeLiteral | |
| unaryExpr | Write unary expression with optional grouping parens |
| unaryOperator | Return operator if given method qname maps to unary operator or null |
| uriLiteral |
Slot Details
andExpr
abstract This andExpr(CondExpr x)
asExpr
abstract This asExpr(TypeCheckExpr x)
assignExpr
abstract This assignExpr(BinaryExpr x)
binaryExpr
virtual This binaryExpr(Expr lhs, Str op, Expr rhs)
Write binary expression with optional grouping parens
binaryOperator
virtual Str? binaryOperator(Str qname)
Return operator if given method qname maps to binary operator or null
callExpr
virtual This callExpr(CallExpr x)
Call expression handling
callMethodExpr
abstract This callMethodExpr(CallExpr x)
Normal call method
closureExpr
abstract This closureExpr(ClosureExpr x)
coerceExpr
abstract This coerceExpr(TypeCheckExpr x)
compareExpr
abstract This compareExpr(Expr lhs, Token op, Expr rhs)
compareNotNullExpr
abstract This compareNotNullExpr(UnaryExpr x)
compareNullExpr
abstract This compareNullExpr(UnaryExpr x)
condExpr
virtual This condExpr(Str op, Expr[] operands)
Write list of cond with operator with optional grouping parens
cparen
This cparen()
Close paren only if not top expr
ctorExpr
abstract This ctorExpr(CallExpr x)
Constructor call expression
decimalLiteral
abstract This decimalLiteral(LiteralExpr x)
doExpr
virtual This doExpr(Expr x)
durationLiteral
abstract This durationLiteral(LiteralExpr x)
elvisExpr
abstract This elvisExpr(BinaryExpr x)
expr
virtual This expr(Expr x)
falseLiteral
abstract This falseLiteral(LiteralExpr x)
fieldExpr
abstract This fieldExpr(FieldExpr x)
floatLiteral
abstract This floatLiteral(LiteralExpr x)
intLiteral
abstract This intLiteral(LiteralExpr x)
isExpr
abstract This isExpr(TypeCheckExpr x)
isTopExpr
Bool isTopExpr()
Top expr - if false might need to wrap some exprs in parens
isnotExpr
abstract This isnotExpr(TypeCheckExpr x)
itExpr
abstract This itExpr(LocalVarExpr x)
listLiteral
abstract This listLiteral(ListLiteralExpr x)
localExpr
abstract This localExpr(LocalVarExpr x)
mapLiteral
abstract This mapLiteral(MapLiteralExpr x)
notExpr
abstract This notExpr(UnaryExpr x)
notSameExpr
abstract This notSameExpr(BinaryExpr x)
nullLiteral
abstract This nullLiteral(LiteralExpr x)
oparen
This oparen()
Open paren only if not top expr
orExpr
abstract This orExpr(CondExpr x)
postfixLeaveExpr
abstract This postfixLeaveExpr(ShortcutExpr x)
Handle postfix ++ or --
rangeLiteral
abstract This rangeLiteral(RangeLiteralExpr x)
safeCallExpr
abstract This safeCallExpr(CallExpr x)
Null safe call expression handling
sameExpr
abstract This sameExpr(BinaryExpr x)
shortcutAssignExpr
abstract This shortcutAssignExpr(ShortcutExpr x)
Handle special assign+math operators: += -= *= /=
shortcutExpr
virtual This shortcutExpr(ShortcutExpr x)
Shortcut special handling for comparison, otherwise route to callExpr
slotLiteral
abstract This slotLiteral(SlotLiteralExpr x)
staticTargetExpr
abstract This staticTargetExpr(StaticTargetExpr x)
strLiteral
abstract This strLiteral(LiteralExpr x)
superExpr
abstract This superExpr(LocalVarExpr x)
ternaryExpr
abstract This ternaryExpr(TernaryExpr x)
thisExpr
abstract This thisExpr(LocalVarExpr x)
throwExpr
abstract This throwExpr(ThrowExpr x)
trapExpr
abstract This trapExpr(CallExpr x)
Trap call expression handling
trueLiteral
abstract This trueLiteral(LiteralExpr x)
typeLiteral
abstract This typeLiteral(LiteralExpr x)
unaryExpr
virtual This unaryExpr(Str op, Expr operand)
Write unary expression with optional grouping parens
unaryOperator
virtual Str? unaryOperator(Str qname)
Return operator if given method qname maps to unary operator or null
uriLiteral
abstract This uriLiteral(LiteralExpr x)
FancCmd
abstract class FancCmd : AbstractMain
Fantom CLI compiler command plugin. To create:
- Define subclass of FancCmd
- Register type qname via indexed prop as "fanc.cmd" (if not in this pod)
- Annotate options and args using
AbstractMaindesign
Methods
| aliases | Command name alises/shortcuts |
| appName | App name is "fanc {name}" |
| err | Print error message and return 1 |
| find | Find a specific command or return null |
| info | Print info message |
| list | List installed commands |
| log | Log name is "fanc" |
| name | Command name |
| names | Name and aliases |
| printLine | Print a line to stdout |
| promptConfirm | Prompt for a confirm yes/no |
| run | Run the command. |
| summary | Single line summary of the command for help |
Slot Details
aliases
virtual Str[] aliases()
Command name alises/shortcuts
appName
override Str appName()
App name is "fanc {name}"
err
Int err(Str msg)
Print error message and return 1
find
static FancCmd? find(Str name)
Find a specific command or return null
info
Void info(Str msg)
Print info message
list
static FancCmd[] list()
List installed commands
log
virtual override Log log()
Log name is "fanc"
name
abstract Str name()
Command name
names
Str[] names()
Name and aliases
printLine
Void printLine(Str line := "")
Print a line to stdout
promptConfirm
Bool promptConfirm(Str msg)
Prompt for a confirm yes/no
run
abstract override Int run()
Run the command. Return zero on success
summary
abstract Str summary()
Single line summary of the command for help
JavaParameterize
@Serializable { simple=true } enum class JavaParameterize : Enum
JavaParameterize
Enum
| no | |
| yes |
Constructors
| fromStr | Return the JavaParameterize instance for the specified name. |
Fields
| vals | List of JavaParameterize values indexed by ordinal |
Methods
| isNo | |
| isYes |
Slot Details
fromStr
static new fromStr(Str name, Bool checked := true)
Return the JavaParameterize instance for the specified name. If not a valid name and checked is false return null, otherwise throw ParseErr.
isNo
Bool isNo()
isYes
Bool isYes()
no
const static JavaParameterize no := ...
vals
const static JavaParameterize[] vals := ...
List of JavaParameterize values indexed by ordinal
yes
const static JavaParameterize yes := ...
JavaPrinterState
class JavaPrinterState : CodePrinterState
JavaPrinterState
Constructors
| make |
Fields
| closure | |
| curMethod | |
| curType | |
| selfVar | |
| wrappers |
Slot Details
closure
TypeDef? closure
curMethod
MethodDef? curMethod
curType
TypeDef? curType
make
new make(OutStream out)
selfVar
Str? selfVar
wrappers
Str:TypeDef wrappers := [Str:TypeDef][:]
Main
class Main : Obj
Fantom command line compiler tools
Methods
| main |
Slot Details
main
static Int main(Str[] args)
SafeLocalVar
class SafeLocalVar : ItExpr
SafeLocalVar
Constructors
| make |
Methods
| name |
Slot Details
make
new make(Loc loc, CType type)
name
virtual override Str name()
StmtPrinter
mixin StmtPrinter : CodePrinter
CodePrinter routing for Stmt nodes
Methods
| block | |
| breakStmt | |
| continueStmt | |
| exprStmt | |
| forStmt | |
| ifStmt | |
| localDefStmt | |
| returnStmt | |
| stmt | |
| switchStmt | |
| throwStmt | |
| tryStmt | |
| whileStmt |
Slot Details
block
virtual This block(Block x)
breakStmt
abstract This breakStmt(BreakStmt x)
continueStmt
abstract This continueStmt(ContinueStmt x)
exprStmt
abstract This exprStmt(ExprStmt x)
forStmt
abstract This forStmt(ForStmt x)
ifStmt
abstract This ifStmt(IfStmt x)
localDefStmt
abstract This localDefStmt(LocalDefStmt x)
returnStmt
abstract This returnStmt(ReturnStmt x)
stmt
virtual This stmt(Stmt x)
switchStmt
abstract This switchStmt(SwitchStmt x)
throwStmt
abstract This throwStmt(ThrowStmt x)
tryStmt
abstract This tryStmt(TryStmt x)
whileStmt
abstract This whileStmt(WhileStmt x)
TranspileCmd
abstract class TranspileCmd : FancCmd
Base class for transpiler commands
Fields
| compiler | Compiler for current pod |
| outDir | |
| podNames | |
| pods | Pod data with flattened dependency chain |
Methods
| buildScriptMap | Map of pod name to build scripts for environment |
| compilePod | Compile build script into AST |
| flattenPods | Expand command line pod names to their full dependency chain. |
| genPod | Generate pod which calls genType for each non-synthetic |
| genType | Generate non-synthetic type |
| init | Standard initializaton |
| run | Call compilePod on every target |
| stdCompilerInput | Use the build script to generate the standard compiler input and then inovke the callback on it for additonal configuration. |
| transpile | Delete outDir and run compilePod on all pods |
Slot Details
buildScriptMap
Str:File buildScriptMap()
Map of pod name to build scripts for environment
compilePod
virtual Void compilePod(TranspilePod pod)
Compile build script into AST
compiler
Compiler? compiler
Compiler for current pod
flattenPods
Void flattenPods()
Expand command line pod names to their full dependency chain. We require all podNames to be pre-compiled using normal Fantom compilation
genPod
virtual Void genPod(PodDef pod)
Generate pod which calls genType for each non-synthetic
genType
virtual Void genType(TypeDef type)
Generate non-synthetic type
init
virtual Void init()
Standard initializaton
outDir
@Opt { help="Output directory" } File outDir := ...
podNames
@Arg { help="Target pod(s)" } Str[] podNames := Str[,]
pods
TranspilePod[] pods := TranspilePod[,]
Pod data with flattened dependency chain
run
override Int run()
Call compilePod on every target
stdCompilerInput
virtual CompilerInput stdCompilerInput(TranspilePod pod, |CompilerInput|? f := null)
Use the build script to generate the standard compiler input and then inovke the callback on it for additonal configuration.
transpile
virtual Int transpile()
Delete outDir and run compilePod on all pods
TranspilePod
class TranspilePod : Obj
Pod data for every pod to comile
Constructors
| make |
Fields
| buildScript | |
| name | |
| podFile | |
| version |
Methods
| toStr |
Slot Details
buildScript
const File buildScript
make
new make(|This| f)
name
const Str name
podFile
const File podFile
toStr
virtual override Str toStr()
version
const Version version