for(NodeArray<VariableDeclaration>::const_iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
(*i)->visit(*this);
last_branch();
- if(func.definition!=&func)
- append(format("Definition: %%%d", get_label(*func.definition)));
- else
+ if(func.definition==&func)
func.body.visit(*this);
+ else if(func.definition)
+ append(format("Definition: %%%d", get_label(*func.definition)));
end_sub();
}
stage(0),
r_members(0),
record_target(false),
- r_assignment_target(0),
- r_self_referencing(false)
+ r_self_referencing(false),
+ r_assignment_target(0)
{ }
void VariableResolver::apply(Stage &s)
if(binary.oper->token[0]=='[')
{
{
- SetForScope<bool> set(record_target, false);
+ SetFlag set(record_target, false);
binary.right->visit(*this);
}
r_members = 0;
SetFlag set(record_target);
r_assignment_target = 0;
assign.left->visit(*this);
+ assign.target_declaration = r_assignment_target;
}
r_self_referencing = false;
assign.right->visit(*this);
-
assign.self_referencing = (r_self_referencing || assign.oper->token[0]!='=');
- assign.target_declaration = r_assignment_target;
+
r_members = 0;
r_iface_ref = 0;
}
RefPtr<InterfaceBlockReference> r_iface_ref;
std::string block_interface;
bool record_target;
- VariableDeclaration *r_assignment_target;
bool r_self_referencing;
+ VariableDeclaration *r_assignment_target;
public:
VariableResolver();
deps_only(false)
{ }
-const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_func, Block &tgtb, const NodeList<Statement>::iterator &ins_pt, FunctionDeclaration &src)
+const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_func, Block &tgt_blk, const NodeList<Statement>::iterator &ins_pt, FunctionDeclaration &src)
{
- target_block = &tgtb;
+ target_block = &tgt_blk;
source_func = &src;
for(NodeList<Statement>::iterator i=src.body.body.begin(); i!=src.body.body.end(); ++i)
{
SetFlag set_remap(remap_names);
r_inlined_statement->visit(*this);
- tgtb.body.insert(ins_pt, r_inlined_statement);
+ tgt_blk.body.insert(ins_pt, r_inlined_statement);
}
NodeReorderer().apply(stage, target_func, dependencies);
if(assignment_target)
r_assign_to_subfield = true;
binary.left->visit(*this);
- SetForScope<bool> set(assignment_target, false);
+ SetFlag set(assignment_target, false);
binary.right->visit(*this);
}
else
void UnusedVariableRemover::visit(Assignment &assign)
{
{
- SetForScope<bool> set(assignment_target, !assign.self_referencing);
+ SetFlag set(assignment_target, !assign.self_referencing);
assign.left->visit(*this);
}
assign.right->visit(*this);
BlockVariableMap &block_variables = variables.back();
for(BlockVariableMap::iterator i=block_variables.begin(); i!=block_variables.end(); ++i)
- i->second.conditionally_assigned = true;
+ if(!i->second.local)
+ i->second.conditionally_assigned = true;
for(NodeArray<VariableDeclaration>::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i)
block_variables[i->get()].referenced = true;
merge_down_variables();
source_line = line;
}
+void Formatter::visit(Block &block)
+{
+ unsigned brace_indent = indent;
+ bool use_braces = (block.use_braces || (indent && block.body.size()!=1));
+ if(use_braces)
+ append(format("%s{\n", string(brace_indent*2, ' ')));
+
+ SetForScope<unsigned> set(indent, indent+(indent>0 || use_braces));
+ string spaces(indent*2, ' ');
+ bool first = true;
+ for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
+ {
+ if((*i)->source==BUILTIN_SOURCE)
+ continue;
+ if(!first)
+ append('\n');
+ first = false;
+ set_source((*i)->source, (*i)->line);
+ append(spaces);
+ (*i)->visit(*this);
+ }
+
+ if(use_braces)
+ append(format("\n%s}", string(brace_indent*2, ' ')));
+}
+
void Formatter::visit(Literal &literal)
{
append(literal.token);
append(';');
}
-void Formatter::visit(Block &block)
-{
- unsigned brace_indent = indent;
- bool use_braces = (block.use_braces || (indent && block.body.size()!=1));
- if(use_braces)
- append(format("%s{\n", string(brace_indent*2, ' ')));
-
- SetForScope<unsigned> set(indent, indent+(indent>0 || use_braces));
- string spaces(indent*2, ' ');
- bool first = true;
- for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
- {
- if((*i)->source==BUILTIN_SOURCE)
- continue;
- if(!first)
- append('\n');
- first = false;
- set_source((*i)->source, (*i)->line);
- append(spaces);
- (*i)->visit(*this);
- }
-
- if(use_braces)
- append(format("\n%s}", string(brace_indent*2, ' ')));
-}
-
void Formatter::visit(Import &import)
{
append(format("import %s;", import.module));
namespace GL {
namespace SL {
-void NodeVisitor::visit(Assignment &assign)
-{
- visit(static_cast<BinaryExpression &>(assign));
-}
-
-
void TraversingVisitor::visit(Block &block)
{
if(&block!=current_block)
binary.right->visit(*this);
}
+void TraversingVisitor::visit(Assignment &assign)
+{
+ visit(static_cast<BinaryExpression &>(assign));
+}
+
void TraversingVisitor::visit(FunctionCall &call)
{
for(NodeArray<Expression>::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i)
virtual void visit(MemberAccess &) { }
virtual void visit(UnaryExpression &) { }
virtual void visit(BinaryExpression &) { }
- virtual void visit(Assignment &);
+ virtual void visit(Assignment &) { }
virtual void visit(FunctionCall &) { }
virtual void visit(ExpressionStatement &) { }
virtual void visit(Import &) { }
virtual void visit(MemberAccess &);
virtual void visit(UnaryExpression &);
virtual void visit(BinaryExpression &);
+ virtual void visit(Assignment &);
virtual void visit(FunctionCall &);
virtual void visit(ExpressionStatement &);
virtual void visit(InterfaceLayout &);