processing functions
git-svn-id: svn://anubis/jtlc/trunk@23 f5bc74b8-7b62-4e90-9214-7121d538519f
This commit is contained in:
parent
7b8436acb4
commit
31ec778b3a
@ -7,6 +7,26 @@ using namespace std;
|
|||||||
|
|
||||||
void FunctionNode::process(refptr<Compiler> compiler)
|
void FunctionNode::process(refptr<Compiler> compiler)
|
||||||
{
|
{
|
||||||
refptr<Node> params = m_children[2];
|
refptr<Node> name = m_children[0];
|
||||||
refptr<Node> type = m_children[1];
|
refptr<Node> params = m_children[1];
|
||||||
|
refptr<Node> 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");
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,9 @@ class StructTypeNode : public Node
|
|||||||
|
|
||||||
class VariableSpecNode : public Node
|
class VariableSpecNode : public Node
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
void process(refptr<Compiler> compiler);
|
||||||
|
std::string getString();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
15
nodes/VariableSpecNode.cc
Normal file
15
nodes/VariableSpecNode.cc
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "Node.h"
|
||||||
|
#include "parser/parser.h"
|
||||||
|
#include "main/Compiler.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void VariableSpecNode::process(refptr<Compiler> compiler)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
string VariableSpecNode::getString()
|
||||||
|
{
|
||||||
|
return m_children[1]->getString() + " " + m_children[0]->getString();
|
||||||
|
}
|
@ -131,6 +131,7 @@ import_name_more_more: IDENTIFIER import_name_more
|
|||||||
|
|
||||||
function: IDENTIFIER LPAREN parameter_list RPAREN COLON type LCURLY function_items RCURLY {
|
function: IDENTIFIER LPAREN parameter_list RPAREN COLON type LCURLY function_items RCURLY {
|
||||||
$$ = new FunctionNode();
|
$$ = new FunctionNode();
|
||||||
|
$$->addChild($1);
|
||||||
$$->addChild($3);
|
$$->addChild($3);
|
||||||
$$->addChild($6);
|
$$->addChild($6);
|
||||||
$$->addChildren($8);
|
$$->addChildren($8);
|
||||||
|
@ -1,2 +1,5 @@
|
|||||||
|
|
||||||
c("int main() { return 42; }");
|
main() : int
|
||||||
|
{
|
||||||
|
c("return 42;");
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user