Commit a86469cc authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Remove unnecessary accept calls in semantic analyzer

2008-11-10  Jürg Billeter  <j@bitron.ch>

	* vala/valaaddressofexpression.vala:
	* vala/valaarraycreationexpression.vala:
	* vala/valaassignment.vala:
	* vala/valabinaryexpression.vala:
	* vala/valablock.vala:
	* vala/valacastexpression.vala:
	* vala/valacatchclause.vala:
	* vala/valaclass.vala:
	* vala/valaconditionalexpression.vala:
	* vala/valaconstant.vala:
	* vala/valaconstructor.vala:
	* vala/valacreationmethod.vala:
	* vala/valadeclarationstatement.vala:
	* vala/valadelegate.vala:
	* vala/valadeletestatement.vala:
	* vala/valadestructor.vala:
	* vala/valadostatement.vala:
	* vala/valaelementaccess.vala:
	* vala/valaenum.vala:
	* vala/valaenumvalue.vala:
	* vala/valaerrorcode.vala:
	* vala/valaerrordomain.vala:
	* vala/valaexpressionstatement.vala:
	* vala/valafield.vala:
	* vala/valaforeachstatement.vala:
	* vala/valaformalparameter.vala:
	* vala/valaforstatement.vala:
	* vala/valaifstatement.vala:
	* vala/valainitializerlist.vala:
	* vala/valainterface.vala:
	* vala/valainvocationexpression.vala:
	* vala/valalambdaexpression.vala:
	* vala/valalocalvariable.vala:
	* vala/valalockstatement.vala:
	* vala/valamemberaccess.vala:
	* vala/valamemberinitializer.vala:
	* vala/valamethod.vala:
	* vala/valanamespace.vala:
	* vala/valaobjectcreationexpression.vala:
	* vala/valaparenthesizedexpression.vala:
	* vala/valapointerindirection.vala:
	* vala/valapostfixexpression.vala:
	* vala/valaproperty.vala:
	* vala/valapropertyaccessor.vala:
	* vala/valareferencetransferexpression.vala:
	* vala/valareturnstatement.vala:
	* vala/valasemanticanalyzer.vala:
	* vala/valasignal.vala:
	* vala/valasizeofexpression.vala:
	* vala/valasourcefile.vala:
	* vala/valastruct.vala:
	* vala/valaswitchlabel.vala:
	* vala/valaswitchsection.vala:
	* vala/valaswitchstatement.vala:
	* vala/valathrowstatement.vala:
	* vala/valatrystatement.vala:
	* vala/valatypecheck.vala:
	* vala/valatypeofexpression.vala:
	* vala/valaunaryexpression.vala:
	* vala/valawhilestatement.vala:
	* vala/valayieldstatement.vala:

	Remove unnecessary accept calls in semantic analyzer

