-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add templating and template ASTPass.swift (#15)
* reformat ASTPass.swift to single lines * add test jinja2 template * add .derived-sources to gitignore and update Package.swift to include derived source * added codegen using jinja2 * turn codegen into a node package and add to top level module * add generate target to makefile * pre-refactor extraction * rename enumCase => enumMember * rename literalToken => token * fix travis yaml
- Loading branch information
Showing
14 changed files
with
2,428 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/.derived-sources | ||
/Packages | ||
/*.xcodeproj | ||
/node_modules | ||
Package.resolved | ||
|
||
*.sol | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// swiftlint:disable all | ||
// | ||
// ASTPass.swift | ||
// AST | ||
// | ||
// Created by Franklin Schrans on 1/11/18. | ||
// | ||
import Diagnostic | ||
import Lexer | ||
|
||
/// A pass over an AST. | ||
/// | ||
/// The class `ASTVisitor` is used to visit an AST using a given `ASTPass`. The appropriate `process` function will be | ||
/// called when visiting a node, and `postProcess` will be called after visiting the children of that node. | ||
public protocol ASTPass { | ||
{# Modules #} | ||
{%- set nodes = [ | ||
"TopLevelModule" | ||
] -%} | ||
|
||
{# Declarations #} | ||
{%- set nodes = nodes.concat([ | ||
"TopLevelDeclaration", | ||
"ContractDeclaration", | ||
"StructDeclaration", | ||
"EnumDeclaration", | ||
"TraitDeclaration", | ||
"ContractBehaviorDeclaration" | ||
]) -%} | ||
|
||
{# Members #} | ||
{%- set nodes = nodes.concat([ | ||
"ContractMember", | ||
"StructMember", | ||
"EnumMember", | ||
"TraitMember", | ||
"ContractBehaviorMember" | ||
]) -%} | ||
|
||
{# Statements #} | ||
{%- set nodes = nodes.concat([ | ||
"Statement", | ||
"ReturnStatement", | ||
"BecomeStatement", | ||
"EmitStatement", | ||
"IfStatement", | ||
"ForStatement" | ||
]) -%} | ||
|
||
{# Declarations #} | ||
{%- set nodes = nodes.concat([ | ||
"VariableDeclaration", | ||
"FunctionDeclaration", | ||
"FunctionSignatureDeclaration", | ||
"SpecialDeclaration", | ||
"SpecialSignatureDeclaration", | ||
"EventDeclaration" | ||
]) -%} | ||
|
||
{# Expression #} | ||
{%- set nodes = nodes.concat([ | ||
"Expression", | ||
"InoutExpression", | ||
"BinaryExpression", | ||
"FunctionCall", | ||
"ArrayLiteral", | ||
"DictionaryLiteral", | ||
"RangeExpression", | ||
"SubscriptExpression", | ||
"AttemptExpression" | ||
]) -%} | ||
|
||
{# Components #} | ||
{%- set nodes = nodes.concat([ | ||
"Attribute", | ||
"Parameter", | ||
"TypeAnnotation", | ||
"Identifier", | ||
"Type", | ||
"Token", | ||
"CallerProtection", | ||
"TypeState", | ||
"Conformance", | ||
"FunctionArgument" | ||
]) -%} | ||
|
||
{%- for node in nodes %} | ||
func process({{ node | camelCase }}: {{ node }}, passContext: ASTPassContext) -> ASTPassResult<{{ node }}> | ||
func postProcess({{ node | camelCase }}: {{ node }}, passContext: ASTPassContext) -> ASTPassResult<{{ node }}> | ||
{% endfor %} | ||
} | ||
|
||
extension ASTPass { | ||
{%- for node in nodes %} | ||
public func process({{ node | camelCase }}: {{ node }}, passContext: ASTPassContext) -> ASTPassResult<{{ node }}> { | ||
return ASTPassResult(element: {{ node | camelCase }}, diagnostics: [], passContext: passContext) | ||
} | ||
|
||
public func postProcess({{ node | camelCase }}: {{ node }}, passContext: ASTPassContext) -> ASTPassResult<{{ node }}> { | ||
return ASTPassResult(element: {{ node | camelCase }}, diagnostics: [], passContext: passContext) | ||
} | ||
{% endfor %} | ||
} | ||
// swiftlint:enable all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.