From 31ec778b3a61a1993dcceb5cf7760c69fb4c1e7f Mon Sep 17 00:00:00 2001 From: josh Date: Fri, 15 Jan 2010 03:29:30 +0000 Subject: [PATCH] processing functions git-svn-id: svn://anubis/jtlc/trunk@23 f5bc74b8-7b62-4e90-9214-7121d538519f --- nodes/FunctionNode.cc | 24 ++++++++++++++++++++++-- nodes/Node.h | 3 +++ nodes/VariableSpecNode.cc | 15 +++++++++++++++ parser/parser.yy | 1 + tests/Initial.jtl | 5 ++++- 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 nodes/VariableSpecNode.cc diff --git a/nodes/FunctionNode.cc b/nodes/FunctionNode.cc index 4043744..5a222f6 100644 --- a/nodes/FunctionNode.cc +++ b/nodes/FunctionNode.cc @@ -7,6 +7,26 @@ using namespace std; void FunctionNode::process(refptr compiler) { - refptr params = m_children[2]; - refptr type = m_children[1]; + refptr name = m_children[0]; + refptr params = m_children[1]; + refptr type = m_children[2]; + compiler->write(type->getString()); + compiler->write(" "); + compiler->write(name->getString()); + compiler->write("("); + for (int i = 0, sz = params->getChildren().size(); i < sz; i++) + { + if (i > 0) + { + compiler->write(", "); + } + compiler->write(params->getChildren()[i]->getString()); + } + compiler->write(")\n"); + compiler->write("{\n"); + for (int i = 3, sz = m_children.size(); i < sz; i++) + { + m_children[i]->process(compiler); + } + compiler->write("}\n\n"); } diff --git a/nodes/Node.h b/nodes/Node.h index b567e13..e7c2145 100644 --- a/nodes/Node.h +++ b/nodes/Node.h @@ -104,6 +104,9 @@ class StructTypeNode : public Node class VariableSpecNode : public Node { + public: + void process(refptr compiler); + std::string getString(); }; #endif diff --git a/nodes/VariableSpecNode.cc b/nodes/VariableSpecNode.cc new file mode 100644 index 0000000..15155b4 --- /dev/null +++ b/nodes/VariableSpecNode.cc @@ -0,0 +1,15 @@ + +#include +#include "Node.h" +#include "parser/parser.h" +#include "main/Compiler.h" +using namespace std; + +void VariableSpecNode::process(refptr compiler) +{ +} + +string VariableSpecNode::getString() +{ + return m_children[1]->getString() + " " + m_children[0]->getString(); +} diff --git a/parser/parser.yy b/parser/parser.yy index b9ce280..5973127 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -131,6 +131,7 @@ import_name_more_more: IDENTIFIER import_name_more function: IDENTIFIER LPAREN parameter_list RPAREN COLON type LCURLY function_items RCURLY { $$ = new FunctionNode(); + $$->addChild($1); $$->addChild($3); $$->addChild($6); $$->addChildren($8); diff --git a/tests/Initial.jtl b/tests/Initial.jtl index 213494a..d5676b7 100644 --- a/tests/Initial.jtl +++ b/tests/Initial.jtl @@ -1,2 +1,5 @@ -c("int main() { return 42; }"); +main() : int +{ + c("return 42;"); +}