2015-12-05 07:13:32 -05:00
|
|
|
import tree:*
|
|
|
|
|
import vector:*
|
2015-12-28 03:34:40 -05:00
|
|
|
import set:*
|
2015-12-05 07:13:32 -05:00
|
|
|
import stack:*
|
|
|
|
|
import map:*
|
|
|
|
|
import util:*
|
|
|
|
|
import string:*
|
|
|
|
|
import mem:*
|
|
|
|
|
import io:*
|
2016-01-06 02:46:42 -05:00
|
|
|
import type:*
|
2015-12-05 07:13:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
adt ast_node {
|
|
|
|
|
translation_unit: translation_unit,
|
|
|
|
|
import: import,
|
|
|
|
|
identifier: identifier,
|
|
|
|
|
type_def: type_def,
|
|
|
|
|
adt_def: adt_def,
|
|
|
|
|
function: function,
|
|
|
|
|
code_block: code_block,
|
|
|
|
|
statement: statement,
|
|
|
|
|
if_statement: if_statement,
|
|
|
|
|
match_statement: match_statement,
|
|
|
|
|
case_statement: case_statement,
|
|
|
|
|
while_loop: while_loop,
|
|
|
|
|
for_loop: for_loop,
|
|
|
|
|
return_statement: return_statement,
|
|
|
|
|
break_statement: break_statement,
|
|
|
|
|
continue_statement: continue_statement,
|
|
|
|
|
defer_statement: defer_statement,
|
|
|
|
|
assignment_statement: assignment_statement,
|
|
|
|
|
declaration_statement: declaration_statement,
|
|
|
|
|
if_comp: if_comp,
|
|
|
|
|
simple_passthrough: simple_passthrough,
|
|
|
|
|
function_call: function_call,
|
|
|
|
|
value: value
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
total:
|
|
|
|
|
ASTType type;
|
|
|
|
|
Type* valueType;
|
|
|
|
|
Symbol symbol;
|
|
|
|
|
std::map<std::string, std::vector<NodeTree<ASTData>*>> scope;
|
|
|
|
|
std::set<NodeTree<ASTData>*> closedVariables;
|
|
|
|
|
*/
|
|
|
|
|
fun ast_node_ptr(node: ast_node): *ast_node {
|
|
|
|
|
var to_ret = new<ast_node>()
|
|
|
|
|
to_ret->copy_construct(&node)
|
|
|
|
|
return to_ret
|
|
|
|
|
}
|
2015-12-06 18:44:04 -05:00
|
|
|
fun ast_translation_unit_ptr(name: string): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var obj_var.construct(name): translation_unit
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::translation_unit(obj_var))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_translation_unit(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::translation_unit(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj translation_unit (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
var children: vector<*ast_node>
|
2015-12-06 18:44:04 -05:00
|
|
|
var name: string
|
|
|
|
|
fun construct(nameIn: string): *translation_unit {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
children.construct()
|
2015-12-06 18:44:04 -05:00
|
|
|
name.copy_construct(&nameIn)
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *translation_unit) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
children.copy_construct(&old->children)
|
2015-12-06 18:44:04 -05:00
|
|
|
name.copy_construct(&old->name)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
children.destruct()
|
2015-12-06 18:44:04 -05:00
|
|
|
name.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref translation_unit) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref translation_unit): bool {
|
2015-12-06 18:44:04 -05:00
|
|
|
return children == other.children && name == other.name
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-11 23:41:09 -05:00
|
|
|
fun ast_import_ptr(name: string, translation_unit: *ast_node): *ast_node {
|
|
|
|
|
var to_ret.construct(name, translation_unit): import
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::import(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_import(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::import(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj import (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-28 03:34:40 -05:00
|
|
|
var imported: set<string>
|
2016-01-11 23:41:09 -05:00
|
|
|
var translation_unit: *ast_node
|
2015-12-06 18:44:04 -05:00
|
|
|
var name: string
|
2016-01-11 23:41:09 -05:00
|
|
|
fun construct(nameIn: string, translation_unit_in: *ast_node): *import {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-28 03:34:40 -05:00
|
|
|
imported.construct()
|
2015-12-06 18:44:04 -05:00
|
|
|
name.copy_construct(&nameIn)
|
2016-01-11 23:41:09 -05:00
|
|
|
translation_unit = translation_unit_in
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *import) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-28 03:34:40 -05:00
|
|
|
imported.copy_construct(&old->imported)
|
2015-12-06 18:44:04 -05:00
|
|
|
name.copy_construct(&old->name)
|
2016-01-11 23:41:09 -05:00
|
|
|
translation_unit = old->translation_unit
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-28 03:34:40 -05:00
|
|
|
imported.destruct()
|
2015-12-06 18:44:04 -05:00
|
|
|
name.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref import) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref import): bool {
|
2016-01-11 23:41:09 -05:00
|
|
|
return imported == other.imported && name == other.name && translation_unit == other.translation_unit
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-06 02:46:42 -05:00
|
|
|
fun ast_identifier_ptr(name: *char, type: *type): *ast_node {
|
|
|
|
|
return ast_identifier_ptr(string(name), type)
|
2015-12-28 03:34:40 -05:00
|
|
|
}
|
2016-01-06 02:46:42 -05:00
|
|
|
fun ast_identifier_ptr(name: string, type: *type): *ast_node {
|
|
|
|
|
var to_ret.construct(name, type): identifier
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::identifier(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_identifier(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::identifier(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj identifier (Object) {
|
2015-12-28 03:34:40 -05:00
|
|
|
var name: string
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2016-01-06 02:46:42 -05:00
|
|
|
var type: *type
|
|
|
|
|
fun construct(name_in: string, type_in: *type): *identifier {
|
|
|
|
|
name.copy_construct(&name_in)
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2016-01-06 02:46:42 -05:00
|
|
|
type = type_in
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *identifier) {
|
2015-12-28 03:34:40 -05:00
|
|
|
name.copy_construct(&old->name)
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2016-01-06 02:46:42 -05:00
|
|
|
type = old->type
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-28 03:34:40 -05:00
|
|
|
name.destruct()
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref identifier) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref identifier): bool {
|
2016-01-06 02:46:42 -05:00
|
|
|
return name == other.name && type == other.type
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 18:44:04 -05:00
|
|
|
fun ast_type_def_ptr(name: string): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(name): type_def
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::type_def(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_type_def(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::type_def(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj type_def (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-06 18:44:04 -05:00
|
|
|
var name: string
|
|
|
|
|
fun construct(nameIn: string): *type_def {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-06 18:44:04 -05:00
|
|
|
name.copy_construct(&nameIn)
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *type_def) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-06 18:44:04 -05:00
|
|
|
name.copy_construct(&old->name)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-06 18:44:04 -05:00
|
|
|
name.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref type_def) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref type_def): bool {
|
2015-12-06 18:44:04 -05:00
|
|
|
return name == other.name
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 18:44:04 -05:00
|
|
|
fun ast_adt_def_ptr(name: string): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(name): adt_def
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::adt_def(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_adt_def(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::adt_def(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj adt_def (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-06 18:44:04 -05:00
|
|
|
var name: string
|
|
|
|
|
fun construct(nameIn: string): *adt_def {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-06 18:44:04 -05:00
|
|
|
name.copy_construct(&nameIn)
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *adt_def) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-06 18:44:04 -05:00
|
|
|
name.copy_construct(&old->name)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-06 18:44:04 -05:00
|
|
|
name.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref adt_def) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref adt_def): bool {
|
2015-12-06 18:44:04 -05:00
|
|
|
return name == other.name
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-06 02:46:42 -05:00
|
|
|
fun ast_function_ptr(name: string, type: *type, parameters: vector<*ast_node>): *ast_node {
|
|
|
|
|
var to_ret.construct(name, type, parameters): function
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::function(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_function(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::function(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj function (Object) {
|
2016-01-06 02:46:42 -05:00
|
|
|
var name: string
|
|
|
|
|
var type: *type
|
|
|
|
|
var parameters: vector<*ast_node>
|
2016-01-07 02:52:22 -05:00
|
|
|
var body_statement: *ast_node
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2016-01-06 02:46:42 -05:00
|
|
|
fun construct(name_in: string, type_in: *type, parameters_in: vector<*ast_node>): *function {
|
|
|
|
|
name.copy_construct(&name_in)
|
|
|
|
|
parameters.copy_construct(¶meters_in)
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2016-01-06 02:46:42 -05:00
|
|
|
type = type_in
|
2016-01-07 02:52:22 -05:00
|
|
|
body_statement = null<ast_node>()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *function) {
|
2016-01-06 02:46:42 -05:00
|
|
|
name.copy_construct(&old->name)
|
|
|
|
|
type = old->type
|
2016-01-07 02:52:22 -05:00
|
|
|
body_statement = old->body_statement
|
2016-01-06 02:46:42 -05:00
|
|
|
parameters.copy_construct(&old->parameters)
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2016-01-06 02:46:42 -05:00
|
|
|
name.destruct()
|
|
|
|
|
parameters.destruct()
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref function) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref function): bool {
|
2016-01-07 02:52:22 -05:00
|
|
|
return name == name && type == other.type && parameters == other.parameters && body_statement == other.body_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_code_block_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): code_block
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::code_block(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_code_block(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::code_block(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj code_block (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-28 03:34:40 -05:00
|
|
|
var children: vector<*ast_node>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *code_block {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-28 03:34:40 -05:00
|
|
|
children.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *code_block) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-28 03:34:40 -05:00
|
|
|
children.copy_construct(&old->children)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-28 03:34:40 -05:00
|
|
|
children.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref code_block) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref code_block): bool {
|
2015-12-28 03:34:40 -05:00
|
|
|
return children == other.children && scope == other.scope
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_statement_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj statement (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2016-01-04 00:38:59 -05:00
|
|
|
var child: *ast_node
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *statement {
|
2016-01-07 02:52:22 -05:00
|
|
|
child = null<ast_node>()
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *statement) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2016-01-04 00:38:59 -05:00
|
|
|
child = old->child
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref statement): bool {
|
2016-01-04 00:38:59 -05:00
|
|
|
return child == other.child
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_if_statement_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): if_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::if_statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_if_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::if_statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj if_statement (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *if_statement {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *if_statement) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref if_statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref if_statement): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_match_statement_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): match_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::match_statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_match_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::match_statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj match_statement (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *match_statement {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *match_statement) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref match_statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref match_statement): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_case_statement_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): case_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::case_statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_case_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::case_statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj case_statement (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *case_statement {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *case_statement) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref case_statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref case_statement): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_while_loop_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): while_loop
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::while_loop(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_while_loop(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::while_loop(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj while_loop (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *while_loop {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *while_loop) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref while_loop) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref while_loop): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_for_loop_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): for_loop
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::for_loop(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_for_loop(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::for_loop(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj for_loop (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *for_loop {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *for_loop) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref for_loop) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref for_loop): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-08 00:33:05 -05:00
|
|
|
fun ast_return_statement_ptr(return_value: *ast_node): *ast_node {
|
|
|
|
|
var to_ret.construct(return_value): return_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::return_statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_return_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::return_statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj return_statement (Object) {
|
2016-01-08 00:33:05 -05:00
|
|
|
var return_value: *ast_node
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2016-01-08 00:33:05 -05:00
|
|
|
fun construct(return_value_in: *ast_node): *return_statement {
|
|
|
|
|
return_value = return_value_in
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *return_statement) {
|
2016-01-08 00:33:05 -05:00
|
|
|
return_value = old->return_value
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref return_statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref return_statement): bool {
|
2016-01-08 00:33:05 -05:00
|
|
|
return return_value == other.return_value
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_break_statement_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): break_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::break_statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_break_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::break_statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj break_statement (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *break_statement {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *break_statement) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref break_statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref break_statement): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_continue_statement_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): continue_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::continue_statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_continue_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::continue_statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj continue_statement (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *continue_statement {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *continue_statement) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref continue_statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref continue_statement): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_defer_statement_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): defer_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::defer_statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_defer_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::defer_statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj defer_statement (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *defer_statement {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *defer_statement) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref defer_statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref defer_statement): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_assignment_statement_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): assignment_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::assignment_statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_assignment_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::assignment_statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj assignment_statement (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *assignment_statement {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *assignment_statement) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref assignment_statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref assignment_statement): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_declaration_statement_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): declaration_statement
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::declaration_statement(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_declaration_statement(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::declaration_statement(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj declaration_statement (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *declaration_statement {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *declaration_statement) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref declaration_statement) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref declaration_statement): bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_if_comp_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): if_comp
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::if_comp(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_if_comp(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::if_comp(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj if_comp (Object) {
|
2016-01-02 01:43:41 -05:00
|
|
|
var wanted_generator: string
|
2016-01-04 00:38:59 -05:00
|
|
|
var statement: *ast_node
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *if_comp {
|
2016-01-02 01:43:41 -05:00
|
|
|
wanted_generator.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *if_comp) {
|
2016-01-02 01:43:41 -05:00
|
|
|
wanted_generator.copy_construct(&old->wanted_generator)
|
2016-01-04 00:38:59 -05:00
|
|
|
statement = old->statement
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2016-01-02 01:43:41 -05:00
|
|
|
wanted_generator.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
2016-01-04 00:38:59 -05:00
|
|
|
fun operator=(other: if_comp) {
|
2015-12-05 07:13:32 -05:00
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
2016-01-04 00:38:59 -05:00
|
|
|
fun operator==(other: if_comp): bool {
|
|
|
|
|
return wanted_generator == other.wanted_generator && statement == other.statement
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-06 15:15:33 -05:00
|
|
|
fun ast_simple_passthrough_ptr(): *ast_node {
|
2015-12-28 03:34:40 -05:00
|
|
|
var to_ret.construct(): simple_passthrough
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::simple_passthrough(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_simple_passthrough(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::simple_passthrough(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj simple_passthrough (Object) {
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2016-01-04 00:38:59 -05:00
|
|
|
var passthrough_str: string
|
2015-12-05 07:13:32 -05:00
|
|
|
fun construct(): *simple_passthrough {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2016-01-04 00:38:59 -05:00
|
|
|
passthrough_str.construct()
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *simple_passthrough) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2016-01-04 00:38:59 -05:00
|
|
|
passthrough_str.copy_construct(&old->passthrough_str)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2016-01-04 00:38:59 -05:00
|
|
|
passthrough_str.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref simple_passthrough) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref simple_passthrough): bool {
|
2016-01-04 00:38:59 -05:00
|
|
|
return scope == other.scope && passthrough_str == other.passthrough_str
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-11 23:41:09 -05:00
|
|
|
fun ast_function_call_ptr(func: *ast_node, parameters: vector<*ast_node>): *ast_node {
|
|
|
|
|
var to_ret.construct(func, parameters): function_call
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::function_call(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_function_call(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::function_call(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj function_call (Object) {
|
2016-01-11 23:41:09 -05:00
|
|
|
var func: *ast_node
|
|
|
|
|
var parameters: vector<*ast_node>
|
|
|
|
|
fun construct(func_in: *ast_node, parameters_in: vector<*ast_node>): *function_call {
|
|
|
|
|
func = func_in
|
|
|
|
|
parameters.copy_construct(¶meters_in)
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *function_call) {
|
2016-01-11 23:41:09 -05:00
|
|
|
func = old->func
|
|
|
|
|
parameters.copy_construct(&old->parameters)
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2016-01-11 23:41:09 -05:00
|
|
|
parameters.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref function_call) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref function_call): bool {
|
2016-01-11 23:41:09 -05:00
|
|
|
return func == func && parameters == other.parameters
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-09 22:37:43 -05:00
|
|
|
fun ast_value_ptr(string_value: string, value_type: *type): *ast_node {
|
|
|
|
|
var to_ret.construct(string_value, value_type): value
|
2015-12-05 07:13:32 -05:00
|
|
|
var ptr = new<ast_node>()
|
|
|
|
|
ptr->copy_construct(&ast_node::value(to_ret))
|
|
|
|
|
return ptr
|
|
|
|
|
}
|
2016-01-04 02:00:06 -05:00
|
|
|
fun is_value(node: *ast_node): bool {
|
|
|
|
|
match(*node) {
|
|
|
|
|
ast_node::value(backing) return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
obj value (Object) {
|
2016-01-08 00:33:05 -05:00
|
|
|
var string_value: string
|
2016-01-09 22:37:43 -05:00
|
|
|
var value_type: *type
|
2015-12-07 13:43:22 -05:00
|
|
|
var scope: map<string, vector<*ast_node>>
|
2016-01-09 22:37:43 -05:00
|
|
|
fun construct(string_value_in: string, value_type_in: *type): *value {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.construct()
|
2016-01-08 00:33:05 -05:00
|
|
|
string_value.copy_construct(&string_value_in)
|
2016-01-09 22:37:43 -05:00
|
|
|
value_type = value_type_in
|
2015-12-05 07:13:32 -05:00
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: *value) {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.copy_construct(&old->scope)
|
2016-01-08 00:33:05 -05:00
|
|
|
string_value.copy_construct(&old->string_value)
|
2016-01-09 22:37:43 -05:00
|
|
|
value_type = old->value_type
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun destruct() {
|
2015-12-07 13:43:22 -05:00
|
|
|
scope.destruct()
|
2016-01-08 00:33:05 -05:00
|
|
|
string_value.destruct()
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun operator=(other: ref value) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun operator==(other: ref value): bool {
|
2016-01-09 22:37:43 -05:00
|
|
|
return string_value == other.string_value && value_type == other.value_type
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun get_ast_children(node: *ast_node): vector<*ast_node> {
|
2015-12-06 15:15:33 -05:00
|
|
|
match (*node) {
|
|
|
|
|
ast_node::translation_unit(backing) return backing.children
|
2015-12-28 03:34:40 -05:00
|
|
|
ast_node::import(backing) return vector<*ast_node>()
|
2015-12-06 15:15:33 -05:00
|
|
|
ast_node::identifier(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::type_def(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::adt_def(backing) return vector<*ast_node>()
|
2016-01-07 02:52:22 -05:00
|
|
|
ast_node::function(backing) return backing.parameters + backing.body_statement
|
2015-12-28 03:34:40 -05:00
|
|
|
ast_node::code_block(backing) return backing.children
|
2016-01-04 00:38:59 -05:00
|
|
|
ast_node::statement(backing) return vector<*ast_node>(backing.child)
|
2015-12-06 15:15:33 -05:00
|
|
|
ast_node::if_statement(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::match_statement(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::case_statement(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::while_loop(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::for_loop(backing) return vector<*ast_node>()
|
2016-01-09 22:37:43 -05:00
|
|
|
ast_node::return_statement(backing) return vector(backing.return_value)
|
2015-12-06 15:15:33 -05:00
|
|
|
ast_node::break_statement(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::continue_statement(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::defer_statement(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::assignment_statement(backing) return vector<*ast_node>()
|
|
|
|
|
ast_node::declaration_statement(backing) return vector<*ast_node>()
|
2016-01-04 00:38:59 -05:00
|
|
|
ast_node::if_comp(backing) return vector<*ast_node>(backing.statement)
|
2015-12-06 15:15:33 -05:00
|
|
|
ast_node::simple_passthrough(backing) return vector<*ast_node>()
|
2016-01-11 23:41:09 -05:00
|
|
|
ast_node::function_call(backing) return vector(backing.func) + backing.parameters
|
2015-12-06 15:15:33 -05:00
|
|
|
ast_node::value(backing) return vector<*ast_node>()
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
|
|
|
|
fun get_ast_name(node: *ast_node): string {
|
2015-12-06 15:15:33 -05:00
|
|
|
match (*node) {
|
2015-12-06 18:44:04 -05:00
|
|
|
ast_node::translation_unit(backing) return string("translation_unit: ") + backing.name
|
2015-12-28 03:34:40 -05:00
|
|
|
ast_node::import(backing) return string("import: ") + backing.name + "; [" + backing.imported.reduce(fun(name: string, acc: string): string return acc + " " + name;, string()) + " ]"
|
2016-01-06 02:46:42 -05:00
|
|
|
ast_node::identifier(backing) return string("identifier: ") + backing.name + ": " + backing.type->to_string()
|
2015-12-06 18:44:04 -05:00
|
|
|
ast_node::type_def(backing) return string("type_def: ") + backing.name
|
|
|
|
|
ast_node::adt_def(backing) return string("adt_def: ") + backing.name
|
2016-01-06 02:46:42 -05:00
|
|
|
ast_node::function(backing) return string("function: ") + backing.name + ": " + backing.type->to_string()
|
2015-12-06 15:15:33 -05:00
|
|
|
ast_node::code_block(backing) return string("code_block")
|
|
|
|
|
ast_node::statement(backing) return string("statement")
|
|
|
|
|
ast_node::if_statement(backing) return string("if_statement")
|
|
|
|
|
ast_node::match_statement(backing) return string("match_statement")
|
|
|
|
|
ast_node::case_statement(backing) return string("case_statement")
|
|
|
|
|
ast_node::while_loop(backing) return string("while_loop")
|
|
|
|
|
ast_node::for_loop(backing) return string("for_loop")
|
|
|
|
|
ast_node::return_statement(backing) return string("return_statement")
|
|
|
|
|
ast_node::break_statement(backing) return string("break_statement")
|
|
|
|
|
ast_node::continue_statement(backing) return string("continue_statement")
|
|
|
|
|
ast_node::defer_statement(backing) return string("defer_statement")
|
|
|
|
|
ast_node::assignment_statement(backing) return string("assignment_statement")
|
|
|
|
|
ast_node::declaration_statement(backing) return string("declaration_statement")
|
2016-01-02 01:43:41 -05:00
|
|
|
ast_node::if_comp(backing) return string("if_comp: ") + backing.wanted_generator
|
2016-01-04 00:38:59 -05:00
|
|
|
ast_node::simple_passthrough(backing) return string("simple_passthrough: , string:") + backing.passthrough_str
|
2016-01-11 23:41:09 -05:00
|
|
|
ast_node::function_call(backing) return string("function_call:(") + backing.parameters.size + ")"
|
2016-01-09 22:37:43 -05:00
|
|
|
ast_node::value(backing) return string("value: ") + backing.string_value + ": " + backing.value_type->to_string()
|
2015-12-06 15:15:33 -05:00
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
}
|
2015-12-07 13:43:22 -05:00
|
|
|
fun get_ast_scope(node: *ast_node): *map<string,vector<*ast_node>> {
|
|
|
|
|
match (*node) {
|
|
|
|
|
ast_node::translation_unit() return &node->translation_unit.scope
|
|
|
|
|
ast_node::import() return &node->import.scope
|
|
|
|
|
ast_node::identifier() return &node->identifier.scope
|
|
|
|
|
ast_node::type_def() return &node->type_def.scope
|
|
|
|
|
ast_node::adt_def() return &node->adt_def.scope
|
|
|
|
|
ast_node::function() return &node->function.scope
|
|
|
|
|
ast_node::code_block() return &node->code_block.scope
|
|
|
|
|
ast_node::statement() return &node->statement.scope
|
|
|
|
|
ast_node::if_statement() return &node->if_statement.scope
|
|
|
|
|
ast_node::match_statement() return &node->match_statement.scope
|
|
|
|
|
ast_node::case_statement() return &node->case_statement.scope
|
|
|
|
|
ast_node::while_loop() return &node->while_loop.scope
|
|
|
|
|
ast_node::for_loop() return &node->for_loop.scope
|
|
|
|
|
ast_node::return_statement() return &node->return_statement.scope
|
|
|
|
|
ast_node::break_statement() return &node->break_statement.scope
|
|
|
|
|
ast_node::continue_statement() return &node->continue_statement.scope
|
|
|
|
|
ast_node::defer_statement() return &node->defer_statement.scope
|
|
|
|
|
ast_node::assignment_statement() return &node->assignment_statement.scope
|
|
|
|
|
ast_node::declaration_statement() return &node->declaration_statement.scope
|
|
|
|
|
ast_node::if_comp() return null<map<string,vector<*ast_node>>>()
|
|
|
|
|
ast_node::simple_passthrough() return &node->simple_passthrough.scope
|
2016-01-11 23:41:09 -05:00
|
|
|
ast_node::function_call() return null<map<string,vector<*ast_node>>>()
|
2015-12-07 13:43:22 -05:00
|
|
|
ast_node::value() return &node->value.scope
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-13 21:09:28 -05:00
|
|
|
fun get_ast_type(node: *ast_node): *type {
|
|
|
|
|
match (*node) {
|
|
|
|
|
ast_node::identifier() return node->identifier.type
|
|
|
|
|
ast_node::function() return node->function.type
|
|
|
|
|
ast_node::function_call() return get_ast_type(node->function_call.func)
|
|
|
|
|
ast_node::value() return node->value.value_type
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-05 07:13:32 -05:00
|
|
|
|
|
|
|
|
fun ast_to_dot(root: *ast_node): string {
|
|
|
|
|
var ret = string("digraph Kaken {\n")
|
|
|
|
|
var counter = 0
|
|
|
|
|
var node_name_map = map<*ast_node, string>()
|
|
|
|
|
var get_name = fun(node: *ast_node): string {
|
|
|
|
|
if (node_name_map.contains_key(node))
|
|
|
|
|
return node_name_map[node]
|
|
|
|
|
var escaped = string("")
|
|
|
|
|
get_ast_name(node).data.for_each(fun(c: char) {
|
|
|
|
|
if (c != '"')
|
|
|
|
|
escaped += c
|
|
|
|
|
else
|
|
|
|
|
escaped += "\\\""
|
|
|
|
|
})
|
|
|
|
|
escaped += to_string(counter++)
|
|
|
|
|
node_name_map.set(node, escaped)
|
|
|
|
|
return escaped
|
|
|
|
|
}
|
|
|
|
|
var helper: fun(*ast_node):void = fun(node: *ast_node) {
|
|
|
|
|
get_ast_children(node).for_each(fun(child: *ast_node) {
|
|
|
|
|
if (!child)
|
|
|
|
|
return; // where on earth does the null come from
|
|
|
|
|
ret += string("\"") + get_name(node) + "\" -> \"" + get_name(child) + "\"\n";
|
|
|
|
|
helper(child)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (root)
|
|
|
|
|
helper(root)
|
|
|
|
|
return ret + "}"
|
|
|
|
|
}
|
|
|
|
|
|