diff --git a/lib/typed/ast/code.rb b/lib/typed/ast/code.rb deleted file mode 100644 index 58faefc3..00000000 --- a/lib/typed/ast/code.rb +++ /dev/null @@ -1,27 +0,0 @@ - -# Base class for Expresssion and Statement -module Typed - - class Code - - end - - class Statement < Code - end - class Expression < Code - end - -end - -require_relative "while_statement" -require_relative "if_statement" -require_relative "return_statement" -require_relative "statements" -require_relative "operator_expression" -require_relative "field_access" -require_relative "call_site" -require_relative "basic_values" -require_relative "assignment" -require_relative "class_statement" -require_relative "function_statement" -require_relative "to_code" diff --git a/lib/typed/ast/while_statement.rb b/lib/typed/ast/while_statement.rb deleted file mode 100644 index 3a83247c..00000000 --- a/lib/typed/ast/while_statement.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Typed - class WhileStatement < Statement - attr_accessor :branch_type , :condition , :statements - end -end diff --git a/lib/typed/ast_helper.rb b/lib/typed/ast_helper.rb deleted file mode 100644 index a1706805..00000000 --- a/lib/typed/ast_helper.rb +++ /dev/null @@ -1,23 +0,0 @@ -AST::Node.class_eval do - - def [](name) - #puts self.inspect - children.each do |child| - if child.is_a?(AST::Node) - #puts child.type - if (child.type == name) - return child.children - end - else - #puts child.class - end - end - nil - end - - def first_from( node_name ) - from = self[node_name] - return nil unless from - from.first - end -end diff --git a/lib/typed/compiler.rb b/lib/typed/compiler.rb index c790add5..77771ef5 100644 --- a/lib/typed/compiler.rb +++ b/lib/typed/compiler.rb @@ -1,3 +1,5 @@ +require_relative "tree" + module Typed CompilerModules = [ "assignment" , "basic_values" , "call_site", "class_field" , @@ -187,8 +189,6 @@ module Typed end end -require_relative "ast_helper" -require_relative "ast/code" require_relative "compiler/collections" require_relative "compiler/field_def" require_relative "compiler/field_access" diff --git a/lib/typed/tree.rb b/lib/typed/tree.rb new file mode 100644 index 00000000..6a53830d --- /dev/null +++ b/lib/typed/tree.rb @@ -0,0 +1,38 @@ +# Base class for Expresssion and Statement +module Typed + + class Code ; end + class Statement < Code ; end + class Expression < Code ; end + +end + +["while_statement", "if_statement" , "return_statement" , "statements", + "operator_expression" , "field_access" , "call_site" , "basic_values", + "assignment" , "class_statement" , "function_statement" , "to_code"].each do |code| + require_relative "tree/" + code +end + +AST::Node.class_eval do + + def [](name) + #puts self.inspect + children.each do |child| + if child.is_a?(AST::Node) + #puts child.type + if (child.type == name) + return child.children + end + else + #puts child.class + end + end + nil + end + + def first_from( node_name ) + from = self[node_name] + return nil unless from + from.first + end +end diff --git a/lib/typed/ast/assignment.rb b/lib/typed/tree/assignment.rb similarity index 100% rename from lib/typed/ast/assignment.rb rename to lib/typed/tree/assignment.rb diff --git a/lib/typed/ast/basic_values.rb b/lib/typed/tree/basic_values.rb similarity index 100% rename from lib/typed/ast/basic_values.rb rename to lib/typed/tree/basic_values.rb diff --git a/lib/typed/ast/call_site.rb b/lib/typed/tree/call_site.rb similarity index 100% rename from lib/typed/ast/call_site.rb rename to lib/typed/tree/call_site.rb diff --git a/lib/typed/ast/class_statement.rb b/lib/typed/tree/class_statement.rb similarity index 100% rename from lib/typed/ast/class_statement.rb rename to lib/typed/tree/class_statement.rb diff --git a/lib/typed/ast/field_access.rb b/lib/typed/tree/field_access.rb similarity index 100% rename from lib/typed/ast/field_access.rb rename to lib/typed/tree/field_access.rb diff --git a/lib/typed/ast/function_statement.rb b/lib/typed/tree/function_statement.rb similarity index 100% rename from lib/typed/ast/function_statement.rb rename to lib/typed/tree/function_statement.rb diff --git a/lib/typed/ast/if_statement.rb b/lib/typed/tree/if_statement.rb similarity index 100% rename from lib/typed/ast/if_statement.rb rename to lib/typed/tree/if_statement.rb diff --git a/lib/typed/ast/operator_expression.rb b/lib/typed/tree/operator_expression.rb similarity index 100% rename from lib/typed/ast/operator_expression.rb rename to lib/typed/tree/operator_expression.rb diff --git a/lib/typed/ast/return_statement.rb b/lib/typed/tree/return_statement.rb similarity index 100% rename from lib/typed/ast/return_statement.rb rename to lib/typed/tree/return_statement.rb diff --git a/lib/typed/ast/statements.rb b/lib/typed/tree/statements.rb similarity index 100% rename from lib/typed/ast/statements.rb rename to lib/typed/tree/statements.rb diff --git a/lib/typed/ast/to_code.rb b/lib/typed/tree/to_code.rb similarity index 100% rename from lib/typed/ast/to_code.rb rename to lib/typed/tree/to_code.rb diff --git a/lib/typed/tree/while_statement.rb b/lib/typed/tree/while_statement.rb new file mode 100644 index 00000000..8a2a447c --- /dev/null +++ b/lib/typed/tree/while_statement.rb @@ -0,0 +1,7 @@ +module Typed + module Tree + class WhileStatement < Statement + attr_accessor :branch_type , :condition , :statements + end + end +end