svn path=/trunk/; revision=2010
parent 67649405
2008-11-10 Jürg Billeter <j@bitron.ch>
* vala/valaaddressofexpression.vala:
* vala/valaarraycreationexpression.vala:
* vala/valaassignment.vala:
* vala/valabinaryexpression.vala:
* vala/valablock.vala:
* vala/valacastexpression.vala:
* vala/valacatchclause.vala:
* vala/valaclass.vala:
* vala/valaconditionalexpression.vala:
* vala/valaconstant.vala:
* vala/valaconstructor.vala:
* vala/valacreationmethod.vala:
* vala/valadeclarationstatement.vala:
* vala/valadelegate.vala:
* vala/valadeletestatement.vala:
* vala/valadestructor.vala:
* vala/valadostatement.vala:
* vala/valaelementaccess.vala:
* vala/valaenum.vala:
* vala/valaenumvalue.vala:
* vala/valaerrorcode.vala:
* vala/valaerrordomain.vala:
* vala/valaexpressionstatement.vala:
* vala/valafield.vala:
* vala/valaforeachstatement.vala:
* vala/valaformalparameter.vala:
* vala/valaforstatement.vala:
* vala/valaifstatement.vala:
* vala/valainitializerlist.vala:
* vala/valainterface.vala:
* vala/valainvocationexpression.vala:
* vala/valalambdaexpression.vala:
* vala/valalocalvariable.vala:
* vala/valalockstatement.vala:
* vala/valamemberaccess.vala:
* vala/valamemberinitializer.vala:
* vala/valamethod.vala:
* vala/valanamespace.vala:
* vala/valaobjectcreationexpression.vala:
* vala/valaparenthesizedexpression.vala:
* vala/valapointerindirection.vala:
* vala/valapostfixexpression.vala:
* vala/valaproperty.vala:
* vala/valapropertyaccessor.vala:
* vala/valareferencetransferexpression.vala:
* vala/valareturnstatement.vala:
* vala/valasemanticanalyzer.vala:
* vala/valasignal.vala:
* vala/valasizeofexpression.vala:
* vala/valasourcefile.vala:
* vala/valastruct.vala:
* vala/valaswitchlabel.vala:
* vala/valaswitchsection.vala:
* vala/valaswitchstatement.vala:
* vala/valathrowstatement.vala:
* vala/valatrystatement.vala:
* vala/valatypecheck.vala:
* vala/valatypeofexpression.vala:
* vala/valaunaryexpression.vala:
* vala/valawhilestatement.vala:
* vala/valayieldstatement.vala:
Remove unnecessary accept calls in semantic analyzer
2008-11-10 Jürg Billeter <j@bitron.ch>
* vala/valaaddressofexpression.vala:
......
......@@ -77,7 +77,8 @@ public class Vala.AddressofExpression : Expression {
checked = true;
if (inner.error) {
if (!inner.check (analyzer)) {
error = true;
return false;
}
if (!(inner.value_type is ValueType
......
......@@ -109,7 +109,7 @@ public class Vala.ArrayCreationExpression : Expression {
private int create_sizes_from_initializer_list (SemanticAnalyzer analyzer, InitializerList il, int rank, Gee.List<Literal> sl) {
var init = new IntegerLiteral (il.size.to_string (), il.source_reference);
init.accept (analyzer);
init.check (analyzer);
sl.add (init);
int subsize = -1;
......@@ -155,18 +155,18 @@ public class Vala.ArrayCreationExpression : Expression {
var initlist = initializer_list;
if (element_type != null) {
element_type.accept (analyzer);
element_type.check (analyzer);
}
foreach (Expression e in size) {
e.accept (analyzer);
e.check (analyzer);
}
var calc_sizes = new ArrayList<Literal> ();
if (initlist != null) {
initlist.target_type = new ArrayType (element_type, rank, source_reference);
initlist.accept (analyzer);
initlist.check (analyzer);
var ret = create_sizes_from_initializer_list (analyzer, initlist, rank, calc_sizes);
if (ret == -1) {
......
......@@ -107,9 +107,7 @@ public class Vala.Assignment : Expression {
left.lvalue = true;
left.accept (analyzer);
if (left.error) {
if (!left.check (analyzer)) {
// skip on error in inner expression
error = true;
return false;
......@@ -161,9 +159,7 @@ public class Vala.Assignment : Expression {
return false;
}
right.accept (analyzer);
if (right.error) {
if (!right.check (analyzer)) {
// skip on error in inner expression
error = true;
return false;
......@@ -207,7 +203,7 @@ public class Vala.Assignment : Expression {
}
right = bin;
right.accept (analyzer);
right.check (analyzer);
operator = AssignmentOperator.SIMPLE;
}
......@@ -365,7 +361,7 @@ public class Vala.Assignment : Expression {
* increment calls */
}
} else {
return false;
return true;
}
if (left.value_type != null) {
......
......@@ -145,7 +145,7 @@ public class Vala.BinaryExpression : Expression {
checked = true;
if (left.error || right.error) {
if (!left.check (analyzer) || !right.check (analyzer)) {
/* if there were any errors in inner expressions, skip type check */
error = true;
return false;
......
......@@ -101,13 +101,15 @@ public class Vala.Block : Symbol, Statement {
owner = analyzer.current_symbol.scope;
analyzer.current_symbol = this;
accept_children (analyzer);
foreach (Statement stmt in statement_list) {
stmt.check (analyzer);
}
foreach (LocalVariable local in get_local_variables ()) {
local.active = false;
}
foreach (Statement stmt in get_statements()) {
foreach (Statement stmt in get_statements ()) {
add_error_types (stmt.get_error_types ());
}
......
......@@ -105,11 +105,13 @@ public class Vala.CastExpression : Expression {
checked = true;
if (inner.error) {
if (!inner.check (analyzer)) {
error = true;
return false;
}
type_reference.check (analyzer);
// FIXME: check whether cast is allowed
analyzer.current_source_file.add_type_dependency (type_reference, SourceFileDependencyType.SOURCE);
......
......@@ -113,7 +113,9 @@ public class Vala.CatchClause : CodeNode {
error_type = new ErrorType (null, null, source_reference);
}
accept_children (analyzer);
error_type.check (analyzer);
body.check (analyzer);
return !error;
}
......
......@@ -884,7 +884,66 @@ public class Vala.Class : ObjectTypeSymbol {
analyzer.current_source_file.add_type_dependency (base_type_reference, SourceFileDependencyType.HEADER_FULL);
}
accept_children (analyzer);
foreach (DataType type in base_types) {
type.check (analyzer);
}
foreach (TypeParameter p in type_parameters) {
p.check (analyzer);
}
/* process enums first to avoid order problems in C code */
foreach (Enum en in enums) {
en.check (analyzer);
}
foreach (Field f in fields) {
f.check (analyzer);
}
foreach (Constant c in constants) {
c.check (analyzer);
}
foreach (Method m in methods) {
m.check (analyzer);
}
foreach (Property prop in properties) {
prop.check (analyzer);
}
foreach (Signal sig in signals) {
sig.check (analyzer);
}
if (constructor != null) {
constructor.check (analyzer);
}
if (class_constructor != null) {
class_constructor.check (analyzer);
}
if (static_constructor != null) {
static_constructor.check (analyzer);
}
if (destructor != null) {
destructor.check (analyzer);
}
foreach (Class cl in classes) {
cl.check (analyzer);
}
foreach (Struct st in structs) {
st.check (analyzer);
}
foreach (Delegate d in delegates) {
d.check (analyzer);
}
/* compact classes cannot implement interfaces */
if (is_compact) {
......
......@@ -77,7 +77,7 @@ public class Vala.ConditionalExpression : Expression {
checked = true;
if (condition.error || false_expression.error || true_expression.error) {
if (!condition.check (analyzer) || !false_expression.check (analyzer) || !true_expression.check (analyzer)) {
return false;
}
......
......@@ -160,7 +160,7 @@ public class Vala.Constant : Member, Lockable {
process_attributes ();
type_reference.accept (analyzer);
type_reference.check (analyzer);
if (!external_package) {
if (initializer == null) {
......@@ -169,7 +169,7 @@ public class Vala.Constant : Member, Lockable {
} else {
initializer.target_type = type_reference;
initializer.accept (analyzer);
initializer.check (analyzer);
}
}
......
......@@ -74,7 +74,9 @@ public class Vala.Constructor : Symbol {
owner = analyzer.current_symbol.scope;
analyzer.current_symbol = this;
accept_children (analyzer);
if (body != null) {
body.check (analyzer);
}
foreach (DataType body_error_type in body.get_error_types ()) {
Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string()));
......
......@@ -137,7 +137,17 @@ public class Vala.CreationMethod : Method {
analyzer.current_symbol = this;
analyzer.current_return_type = return_type;
accept_children (analyzer);
foreach (FormalParameter param in get_parameters()) {
param.check (analyzer);
}
foreach (DataType error_type in get_error_types ()) {
error_type.check (analyzer);
}
if (body != null) {
body.check (analyzer);
}
analyzer.current_symbol = old_symbol;
analyzer.current_return_type = old_return_type;
......
......@@ -56,6 +56,8 @@ public class Vala.DeclarationStatement : CodeNode, Statement {
checked = true;
declaration.check (analyzer);
var local = declaration as LocalVariable;
if (local != null && local.initializer != null) {
foreach (DataType error_type in local.initializer.get_error_types ()) {
......
......@@ -343,7 +343,15 @@ public class Vala.Delegate : TypeSymbol {
analyzer.current_source_file = source_reference.file;
}
accept_children (analyzer);
foreach (TypeParameter p in type_parameters) {
p.check (analyzer);
}
return_type.check (analyzer);
foreach (FormalParameter param in parameters) {
param.check (analyzer);
}
analyzer.current_source_file = old_source_file;
......
......@@ -51,9 +51,7 @@ public class Vala.DeleteStatement : CodeNode, Statement {
checked = true;
accept_children (analyzer);
if (expression.error) {
if (!expression.check (analyzer)) {
// if there was an error in the inner expression, skip this check
return false;
}
......
......@@ -71,7 +71,9 @@ public class Vala.Destructor : Symbol {
owner = analyzer.current_symbol.scope;
analyzer.current_symbol = this;
accept_children (analyzer);
if (body != null) {
body.check (analyzer);
}
analyzer.current_symbol = analyzer.current_symbol.parent_symbol;
......
......@@ -94,9 +94,9 @@ public class Vala.DoStatement : CodeNode, Statement {
checked = true;
accept_children (analyzer);
body.check (analyzer);
if (condition.error) {
if (!condition.check (analyzer)) {
/* if there was an error in the condition, skip this check */
error = true;
return false;
......
......@@ -93,7 +93,7 @@ public class Vala.ElementAccess : Expression {
checked = true;
container.accept (analyzer);
container.check (analyzer);
if (container.value_type == null) {
/* don't proceed if a child expression failed */
......@@ -114,7 +114,7 @@ public class Vala.ElementAccess : Expression {
}
foreach (Expression index in get_indices ()) {
index.accept (analyzer);
index.check (analyzer);
}
bool index_int_type_check = true;
......
......@@ -313,7 +313,13 @@ public class Vala.Enum : TypeSymbol {
analyzer.current_source_file = source_reference.file;
}
accept_children (analyzer);
foreach (EnumValue value in values) {
value.check (analyzer);
}
foreach (Method m in methods) {
m.check (analyzer);
}
analyzer.current_source_file = old_source_file;
......
......@@ -138,7 +138,9 @@ public class Vala.EnumValue : Symbol {
process_attributes ();
accept_children (analyzer);
if (value != null) {
value.check (analyzer);
}
return !error;
}
......
......@@ -80,7 +80,9 @@ public class Vala.ErrorCode : TypeSymbol {
checked = true;
accept_children (analyzer);
if (value != null) {
value.check (analyzer);
}
return !error;
}
......
......@@ -225,7 +225,13 @@ public class Vala.ErrorDomain : TypeSymbol {
process_attributes ();
accept_children (analyzer);
foreach (ErrorCode ecode in codes) {
ecode.check (analyzer);
}
foreach (Method m in methods) {
m.check (analyzer);
}
return !error;
}
......
......@@ -93,7 +93,7 @@ public class Vala.ExpressionStatement : CodeNode, Statement {
checked = true;
if (expression.error) {
if (!expression.check (analyzer)) {
// ignore inner error
error = true;
return false;
......
......@@ -211,7 +211,11 @@ public class Vala.Field : Member, Lockable {
initializer.target_type = field_type;
}
accept_children (analyzer);
field_type.check (analyzer);
if (initializer != null) {
initializer.check (analyzer);
}
if (binding == MemberBinding.INSTANCE && parent_symbol is Interface) {
error = true;
......
......@@ -143,9 +143,7 @@ public class Vala.ForeachStatement : Block {
checked = true;
// analyze collection expression first, used for type inference
collection.accept (analyzer);
if (collection.error) {
if (!collection.check (analyzer)) {
// ignore inner error
error = true;
return false;
......@@ -230,7 +228,7 @@ public class Vala.ForeachStatement : Block {
owner = analyzer.current_symbol.scope;
analyzer.current_symbol = this;
body.accept (analyzer);
body.check (analyzer);
foreach (LocalVariable local in get_local_variables ()) {
local.active = false;
......
......@@ -188,7 +188,13 @@ public class Vala.FormalParameter : Symbol {
parameter_type.check (analyzer);
}
accept_children (analyzer);
if (!ellipsis) {
parameter_type.check (analyzer);
if (default_expression != null) {
default_expression.check (analyzer);
}
}
if (analyzer.context.non_null && default_expression != null) {
if (default_expression is NullLiteral
......
......@@ -164,7 +164,19 @@ public class Vala.ForStatement : CodeNode, Statement {
checked = true;
accept_children (analyzer);
foreach (Expression init_expr in initializer) {
init_expr.check (analyzer);
}
if (condition != null) {
condition.check (analyzer);
}
foreach (Expression it_expr in iterator) {
it_expr.check (analyzer);
}
body.check (analyzer);
if (condition != null && condition.error) {
/* if there was an error in the condition, skip this check */
......
......@@ -94,7 +94,12 @@ public class Vala.IfStatement : CodeNode, Statement {
checked = true;
accept_children (analyzer);
condition.check (analyzer);
true_statement.check (analyzer);
if (false_statement != null) {
false_statement.check (analyzer);
}
if (condition.error) {
/* if there was an error in the condition, skip this check */
......
......@@ -142,7 +142,9 @@ public class Vala.InitializerList : Expression {
return false;
}
accept_children (analyzer);
foreach (Expression expr in initializers) {
expr.check (analyzer);
}
bool error = false;
foreach (Expression e in get_initializers ()) {
......
......@@ -590,7 +590,45 @@ public class Vala.Interface : ObjectTypeSymbol {
}
}
accept_children (analyzer);
foreach (DataType type in prerequisites) {
type.check (analyzer);
}
foreach (TypeParameter p in type_parameters) {
p.check (analyzer);
}
foreach (Enum en in enums) {
en.check (analyzer);
}
foreach (Method m in methods) {
m.check (analyzer);
}
foreach (Field f in fields) {
f.check (analyzer);
}
foreach (Property prop in properties) {
prop.check (analyzer);
}
foreach (Signal sig in signals) {
sig.check (analyzer);
}
foreach (Class cl in classes) {
cl.check (analyzer);
}
foreach (Struct st in structs) {
st.check (analyzer);
}
foreach (Delegate d in delegates) {
d.check (analyzer);
}
analyzer.current_source_file = old_source_file;
analyzer.current_symbol = old_symbol;
......
......@@ -128,9 +128,7 @@ public class Vala.InvocationExpression : Expression {
checked = true;
call.accept (analyzer);
if (call.error) {
if (!call.check (analyzer)) {
/* if method resolving didn't succeed, skip this check */
error = true;
return false;
......@@ -172,7 +170,7 @@ public class Vala.InvocationExpression : Expression {
struct_creation_expression.target_type = target_type;
analyzer.replaced_nodes.add (this);
parent_node.replace_expression (this, struct_creation_expression);
struct_creation_expression.accept (analyzer);
struct_creation_expression.check (analyzer);
return false;
} else if (call is MemberAccess
&& call.symbol_reference is CreationMethod) {
......@@ -360,7 +358,7 @@ public class Vala.InvocationExpression : Expression {
}
foreach (Expression arg in get_argument_list ()) {
arg.accept (analyzer);
arg.check (analyzer);
}
DataType ret_type;
......
......@@ -189,7 +189,15 @@ public class Vala.LambdaExpression : Expression {
/* lambda expressions should be usable like MemberAccess of a method */
symbol_reference = method;
accept_children (analyzer);
if (method == null) {
if (expression_body != null) {
expression_body.check (analyzer);
} else if (statement_body != null) {
statement_body.check (analyzer);
}
} else {
method.check (analyzer);
}
value_type = new MethodType (method);
......
......@@ -110,7 +110,13 @@ public class Vala.LocalVariable : Symbol {
initializer.target_type = variable_type;
}
accept_children (analyzer);
if (initializer != null) {
initializer.check (analyzer);
}
if (variable_type != null) {
variable_type.check (analyzer);
}
if (variable_type == null) {
/* var type */
......
......@@ -55,6 +55,9 @@ public class Vala.LockStatement : CodeNode, Statement {
checked = true;
resource.check (analyzer);
body.check (analyzer);
/* resource must be a member access and denote a Lockable */
if (!(resource is MemberAccess && resource.symbol_reference is Lockable)) {
error = true;
......
......@@ -182,6 +182,14 @@ public class Vala.MemberAccess : Expression {
checked = true;
if (inner != null) {
inner.check (analyzer);
}
foreach (DataType type_arg in type_argument_list) {
type_arg.check (analyzer);
}
Symbol base_symbol = null;
FormalParameter this_parameter = null;
bool may_access_instance_members = false;
......@@ -257,7 +265,7 @@ public class Vala.MemberAccess : Expression {
if (pointer_type != null && pointer_type.base_type is ValueType) {
// transform foo->bar to (*foo).bar
inner = new PointerIndirection (inner, source_reference);
inner.accept (analyzer);
<