return inner.is_pure ();
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!inner.check (analyzer)) {
+ if (!inner.check (context)) {
error = true;
return false;
}
}
}
- private int create_sizes_from_initializer_list (SemanticAnalyzer analyzer, InitializerList il, int rank, List<Literal> sl) {
+ private int create_sizes_from_initializer_list (CodeContext context, InitializerList il, int rank, List<Literal> sl) {
if (sl.size == (this.rank - rank)) {
// only add size if this is the first initializer list of the current dimension
var init = new IntegerLiteral (il.size.to_string (), il.source_reference);
- init.check (analyzer);
+ init.check (context);
sl.add (init);
}
Report.error (e.source_reference, "Expected array element, got array initializer list");
return -1;
}
- int size = create_sizes_from_initializer_list (analyzer, (InitializerList) e, rank - 1, sl);
+ int size = create_sizes_from_initializer_list (context, (InitializerList) e, rank - 1, sl);
if (size == -1) {
return -1;
}
return il.size;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
var initlist = initializer_list;
if (element_type != null) {
- element_type.check (analyzer);
+ element_type.check (context);
}
foreach (Expression e in sizes) {
- e.check (analyzer);
+ e.check (context);
}
var calc_sizes = new ArrayList<Literal> ();
if (initlist != null) {
initlist.target_type = new ArrayType (element_type, rank, source_reference);
- initlist.check (analyzer);
+ initlist.check (context);
- var ret = create_sizes_from_initializer_list (analyzer, initlist, rank, calc_sizes);
+ var ret = create_sizes_from_initializer_list (context, initlist, rank, calc_sizes);
if (ret == -1) {
error = true;
}
return element_type.is_accessible (sym);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (invalid_syntax) {
Report.error (source_reference, "syntax error, no expression allowed between array brackets");
error = true;
return false;
}
- return element_type.check (analyzer);
+ return element_type.check (context);
}
public override string? get_type_id () {
return false;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
var local = new LocalVariable (null, get_temp_name (), right, right.source_reference);
var decl = new DeclarationStatement (local, source_reference);
- decl.check (analyzer);
- insert_statement (analyzer.insert_block, decl);
+ decl.check (context);
+ insert_statement (context.analyzer.insert_block, decl);
int i = 0;
ExpressionStatement stmt = null;
foreach (var expr in tuple.get_expressions ()) {
if (stmt != null) {
- stmt.check (analyzer);
- insert_statement (analyzer.insert_block, stmt);
+ stmt.check (context);
+ insert_statement (context.analyzer.insert_block, stmt);
}
var temp_access = new MemberAccess.simple (local.name, right.source_reference);
i++;
}
- analyzer.replaced_nodes.add (this);
+ context.analyzer.replaced_nodes.add (this);
parent_node.replace_expression (this, stmt.expression);
- return stmt.expression.check (analyzer);
+ return stmt.expression.check (context);
}
left.lvalue = true;
- if (!left.check (analyzer)) {
+ if (!left.check (context)) {
// skip on error in inner expression
error = true;
return false;
var ma = (MemberAccess) left;
if ((!(ma.symbol_reference is Signal || ma.symbol_reference is DynamicProperty) && ma.value_type == null) ||
- (ma.inner == null && ma.member_name == "this" && analyzer.is_in_instance_method ())) {
+ (ma.inner == null && ma.member_name == "this" && context.analyzer.is_in_instance_method ())) {
error = true;
Report.error (source_reference, "unsupported lvalue in assignment");
return false;
if (ma.symbol_reference is DynamicSignal) {
// target_type not available for dynamic signals
- if (!analyzer.context.deprecated) {
+ if (!context.deprecated) {
Report.warning (source_reference, "deprecated syntax, use `connect' method instead");
}
} else if (ma.symbol_reference is Signal) {
- if (!analyzer.context.deprecated) {
+ if (!context.deprecated) {
Report.warning (source_reference, "deprecated syntax, use `connect' method instead");
}
var sig = (Signal) ma.symbol_reference;
} else if (left is ElementAccess) {
var ea = (ElementAccess) left;
- if (ea.container.value_type.data_type == analyzer.string_type.data_type) {
+ if (ea.container.value_type.data_type == context.analyzer.string_type.data_type) {
error = true;
Report.error (ea.source_reference, "strings are immutable");
return false;
}
set_call.add_argument (right);
parent_node.replace_expression (this, set_call);
- return set_call.check (analyzer);
+ return set_call.check (context);
} else {
right.target_type = left.value_type;
}
return false;
}
- if (!right.check (analyzer)) {
+ if (!right.check (context)) {
// skip on error in inner expression
error = true;
return false;
}
right = bin;
- right.check (analyzer);
+ right.check (context);
operator = AssignmentOperator.SIMPLE;
}
}
if (prop.set_accessor == null
- || (!prop.set_accessor.writable && !(analyzer.find_current_method () is CreationMethod || analyzer.is_in_constructor ()))) {
+ || (!prop.set_accessor.writable && !(context.analyzer.find_current_method () is CreationMethod || context.analyzer.is_in_constructor ()))) {
ma.error = true;
Report.error (ma.source_reference, "Property `%s' is read-only".printf (prop.get_full_name ()));
return false;
- } else if (!analyzer.context.deprecated
+ } else if (!context.deprecated
&& !prop.set_accessor.writable
- && analyzer.find_current_method () is CreationMethod) {
- if (ma.inner.symbol_reference != analyzer.find_current_method ().this_parameter) {
+ && context.analyzer.find_current_method () is CreationMethod) {
+ if (ma.inner.symbol_reference != context.analyzer.find_current_method ().this_parameter) {
// trying to set construct-only property in creation method for foreign instance
Report.error (ma.source_reference, "Property `%s' is read-only".printf (prop.get_full_name ()));
return false;
return true;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!analyzer.is_in_instance_method ()) {
+ if (!context.analyzer.is_in_instance_method ()) {
error = true;
Report.error (source_reference, "Base access invalid outside of instance methods");
return false;
}
- if (analyzer.current_class == null) {
- if (analyzer.current_struct == null) {
+ if (context.analyzer.current_class == null) {
+ if (context.analyzer.current_struct == null) {
error = true;
Report.error (source_reference, "Base access invalid outside of class and struct");
return false;
- } else if (analyzer.current_struct.base_type == null) {
+ } else if (context.analyzer.current_struct.base_type == null) {
error = true;
Report.error (source_reference, "Base access invalid without base type");
return false;
}
- value_type = analyzer.current_struct.base_type;
- } else if (analyzer.current_class.base_class == null) {
+ value_type = context.analyzer.current_struct.base_type;
+ } else if (context.analyzer.current_class.base_class == null) {
error = true;
Report.error (source_reference, "Base access invalid without base class");
return false;
} else {
- foreach (var base_type in analyzer.current_class.get_base_types ()) {
+ foreach (var base_type in context.analyzer.current_class.get_base_types ()) {
if (base_type.data_type is Class) {
value_type = base_type.copy ();
value_type.value_owned = false;
return left.is_non_null () && right.is_non_null ();
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
// some expressions are not in a block,
// for example, expressions in method contracts
- if (analyzer.current_symbol is Block
+ if (context.analyzer.current_symbol is Block
&& (operator == BinaryOperator.AND || operator == BinaryOperator.OR)) {
// convert conditional expression into if statement
// required for flow analysis and exception handling
- var local = new LocalVariable (analyzer.bool_type.copy (), get_temp_name (), null, source_reference);
+ var local = new LocalVariable (context.analyzer.bool_type.copy (), get_temp_name (), null, source_reference);
var decl = new DeclarationStatement (local, source_reference);
- decl.check (analyzer);
+ decl.check (context);
var right_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple (local.name, right.source_reference), right, AssignmentOperator.SIMPLE, right.source_reference), right.source_reference);
var if_stmt = new IfStatement (left, true_block, false_block, source_reference);
- insert_statement (analyzer.insert_block, decl);
- insert_statement (analyzer.insert_block, if_stmt);
+ insert_statement (context.analyzer.insert_block, decl);
+ insert_statement (context.analyzer.insert_block, if_stmt);
- if (!if_stmt.check (analyzer)) {
+ if (!if_stmt.check (context)) {
error = true;
return false;
}
var ma = new MemberAccess.simple (local.name, source_reference);
ma.target_type = target_type;
- ma.check (analyzer);
+ ma.check (context);
parent_node.replace_expression (this, ma);
if (operator == BinaryOperator.COALESCE) {
var local = new LocalVariable (null, get_temp_name (), left, source_reference);
var decl = new DeclarationStatement (local, source_reference);
- decl.check (analyzer);
+ decl.check (context);
var right_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple (local.name, right.source_reference), right, AssignmentOperator.SIMPLE, right.source_reference), right.source_reference);
var if_stmt = new IfStatement (cond, true_block, null, source_reference);
- insert_statement (analyzer.insert_block, decl);
- insert_statement (analyzer.insert_block, if_stmt);
+ insert_statement (context.analyzer.insert_block, decl);
+ insert_statement (context.analyzer.insert_block, if_stmt);
- if (!if_stmt.check (analyzer)) {
+ if (!if_stmt.check (context)) {
error = true;
return false;
}
var ma = new MemberAccess.simple (local.name, source_reference);
ma.target_type = target_type;
- ma.check (analyzer);
+ ma.check (context);
parent_node.replace_expression (this, ma);
return true;
}
- if (!left.check (analyzer) || !right.check (analyzer)) {
+ if (!left.check (context) || !right.check (context)) {
/* if there were any errors in inner expressions, skip type check */
error = true;
return false;
return false;
}
- if (left.value_type.data_type == analyzer.string_type.data_type
+ if (left.value_type.data_type == context.analyzer.string_type.data_type
&& operator == BinaryOperator.PLUS) {
// string concatenation
- if (analyzer.context.profile == Profile.DOVA) {
+ if (context.profile == Profile.DOVA) {
var concat_call = new MethodCall (new MemberAccess (left, "concat", source_reference), source_reference);
concat_call.add_argument (right);
concat_call.target_type = target_type;
parent_node.replace_expression (this, concat_call);
- return concat_call.check (analyzer);
+ return concat_call.check (context);
}
- if (right.value_type == null || right.value_type.data_type != analyzer.string_type.data_type) {
+ if (right.value_type == null || right.value_type.data_type != context.analyzer.string_type.data_type) {
error = true;
Report.error (source_reference, "Operands must be strings");
return false;
}
- value_type = analyzer.string_type.copy ();
+ value_type = context.analyzer.string_type.copy ();
if (left.is_constant () && right.is_constant ()) {
value_type.value_owned = false;
} else {
value_type.value_owned = true;
}
- } else if (analyzer.context.profile == Profile.DOVA && left.value_type.data_type == analyzer.list_type.data_type
+ } else if (context.profile == Profile.DOVA && left.value_type.data_type == context.analyzer.list_type.data_type
&& operator == BinaryOperator.PLUS) {
// list concatenation
concat_call.add_argument (right);
concat_call.target_type = target_type;
parent_node.replace_expression (this, concat_call);
- return concat_call.check (analyzer);
- } else if (analyzer.context.profile != Profile.DOVA && left.value_type is ArrayType && operator == BinaryOperator.PLUS) {
+ return concat_call.check (context);
+ } else if (context.profile != Profile.DOVA && left.value_type is ArrayType && operator == BinaryOperator.PLUS) {
// array concatenation
var array_type = (ArrayType) left.value_type;
}
} else if (right.value_type is PointerType) {
// pointer arithmetic: pointer - pointer
- if (analyzer.context.profile == Profile.DOVA) {
- value_type = analyzer.long_type;
+ if (context.profile == Profile.DOVA) {
+ value_type = context.analyzer.long_type;
} else {
- value_type = analyzer.size_t_type;
+ value_type = context.analyzer.size_t_type;
}
}
}
if (value_type == null) {
- value_type = analyzer.get_arithmetic_result_type (left.value_type, right.value_type);
+ value_type = context.analyzer.get_arithmetic_result_type (left.value_type, right.value_type);
}
if (value_type == null) {
|| operator == BinaryOperator.SHIFT_LEFT
|| operator == BinaryOperator.SHIFT_RIGHT
|| operator == BinaryOperator.BITWISE_XOR) {
- value_type = analyzer.get_arithmetic_result_type (left.value_type, right.value_type);
+ value_type = context.analyzer.get_arithmetic_result_type (left.value_type, right.value_type);
if (value_type == null) {
error = true;
|| operator == BinaryOperator.GREATER_THAN
|| operator == BinaryOperator.LESS_THAN_OR_EQUAL
|| operator == BinaryOperator.GREATER_THAN_OR_EQUAL) {
- if (left.value_type.compatible (analyzer.string_type)
- && right.value_type.compatible (analyzer.string_type)) {
+ if (left.value_type.compatible (context.analyzer.string_type)
+ && right.value_type.compatible (context.analyzer.string_type)) {
// string comparison
} else if (left.value_type is PointerType && right.value_type is PointerType) {
// pointer arithmetic
if (chained) {
var lbe = (BinaryExpression) left;
- resulting_type = analyzer.get_arithmetic_result_type (lbe.right.value_type, right.value_type);
+ resulting_type = context.analyzer.get_arithmetic_result_type (lbe.right.value_type, right.value_type);
} else {
- resulting_type = analyzer.get_arithmetic_result_type (left.value_type, right.value_type);
+ resulting_type = context.analyzer.get_arithmetic_result_type (left.value_type, right.value_type);
}
if (resulting_type == null) {
right.target_type.value_owned = false;
}
- value_type = analyzer.bool_type;
+ value_type = context.analyzer.bool_type;
} else if (operator == BinaryOperator.EQUALITY
|| operator == BinaryOperator.INEQUALITY) {
/* relational operation */
}
}
- if (left.value_type.compatible (analyzer.string_type)
- && right.value_type.compatible (analyzer.string_type)) {
+ if (left.value_type.compatible (context.analyzer.string_type)
+ && right.value_type.compatible (context.analyzer.string_type)) {
// string comparison
- if (analyzer.context.profile == Profile.DOVA) {
+ if (context.profile == Profile.DOVA) {
var string_ma = new MemberAccess.simple ("string", source_reference);
string_ma.qualified = true;
var equals_call = new MethodCall (new MemberAccess (string_ma, "equals", source_reference), source_reference);
equals_call.add_argument (right);
if (operator == BinaryOperator.EQUALITY) {
parent_node.replace_expression (this, equals_call);
- return equals_call.check (analyzer);
+ return equals_call.check (context);
} else {
var not = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, equals_call, source_reference);
parent_node.replace_expression (this, not);
- return not.check (analyzer);
+ return not.check (context);
}
}
}
- value_type = analyzer.bool_type;
+ value_type = context.analyzer.bool_type;
} else if (operator == BinaryOperator.BITWISE_AND
|| operator == BinaryOperator.BITWISE_OR) {
// integer type or flags type
value_type = left.value_type;
} else if (operator == BinaryOperator.AND
|| operator == BinaryOperator.OR) {
- if (!left.value_type.compatible (analyzer.bool_type) || !right.value_type.compatible (analyzer.bool_type)) {
+ if (!left.value_type.compatible (context.analyzer.bool_type) || !right.value_type.compatible (context.analyzer.bool_type)) {
error = true;
Report.error (source_reference, "Operands must be boolean");
}
- value_type = analyzer.bool_type;
+ value_type = context.analyzer.bool_type;
} else if (operator == BinaryOperator.IN) {
- if (left.value_type.compatible (analyzer.int_type)
- && right.value_type.compatible (analyzer.int_type)) {
+ if (left.value_type.compatible (context.analyzer.int_type)
+ && right.value_type.compatible (context.analyzer.int_type)) {
// integers or enums
} else if (right.value_type is ArrayType) {
if (!left.value_type.compatible (((ArrayType) right.value_type).element_type)) {
error = true;
return false;
}
- if (!contains_method.return_type.compatible (analyzer.bool_type)) {
+ if (!contains_method.return_type.compatible (context.analyzer.bool_type)) {
Report.error (source_reference, "`%s' must return a boolean value".printf (contains_method.get_full_name ()));
error = true;
return false;
var contains_call = new MethodCall (new MemberAccess (right, "contains"));
contains_call.add_argument (left);
parent_node.replace_expression (this, contains_call);
- return contains_call.check (analyzer);
+ return contains_call.check (context);
}
- value_type = analyzer.bool_type;
+ value_type = context.analyzer.bool_type;
} else {
assert_not_reached ();
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- owner = analyzer.current_symbol.scope;
+ owner = context.analyzer.current_symbol.scope;
- var old_symbol = analyzer.current_symbol;
- var old_insert_block = analyzer.insert_block;
- analyzer.current_symbol = this;
- analyzer.insert_block = this;
+ var old_symbol = context.analyzer.current_symbol;
+ var old_insert_block = context.analyzer.insert_block;
+ context.analyzer.current_symbol = this;
+ context.analyzer.insert_block = this;
for (int i = 0; i < statement_list.size; i++) {
- statement_list[i].check (analyzer);
+ statement_list[i].check (context);
}
foreach (LocalVariable local in get_local_variables ()) {
add_error_types (stmt.get_error_types ());
}
- analyzer.current_symbol = old_symbol;
- analyzer.insert_block = old_insert_block;
+ context.analyzer.current_symbol = old_symbol;
+ context.analyzer.insert_block = old_insert_block;
return !error;
}
return true;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- value_type = analyzer.bool_type;
+ value_type = context.analyzer.bool_type;
return !error;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!inner.check (analyzer)) {
+ if (!inner.check (context)) {
error = true;
return false;
}
type_reference.nullable = false;
}
- type_reference.check (analyzer);
+ type_reference.check (context);
// FIXME: check whether cast is allowed
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
error_variable.checked = true;
} else {
// generic catch clause
- if (analyzer.context.profile == Profile.GOBJECT) {
+ if (context.profile == Profile.GOBJECT) {
error_type = new ErrorType (null, null, source_reference);
} else {
- error_type = analyzer.error_type;
+ error_type = context.analyzer.error_type;
}
}
- error_type.check (analyzer);
+ error_type.check (context);
- body.check (analyzer);
+ body.check (context);
return !error;
}
return value;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (analyzer.context.profile == Profile.DOVA) {
- value_type = new IntegerType ((Struct) analyzer.root_symbol.scope.lookup ("char"), get_char ().to_string (), "int");
+ if (context.profile == Profile.DOVA) {
+ value_type = new IntegerType ((Struct) context.analyzer.root_symbol.scope.lookup ("char"), get_char ().to_string (), "int");
} else {
if (get_char () < 128) {
- value_type = new IntegerType ((Struct) analyzer.root_symbol.scope.lookup ("char"));
+ value_type = new IntegerType ((Struct) context.analyzer.root_symbol.scope.lookup ("char"));
} else {
- value_type = new IntegerType ((Struct) analyzer.root_symbol.scope.lookup ("unichar"));
+ value_type = new IntegerType ((Struct) context.analyzer.root_symbol.scope.lookup ("unichar"));
}
}
return false;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
foreach (DataType base_type_reference in get_base_types ()) {
- if (!base_type_reference.check (analyzer)) {
+ if (!base_type_reference.check (context)) {
error = true;
return false;
}
}
// check whether base type is at least as accessible as the class
- if (!analyzer.is_type_accessible (this, base_type_reference)) {
+ if (!context.analyzer.is_type_accessible (this, base_type_reference)) {
error = true;
Report.error (source_reference, "base type `%s` is less accessible than class `%s`".printf (base_type_reference.to_string (), get_full_name ()));
return false;
}
foreach (DataType type in base_types) {
- type.check (analyzer);
+ type.check (context);
}
foreach (TypeParameter p in get_type_parameters ()) {
- p.check (analyzer);
+ p.check (context);
}
/* process enums first to avoid order problems in C code */
foreach (Enum en in enums) {
- en.check (analyzer);
+ en.check (context);
}
foreach (Field f in fields) {
- f.check (analyzer);
+ f.check (context);
}
foreach (Constant c in constants) {
- c.check (analyzer);
+ c.check (context);
}
foreach (Method m in methods) {
- m.check (analyzer);
+ m.check (context);
}
foreach (Property prop in properties) {
- prop.check (analyzer);
+ prop.check (context);
}
foreach (Signal sig in signals) {
- sig.check (analyzer);
+ sig.check (context);
}
if (constructor != null) {
- constructor.check (analyzer);
+ constructor.check (context);
}
if (class_constructor != null) {
- class_constructor.check (analyzer);
+ class_constructor.check (context);
}
if (static_constructor != null) {
- static_constructor.check (analyzer);
+ static_constructor.check (context);
}
if (destructor != null) {
- destructor.check (analyzer);
+ destructor.check (context);
}
if (static_destructor != null) {
- static_destructor.check (analyzer);
+ static_destructor.check (context);
}
if (class_destructor != null) {
- class_destructor.check (analyzer);
+ class_destructor.check (context);
}
foreach (Class cl in classes) {
- cl.check (analyzer);
+ cl.check (context);
}
foreach (Struct st in structs) {
- st.check (analyzer);
+ st.check (context);
}
foreach (Delegate d in delegates) {
- d.check (analyzer);
+ d.check (context);
}
/* compact classes cannot implement interfaces */
while (base_class != null && base_class.is_abstract) {
foreach (Method base_method in base_class.get_methods ()) {
if (base_method.is_abstract) {
- var override_method = analyzer.symbol_lookup_inherited (this, base_method.name) as Method;
+ var override_method = context.analyzer.symbol_lookup_inherited (this, base_method.name) as Method;
if (override_method == null || !override_method.overrides) {
error = true;
Report.error (source_reference, "`%s' does not implement abstract method `%s'".printf (get_full_name (), base_method.get_full_name ()));
}
foreach (Property base_property in base_class.get_properties ()) {
if (base_property.is_abstract) {
- var override_property = analyzer.symbol_lookup_inherited (this, base_property.name) as Property;
+ var override_property = context.analyzer.symbol_lookup_inherited (this, base_property.name) as Property;
if (override_property == null || !override_property.overrides) {
error = true;
Report.error (source_reference, "`%s' does not implement abstract property `%s'".printf (get_full_name (), base_property.get_full_name ()));
}
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
return !error;
}
public virtual void accept_children (CodeVisitor visitor) {
}
- public virtual bool check (SemanticAnalyzer analyzer) {
+ public virtual bool check (CodeContext context) {
return true;
}
return condition.is_pure () && true_expression.is_pure () && false_expression.is_pure ();
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!(analyzer.current_symbol is Block)) {
+ if (!(context.analyzer.current_symbol is Block)) {
Report.error (source_reference, "Conditional expressions may only be used in blocks");
error = true;
return false;
var if_stmt = new IfStatement (condition, true_block, false_block, source_reference);
- insert_statement (analyzer.insert_block, decl);
- insert_statement (analyzer.insert_block, if_stmt);
+ insert_statement (context.analyzer.insert_block, decl);
+ insert_statement (context.analyzer.insert_block, if_stmt);
- if (!if_stmt.check (analyzer) || true_expression.error || false_expression.error) {
+ if (!if_stmt.check (context) || true_expression.error || false_expression.error) {
error = true;
return false;
}
value_type.value_owned = (true_expression.value_type.value_owned || false_expression.value_type.value_owned);
local.variable_type = value_type;
- decl.check (analyzer);
+ decl.check (context);
true_expression.target_type = value_type;
false_expression.target_type = value_type;
var true_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple (local.name, true_expression.source_reference), true_expression, AssignmentOperator.SIMPLE, true_expression.source_reference), true_expression.source_reference);
- true_stmt.check (analyzer);
+ true_stmt.check (context);
var false_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple (local.name, false_expression.source_reference), false_expression, AssignmentOperator.SIMPLE, false_expression.source_reference), false_expression.source_reference);
- false_stmt.check (analyzer);
+ false_stmt.check (context);
true_block.replace_statement (true_decl, true_stmt);
false_block.replace_statement (false_decl, false_stmt);
var ma = new MemberAccess.simple (local.name, source_reference);
ma.target_type = target_type;
- ma.check (analyzer);
+ ma.check (context);
parent_node.replace_expression (this, ma);
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
- type_reference.check (analyzer);
+ type_reference.check (context);
- if (!check_const_type (type_reference, analyzer)) {
+ if (!check_const_type (type_reference, context)) {
error = true;
Report.error (source_reference, "`%s' not supported as type for constants".printf (type_reference.to_string ()));
return false;
} else {
value.target_type = type_reference;
- value.check (analyzer);
+ value.check (context);
if (!value.value_type.compatible (type_reference)) {
error = true;
Report.warning (source_reference, "%s hides inherited constant `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
active = true;
return !error;
}
- bool check_const_type (DataType type, SemanticAnalyzer analyzer) {
+ bool check_const_type (DataType type, CodeContext context) {
if (type is ValueType) {
return true;
} else if (type is ArrayType) {
var array_type = type as ArrayType;
- return check_const_type (array_type.element_type, analyzer);
- } else if (type.data_type == analyzer.string_type.data_type) {
+ return check_const_type (array_type.element_type, context);
+ } else if (type.data_type == context.analyzer.string_type.data_type) {
return true;
} else {
return false;
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- this_parameter = new Parameter ("this", new ObjectType (analyzer.current_class));
+ this_parameter = new Parameter ("this", new ObjectType (context.analyzer.current_class));
scope.add (this_parameter.name, this_parameter);
- owner = analyzer.current_symbol.scope;
- analyzer.current_symbol = this;
+ owner = context.analyzer.current_symbol.scope;
+ context.analyzer.current_symbol = this;
if (body != null) {
- body.check (analyzer);
+ body.check (context);
}
foreach (DataType body_error_type in body.get_error_types ()) {
}
}
- analyzer.current_symbol = analyzer.current_symbol.parent_symbol;
+ context.analyzer.current_symbol = context.analyzer.current_symbol.parent_symbol;
return !error;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
if (class_name != null && class_name != parent_symbol.name) {
// class_name is null for constructors generated by GIdlParser
- Report.error (source_reference, "missing return type in method `%s.%s´".printf (analyzer.current_symbol.get_full_name (), class_name));
+ Report.error (source_reference, "missing return type in method `%s.%s´".printf (context.analyzer.current_symbol.get_full_name (), class_name));
error = true;
return false;
}
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
foreach (Parameter param in get_parameters()) {
- param.check (analyzer);
+ param.check (context);
}
foreach (DataType error_type in get_error_types ()) {
- error_type.check (analyzer);
+ error_type.check (context);
}
foreach (Expression precondition in get_preconditions ()) {
- precondition.check (analyzer);
+ precondition.check (context);
}
foreach (Expression postcondition in get_postconditions ()) {
- postcondition.check (analyzer);
+ postcondition.check (context);
}
if (body != null) {
- body.check (analyzer);
+ body.check (context);
var cl = parent_symbol as Class;
// ensure we chain up to base constructor
if (!chain_up && cl != null && cl.base_class != null) {
- if (analyzer.context.profile == Profile.GOBJECT
+ if (context.profile == Profile.GOBJECT
&& cl.base_class.default_construction_method != null
&& !cl.base_class.default_construction_method.has_construct_function) {
// directly chain up to Object
- var old_insert_block = analyzer.insert_block;
- analyzer.current_symbol = body;
- analyzer.insert_block = body;
+ var old_insert_block = context.analyzer.insert_block;
+ context.analyzer.current_symbol = body;
+ context.analyzer.insert_block = body;
var stmt = new ExpressionStatement (new MethodCall (new MemberAccess (new MemberAccess.simple ("GLib", source_reference), "Object", source_reference), source_reference), source_reference);
body.insert_statement (0, stmt);
- stmt.check (analyzer);
+ stmt.check (context);
- analyzer.current_symbol = this;
- analyzer.insert_block = old_insert_block;
+ context.analyzer.current_symbol = this;
+ context.analyzer.insert_block = old_insert_block;
} else if (cl.base_class.default_construction_method == null
|| cl.base_class.default_construction_method.access == SymbolAccessibility.PRIVATE) {
Report.error (source_reference, "unable to chain up to private base constructor");
} else if (cl.base_class.default_construction_method.get_required_arguments () > 0) {
Report.error (source_reference, "unable to chain up to base constructor requiring arguments");
} else {
- var old_insert_block = analyzer.insert_block;
- analyzer.current_symbol = body;
- analyzer.insert_block = body;
+ var old_insert_block = context.analyzer.insert_block;
+ context.analyzer.current_symbol = body;
+ context.analyzer.insert_block = body;
var stmt = new ExpressionStatement (new MethodCall (new BaseAccess (source_reference), source_reference), source_reference);
body.insert_statement (0, stmt);
- stmt.check (analyzer);
+ stmt.check (context);
- analyzer.current_symbol = this;
- analyzer.insert_block = old_insert_block;
+ context.analyzer.current_symbol = this;
+ context.analyzer.insert_block = old_insert_block;
}
}
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
if (is_abstract || is_virtual || overrides) {
Report.error (source_reference, "The creation method `%s' cannot be marked as override, virtual, or abstract".printf (get_full_name ()));
declaration.accept (visitor);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- declaration.check (analyzer);
+ declaration.check (context);
var local = declaration as LocalVariable;
if (local != null && local.initializer != null) {
return str;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
- var old_source_file = analyzer.current_source_file;
+ var old_source_file = context.analyzer.current_source_file;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
foreach (TypeParameter p in type_parameters) {
- p.check (analyzer);
+ p.check (context);
}
- return_type.check (analyzer);
+ return_type.check (context);
foreach (Parameter param in parameters) {
- param.check (analyzer);
+ param.check (context);
}
foreach (DataType error_type in get_error_types ()) {
- error_type.check (analyzer);
+ error_type.check (context);
}
- analyzer.current_source_file = old_source_file;
+ context.analyzer.current_source_file = old_source_file;
return !error;
}
return "G_TYPE_POINTER";
}
- public override bool check (SemanticAnalyzer analyzer) {
- return delegate_symbol.check (analyzer);
+ public override bool check (CodeContext context) {
+ return delegate_symbol.check (context);
}
public override bool is_disposable () {
expression.accept (visitor);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!expression.check (analyzer)) {
+ if (!expression.check (context)) {
// if there was an error in the inner expression, skip this check
return false;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- owner = analyzer.current_symbol.scope;
- analyzer.current_symbol = this;
+ owner = context.analyzer.current_symbol.scope;
+ context.analyzer.current_symbol = this;
if (body != null) {
- body.check (analyzer);
+ body.check (context);
}
- analyzer.current_symbol = analyzer.current_symbol.parent_symbol;
+ context.analyzer.current_symbol = context.analyzer.current_symbol.parent_symbol;
return !error;
}
return (literal != null && literal.value);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
// convert to simple loop
// do not generate variable and if block if condition is always true
var parent_block = (Block) parent_node;
parent_block.replace_statement (this, loop);
- return loop.check (analyzer);
+ return loop.check (context);
}
var block = new Block (source_reference);
- var first_local = new LocalVariable (analyzer.bool_type.copy (), get_temp_name (), new BooleanLiteral (true, source_reference), source_reference);
+ var first_local = new LocalVariable (context.analyzer.bool_type.copy (), get_temp_name (), new BooleanLiteral (true, source_reference), source_reference);
block.add_statement (new DeclarationStatement (first_local, source_reference));
var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, condition, condition.source_reference);
var parent_block = (Block) parent_node;
parent_block.replace_statement (this, block);
- return block.check (analyzer);
+ return block.check (context);
}
}
return cname;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
return true;
}
}
return new ArrayList<string> ();
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
return true;
}
}
this.dynamic_type = dynamic_type;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
return true;
}
}
return container.is_pure ();
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!container.check (analyzer)) {
+ if (!container.check (context)) {
/* don't proceed if a child expression failed */
error = true;
return false;
Report.error (source_reference, "Element access with more than one dimension is not supported for signals");
return false;
}
- get_indices ().get (0).target_type = analyzer.string_type.copy ();
+ get_indices ().get (0).target_type = context.analyzer.string_type.copy ();
}
foreach (Expression index in get_indices ()) {
- index.check (analyzer);
+ index.check (context);
}
bool index_int_type_check = true;
}
} else if (pointer_type != null && !pointer_type.base_type.is_reference_type_or_type_parameter ()) {
value_type = pointer_type.base_type.copy ();
- } else if (analyzer.context.profile == Profile.DOVA && container_type == analyzer.tuple_type.data_type) {
+ } else if (context.profile == Profile.DOVA && container_type == context.analyzer.tuple_type.data_type) {
if (get_indices ().size != 1) {
error = true;
Report.error (source_reference, "Element access with more than one dimension is not supported for tuples");
get_call.add_argument (index);
get_call.target_type = this.target_type;
parent_node.replace_expression (this, get_call);
- return get_call.check (analyzer);
+ return get_call.check (context);
} else if (container is MemberAccess && container.symbol_reference is Signal) {
index_int_type_check = false;
get_call.formal_target_type = this.formal_target_type;
get_call.target_type = this.target_type;
parent_node.replace_expression (this, get_call);
- return get_call.check (analyzer);
+ return get_call.check (context);
}
}
return "0";
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
foreach (EnumValue value in values) {
- value.check (analyzer);
+ value.check (context);
}
foreach (Method m in methods) {
- m.check (analyzer);
+ m.check (context);
}
foreach (Constant c in constants) {
- c.check (analyzer);
+ c.check (context);
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
return !error;
}
return "%s%s".printf (en.get_cprefix (), name);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
if (value != null) {
- value.check (analyzer);
+ value.check (context);
}
return !error;
return get_cname ().down ();
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
if (value != null) {
- value.check (analyzer);
+ value.check (context);
}
return !error;
return "g_value_set_pointer";
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
foreach (ErrorCode ecode in codes) {
- ecode.check (analyzer);
+ ecode.check (context);
}
foreach (Method m in methods) {
- m.check (analyzer);
+ m.check (context);
}
return !error;
return true;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (error_domain != null) {
- return error_domain.check (analyzer);
+ return error_domain.check (context);
}
return true;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!expression.check (analyzer)) {
+ if (!expression.check (context)) {
// ignore inner error
error = true;
return false;
attr.add_argument ("type", "\"%s\"".printf (ctype));
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
if (variable_type is VoidType) {
error = true;
return false;
}
- variable_type.check (analyzer);
+ variable_type.check (context);
// check whether field type is at least as accessible as the field
- if (!analyzer.is_type_accessible (this, variable_type)) {
+ if (!context.analyzer.is_type_accessible (this, variable_type)) {
error = true;
Report.error (source_reference, "field type `%s` is less accessible than field `%s`".printf (variable_type.to_string (), get_full_name ()));
return false;
if (initializer != null) {
initializer.target_type = variable_type;
- if (!initializer.check (analyzer)) {
+ if (!initializer.check (context)) {
error = true;
return false;
}
Report.warning (source_reference, "%s hides inherited field `%s'. Use the `new' keyword if hiding was intentional".printf (get_full_name (), get_hidden_member ().get_full_name ()));
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
return !error;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
// analyze collection expression first, used for type inference
- if (!collection.check (analyzer)) {
+ if (!collection.check (context)) {
// ignore inner error
error = true;
return false;
var collection_type = collection.value_type.copy ();
collection.target_type = collection_type.copy ();
- if (analyzer.context.profile != Profile.DOVA && collection_type.is_array ()) {
+ if (context.profile != Profile.DOVA && collection_type.is_array ()) {
var array_type = (ArrayType) collection_type;
// can't use inline-allocated array for temporary variable
array_type.inline_allocated = false;
- return check_without_iterator (analyzer, collection_type, array_type.element_type);
- } else if (analyzer.context.profile == Profile.GOBJECT && (collection_type.compatible (analyzer.glist_type) || collection_type.compatible (analyzer.gslist_type))) {
+ return check_without_iterator (context, collection_type, array_type.element_type);
+ } else if (context.profile == Profile.GOBJECT && (collection_type.compatible (context.analyzer.glist_type) || collection_type.compatible (context.analyzer.gslist_type))) {
if (collection_type.get_type_arguments ().size != 1) {
error = true;
Report.error (collection.source_reference, "missing type argument for collection");
return false;
}
- return check_without_iterator (analyzer, collection_type, collection_type.get_type_arguments ().get (0));
- } else if (analyzer.context.profile == Profile.GOBJECT && collection_type.compatible (analyzer.gvaluearray_type)) {
- return check_without_iterator (analyzer, collection_type, analyzer.gvalue_type);
+ return check_without_iterator (context, collection_type, collection_type.get_type_arguments ().get (0));
+ } else if (context.profile == Profile.GOBJECT && collection_type.compatible (context.analyzer.gvaluearray_type)) {
+ return check_without_iterator (context, collection_type, context.analyzer.gvalue_type);
} else {
- return check_with_iterator (analyzer, collection_type);
+ return check_with_iterator (context, collection_type);
}
}
- bool check_with_index (SemanticAnalyzer analyzer, DataType collection_type) {
+ bool check_with_index (CodeContext context, DataType collection_type) {
var get_method = collection_type.get_member ("get") as Method;
if (get_method == null) {
return false;
body.insert_statement (0, new DeclarationStatement (new LocalVariable (type_reference, variable_name, get_call, source_reference), source_reference));
checked = false;
- return base.check (analyzer);
+ return base.check (context);
}
- bool check_with_iterator (SemanticAnalyzer analyzer, DataType collection_type) {
+ bool check_with_iterator (CodeContext context, DataType collection_type) {
use_iterator = true;
- if (check_with_index (analyzer, collection_type)) {
+ if (check_with_index (context, collection_type)) {
return true;
}
error = true;
return false;
}
- if (!next_method.return_type.compatible (analyzer.bool_type)) {
+ if (!next_method.return_type.compatible (context.analyzer.bool_type)) {
Report.error (collection.source_reference, "`%s' must return a boolean value".printf (next_method.get_full_name ()));
error = true;
return false;
}
checked = false;
- return base.check (analyzer);
+ return base.check (context);
}
bool analyze_element_type (DataType element_type) {
return true;
}
- bool check_without_iterator (SemanticAnalyzer analyzer, DataType collection_type, DataType element_type) {
+ bool check_without_iterator (CodeContext context, DataType collection_type, DataType element_type) {
// analyze element type
if (type_reference == null) {
// var type
element_variable.checked = true;
// analyze body
- owner = analyzer.current_symbol.scope;
- analyzer.current_symbol = this;
+ owner = context.analyzer.current_symbol.scope;
+ context.analyzer.current_symbol = this;
- body.check (analyzer);
+ body.check (context);
foreach (LocalVariable local in get_local_variables ()) {
local.active = false;
}
- analyzer.current_symbol = analyzer.current_symbol.parent_symbol;
+ context.analyzer.current_symbol = context.analyzer.current_symbol.parent_symbol;
collection_variable = new LocalVariable (collection_type, "%s_collection".printf (variable_name));
return (literal != null && !literal.value);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
// convert to simple loop
var block = new Block (source_reference);
}
// iterator
- var first_local = new LocalVariable (analyzer.bool_type.copy (), get_temp_name (), new BooleanLiteral (true, source_reference), source_reference);
+ var first_local = new LocalVariable (context.analyzer.bool_type.copy (), get_temp_name (), new BooleanLiteral (true, source_reference), source_reference);
block.add_statement (new DeclarationStatement (first_local, source_reference));
var iterator_block = new Block (source_reference);
var parent_block = (Block) parent_node;
parent_block.replace_statement (this, block);
- return block.check (analyzer);
+ return block.check (context);
}
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- condition.target_type = analyzer.bool_type.copy ();
+ condition.target_type = context.analyzer.bool_type.copy ();
- condition.check (analyzer);
+ condition.check (context);
- true_statement.check (analyzer);
+ true_statement.check (context);
if (false_statement != null) {
- false_statement.check (analyzer);
+ false_statement.check (context);
}
if (condition.error) {
return false;
}
- if (condition.value_type == null || !condition.value_type.compatible (analyzer.bool_type)) {
+ if (condition.value_type == null || !condition.value_type.compatible (context.analyzer.bool_type)) {
error = true;
Report.error (condition.source_reference, "Condition must be boolean");
return false;
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
old_parent_node.replace_expression (this, array_creation);
checked = false;
- return array_creation.check (analyzer);
+ return array_creation.check (context);
}
DataType inner_target_type;
}
foreach (Expression expr in initializers) {
- expr.check (analyzer);
+ expr.check (context);
}
bool error = false;
return true;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
}
}
- var st = (Struct) analyzer.root_symbol.scope.lookup (type_name);
+ var st = (Struct) context.analyzer.root_symbol.scope.lookup (type_name);
// ensure attributes are already processed in case of bootstrapping dova-core
- st.check (analyzer);
+ st.check (context);
value_type = new IntegerType (st, value, type_name);
return null;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
foreach (DataType prerequisite_reference in get_prerequisites ()) {
// check whether prerequisite is at least as accessible as the interface
- if (!analyzer.is_type_accessible (this, prerequisite_reference)) {
+ if (!context.analyzer.is_type_accessible (this, prerequisite_reference)) {
error = true;
Report.error (source_reference, "prerequisite `%s` is less accessible than interface `%s`".printf (prerequisite_reference.to_string (), get_full_name ()));
return false;
}
foreach (DataType type in prerequisites) {
- type.check (analyzer);
+ type.check (context);
}
foreach (TypeParameter p in get_type_parameters ()) {
- p.check (analyzer);
+ p.check (context);
}
foreach (Enum en in enums) {
- en.check (analyzer);
+ en.check (context);
}
foreach (Method m in methods) {
- m.check (analyzer);
+ m.check (context);
}
foreach (Field f in fields) {
- f.check (analyzer);
+ f.check (context);
}
foreach (Constant c in constants) {
- c.check (analyzer);
+ c.check (context);
}
foreach (Property prop in properties) {
- prop.check (analyzer);
+ prop.check (context);
}
foreach (Signal sig in signals) {
- sig.check (analyzer);
+ sig.check (context);
}
foreach (Class cl in classes) {
- cl.check (analyzer);
+ cl.check (context);
}
foreach (Struct st in structs) {
- st.check (analyzer);
+ st.check (context);
}
foreach (Delegate d in delegates) {
- d.check (analyzer);
+ d.check (context);
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
return !error;
}
return false;
}
- string get_lambda_name (SemanticAnalyzer analyzer) {
- var result = "_lambda%d_".printf (analyzer.next_lambda_id);
+ string get_lambda_name (CodeContext context) {
+ var result = "_lambda%d_".printf (context.analyzer.next_lambda_id);
- analyzer.next_lambda_id++;
+ context.analyzer.next_lambda_id++;
return result;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
var cb = (Delegate) ((DelegateType) target_type).delegate_symbol;
var return_type = cb.return_type.get_actual_type (target_type, null, this);
- method = new Method (get_lambda_name (analyzer), return_type, source_reference);
+ method = new Method (get_lambda_name (context), return_type, source_reference);
// track usage for flow analyzer
method.used = true;
method.check_deprecated (source_reference);
- if (!cb.has_target || !analyzer.is_in_instance_method ()) {
+ if (!cb.has_target || !context.analyzer.is_in_instance_method ()) {
method.binding = MemberBinding.STATIC;
} else {
- var sym = analyzer.current_symbol;
+ var sym = context.analyzer.current_symbol;
while (method.this_parameter == null) {
if (sym is Property) {
var prop = (Property) sym;
sym = sym.parent_symbol;
}
}
- method.owner = analyzer.current_symbol.scope;
+ method.owner = context.analyzer.current_symbol.scope;
if (!(method.return_type is VoidType) && CodeContext.get ().profile == Profile.DOVA) {
method.result_var = new LocalVariable (method.return_type.copy (), "result", null, source_reference);
block.scope.parent_scope = method.scope;
if (method.return_type.data_type != null) {
- if (analyzer.context.profile == Profile.DOVA) {
+ if (context.profile == Profile.DOVA) {
block.add_statement (new ExpressionStatement (new Assignment (new MemberAccess.simple ("result", source_reference), expression_body, AssignmentOperator.SIMPLE, source_reference), source_reference));
block.add_statement (new ReturnStatement (null, source_reference));
} else {
method.body.owner = method.scope;
// support use of generics in closures
- var m = analyzer.find_parent_method (analyzer.current_symbol);
+ var m = context.analyzer.find_parent_method (context.analyzer.current_symbol);
if (m != null) {
foreach (var type_param in m.get_type_parameters ()) {
method.add_type_parameter (new TypeParameter (type_param.name, type_param.source_reference));
/* lambda expressions should be usable like MemberAccess of a method */
symbol_reference = method;
- method.check (analyzer);
+ method.check (context);
value_type = new MethodType (method);
value_type.value_owned = target_type.value_owned;
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
initializer.append (expr);
}
- analyzer.replaced_nodes.add (this);
+ context.analyzer.replaced_nodes.add (this);
parent_node.replace_expression (this, initializer);
- return initializer.check (analyzer);
+ return initializer.check (context);
}
- var list_type = new ObjectType ((Class) analyzer.context.root.scope.lookup ("Dova").scope.lookup ("List"));
+ var list_type = new ObjectType ((Class) context.root.scope.lookup ("Dova").scope.lookup ("List"));
list_type.value_owned = true;
bool fixed_element_type = false;
if (fixed_element_type) {
expr.target_type = element_type;
}
- if (!expr.check (analyzer)) {
+ if (!expr.check (context)) {
return false;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
Report.error (source_reference, "'void' not supported as variable type");
return false;
}
- variable_type.check (analyzer);
+ variable_type.check (context);
}
if (initializer != null) {
initializer.target_type = variable_type;
- initializer.check (analyzer);
+ initializer.check (context);
}
if (variable_type == null) {
}
}
- analyzer.current_symbol.scope.add (name, this);
+ context.analyzer.current_symbol.scope.add (name, this);
// current_symbol is a Method if this is the `result'
// variable used for postconditions
- var block = analyzer.current_symbol as Block;
+ var block = context.analyzer.current_symbol as Block;
if (block != null) {
block.add_local_variable (this);
}
visitor.visit_lock_statement (this);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (body != null) {
// if the statement isn't empty, it is converted into a try statement
var parent_block = (Block) parent_node;
parent_block.replace_statement (this, block);
- return block.check (analyzer);
+ return block.check (context);
}
if (checked) {
checked = true;
- resource.check (analyzer);
+ resource.check (context);
/* resource must be a member access and denote a Lockable */
if (!(resource is MemberAccess && resource.symbol_reference is Lockable)) {
}
/* parent symbol must be the current class */
- if (resource.symbol_reference.parent_symbol != analyzer.current_class) {
+ if (resource.symbol_reference.parent_symbol != context.analyzer.current_class) {
error = true;
resource.error = true;
Report.error (resource.source_reference, "Only members of the current class are lockable");
body.accept (visitor);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- body.check (analyzer);
+ body.check (context);
add_error_types (body.get_error_types ());
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- var map_type = new ObjectType ((Class) analyzer.context.root.scope.lookup ("Dova").scope.lookup ("Map"));
+ var map_type = new ObjectType ((Class) context.root.scope.lookup ("Dova").scope.lookup ("Map"));
map_type.value_owned = true;
bool fixed_element_type = false;
keys[i].target_type = map_key_type;
values[i].target_type = map_value_type;
}
- if (!keys[i].check (analyzer)) {
+ if (!keys[i].check (context)) {
return false;
}
- if (!values[i].check (analyzer)) {
+ if (!values[i].check (context)) {
return false;
}
if (map_key_type == null) {
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
if (inner != null) {
- inner.check (analyzer);
+ inner.check (context);
}
foreach (DataType type_arg in type_argument_list) {
- type_arg.check (analyzer);
+ type_arg.check (context);
}
Symbol base_symbol = null;
symbol_reference = null;
if (qualified) {
- base_symbol = analyzer.root_symbol;
- symbol_reference = analyzer.root_symbol.scope.lookup (member_name);
+ base_symbol = context.analyzer.root_symbol;
+ symbol_reference = context.analyzer.root_symbol.scope.lookup (member_name);
} else if (inner == null) {
if (member_name == "this") {
- if (!analyzer.is_in_instance_method ()) {
+ if (!context.analyzer.is_in_instance_method ()) {
error = true;
Report.error (source_reference, "This access invalid outside of instance methods");
return false;
}
}
- base_symbol = analyzer.current_symbol;
+ base_symbol = context.analyzer.current_symbol;
// track whether method has been found to make sure that access
// to instance member is denied from within static lambda expressions
bool method_found = false;
- var sym = analyzer.current_symbol;
+ var sym = context.analyzer.current_symbol;
while (sym != null && symbol_reference == null) {
if (!method_found) {
if (sym is CreationMethod) {
}
}
- symbol_reference = analyzer.symbol_lookup_inherited (sym, member_name);
+ symbol_reference = context.analyzer.symbol_lookup_inherited (sym, member_name);
if (symbol_reference == null) {
if (sym is TypeSymbol) {
if (pointer_type != null && pointer_type.base_type is ValueType) {
// transform foo->bar to (*foo).bar
inner = new PointerIndirection (inner, source_reference);
- inner.check (analyzer);
+ inner.check (context);
pointer_member_access = false;
}
}
bool klass = false;
bool generics = false;
- if (!member.check (analyzer)) {
+ if (!member.check (context)) {
return false;
}
if (member is LocalVariable) {
var local = (LocalVariable) member;
var block = local.parent_symbol as Block;
- if (block != null && analyzer.find_parent_method_or_property_accessor (block) != analyzer.current_method_or_property_accessor) {
+ if (block != null && context.analyzer.find_parent_method_or_property_accessor (block) != context.analyzer.current_method_or_property_accessor) {
// mark all methods between current method and the captured
// block as closures (to support nested closures)
- Symbol sym = analyzer.current_method_or_property_accessor;
+ Symbol sym = context.analyzer.current_method_or_property_accessor;
while (sym != block) {
var method = sym as Method;
if (method != null) {
} else if (member is Parameter) {
var param = (Parameter) member;
var m = param.parent_symbol as Method;
- if (m != null && m != analyzer.current_method_or_property_accessor && param != m.this_parameter) {
+ if (m != null && m != context.analyzer.current_method_or_property_accessor && param != m.this_parameter) {
// mark all methods between current method and the captured
// parameter as closures (to support nested closures)
- Symbol sym = analyzer.current_method_or_property_accessor;
+ Symbol sym = context.analyzer.current_method_or_property_accessor;
while (sym != m) {
var method = sym as Method;
if (method != null) {
}
} else {
var acc = param.parent_symbol.parent_symbol as PropertyAccessor;
- if (acc != null && acc != analyzer.current_method_or_property_accessor && param != acc.prop.this_parameter) {
+ if (acc != null && acc != context.analyzer.current_method_or_property_accessor && param != acc.prop.this_parameter) {
// mark all methods between current method and the captured
// parameter as closures (to support nested closures)
- Symbol sym = analyzer.current_method_or_property_accessor;
+ Symbol sym = context.analyzer.current_method_or_property_accessor;
while (sym != m) {
var method = sym as Method;
if (method != null) {
if (m.is_async_callback) {
// ensure to use right callback method for virtual/abstract async methods
// and also for lambda expressions within async methods
- var async_method = analyzer.current_async_method;
+ var async_method = context.analyzer.current_async_method;
- if (async_method != analyzer.current_method) {
- Symbol sym = analyzer.current_method;
+ if (async_method != context.analyzer.current_method) {
+ Symbol sym = context.analyzer.current_method;
while (sym != async_method) {
var method = sym as Method;
if (method != null) {
}
} else if (member is Property) {
var prop = (Property) member;
- if (!prop.check (analyzer)) {
+ if (!prop.check (context)) {
error = true;
return false;
}
var target_type = (TypeSymbol) member.parent_symbol;
bool in_subtype = false;
- for (Symbol this_symbol = analyzer.current_symbol; this_symbol != null; this_symbol = this_symbol.parent_symbol) {
+ for (Symbol this_symbol = context.analyzer.current_symbol; this_symbol != null; this_symbol = this_symbol.parent_symbol) {
if (this_symbol == target_type) {
// required for interfaces with non-abstract methods
// accessing protected interface members
var target_type = member.parent_symbol;
bool in_target_type = false;
- for (Symbol this_symbol = analyzer.current_symbol; this_symbol != null; this_symbol = this_symbol.parent_symbol) {
+ for (Symbol this_symbol = context.analyzer.current_symbol; this_symbol != null; this_symbol = this_symbol.parent_symbol) {
if (target_type == this_symbol) {
in_target_type = true;
break;
// also set static type for prototype access
// required when using instance methods as delegates in constants
// TODO replace by MethodPrototype
- value_type = analyzer.get_value_type_for_symbol (symbol_reference, lvalue);
+ value_type = context.analyzer.get_value_type_for_symbol (symbol_reference, lvalue);
} else if (symbol_reference is Field) {
value_type = new FieldPrototype ((Field) symbol_reference);
} else {
inner.symbol_reference = this_parameter;
}
- if (analyzer.context.experimental_non_null && instance && inner.value_type.nullable &&
+ if (context.experimental_non_null && instance && inner.value_type.nullable &&
!(inner.value_type is PointerType) && !(inner.value_type is GenericType)) {
Report.error (source_reference, "Access to instance member `%s' from nullable reference denied".printf (symbol_reference.get_full_name ()));
}
- formal_value_type = analyzer.get_value_type_for_symbol (symbol_reference, lvalue);
+ formal_value_type = context.analyzer.get_value_type_for_symbol (symbol_reference, lvalue);
if (inner != null && formal_value_type != null) {
value_type = formal_value_type.get_actual_type (inner.value_type, null, this);
} else {
}
if (instance && base_method.parent_symbol is TypeSymbol) {
- inner.target_type = analyzer.get_data_type_for_symbol ((TypeSymbol) base_method.parent_symbol);
+ inner.target_type = context.analyzer.get_data_type_for_symbol ((TypeSymbol) base_method.parent_symbol);
}
} else if (symbol_reference is Property) {
var prop = (Property) symbol_reference;
}
if (instance && base_property.parent_symbol != null) {
- inner.target_type = analyzer.get_data_type_for_symbol ((TypeSymbol) base_property.parent_symbol);
+ inner.target_type = context.analyzer.get_data_type_for_symbol ((TypeSymbol) base_property.parent_symbol);
}
} else if ((symbol_reference is Field
|| symbol_reference is Signal)
&& instance && symbol_reference.parent_symbol != null) {
- inner.target_type = analyzer.get_data_type_for_symbol ((TypeSymbol) symbol_reference.parent_symbol);
+ inner.target_type = context.analyzer.get_data_type_for_symbol ((TypeSymbol) symbol_reference.parent_symbol);
}
}
initializer.accept (visitor);
}
- public override bool check (SemanticAnalyzer analyzer) {
- return initializer.check (analyzer);
+ public override bool check (CodeContext context) {
+ return initializer.check (context);
}
public override void emit (CodeGenerator codegen) {
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
Report.error (source_reference, "Non-abstract, non-extern methods must have bodies");
}
- if (coroutine && !external_package && !analyzer.context.has_package ("gio-2.0")) {
+ if (coroutine && !external_package && !context.has_package ("gio-2.0")) {
error = true;
Report.error (source_reference, "gio-2.0 package required for async methods");
return false;
}
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
- return_type.check (analyzer);
+ return_type.check (context);
var init_attr = get_attribute ("ModuleInit");
if (init_attr != null) {
}
if (return_type != null) {
- return_type.check (analyzer);
+ return_type.check (context);
}
if (parameters.size == 1 && parameters[0].ellipsis && body != null) {
}
foreach (Parameter param in parameters) {
- param.check (analyzer);
+ param.check (context);
if (coroutine && param.direction == ParameterDirection.REF) {
error = true;
Report.error (param.source_reference, "Reference parameters are not supported for async methods");
}
foreach (DataType error_type in get_error_types ()) {
- error_type.check (analyzer);
+ error_type.check (context);
// check whether error type is at least as accessible as the method
- if (!analyzer.is_type_accessible (this, error_type)) {
+ if (!context.analyzer.is_type_accessible (this, error_type)) {
error = true;
Report.error (source_reference, "error type `%s` is less accessible than method `%s`".printf (error_type.to_string (), get_full_name ()));
return false;
}
if (result_var != null) {
- result_var.check (analyzer);
+ result_var.check (context);
}
if (preconditions != null) {
foreach (Expression precondition in preconditions) {
- precondition.check (analyzer);
+ precondition.check (context);
}
}
if (postconditions != null) {
foreach (Expression postcondition in postconditions) {
- postcondition.check (analyzer);
+ postcondition.check (context);
}
}
if (body != null) {
- body.check (analyzer);
+ body.check (context);
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
- if (analyzer.current_struct != null) {
+ if (context.analyzer.current_struct != null) {
if (is_abstract || is_virtual || overrides) {
error = true;
Report.error (source_reference, "A struct member `%s' cannot be marked as override, virtual, or abstract".printf (get_full_name ()));
}
// check whether return type is at least as accessible as the method
- if (!analyzer.is_type_accessible (this, return_type)) {
+ if (!context.analyzer.is_type_accessible (this, return_type)) {
error = true;
Report.error (source_reference, "return type `%s` is less accessible than method `%s`".printf (return_type.to_string (), get_full_name ()));
return false;
return false;
}
- if (!precondition.value_type.compatible (analyzer.bool_type)) {
+ if (!precondition.value_type.compatible (context.analyzer.bool_type)) {
error = true;
Report.error (precondition.source_reference, "Precondition must be boolean");
return false;
return false;
}
- if (!postcondition.value_type.compatible (analyzer.bool_type)) {
+ if (!postcondition.value_type.compatible (context.analyzer.bool_type)) {
error = true;
Report.error (postcondition.source_reference, "Postcondition must be boolean");
return false;
}
}
- if (is_possible_entry_point (analyzer)) {
- if (analyzer.context.entry_point != null) {
+ if (is_possible_entry_point (context)) {
+ if (context.entry_point != null) {
error = true;
- Report.error (source_reference, "program already has an entry point `%s'".printf (analyzer.context.entry_point.get_full_name ()));
+ Report.error (source_reference, "program already has an entry point `%s'".printf (context.entry_point.get_full_name ()));
return false;
}
entry_point = true;
- analyzer.context.entry_point = this;
+ context.entry_point = this;
- if (tree_can_fail && analyzer.context.profile != Profile.DOVA) {
+ if (tree_can_fail && context.profile != Profile.DOVA) {
Report.error (source_reference, "\"main\" method cannot throw errors");
}
}
return !error;
}
- bool is_possible_entry_point (SemanticAnalyzer analyzer) {
+ bool is_possible_entry_point (CodeContext context) {
if (external_package) {
return false;
}
- if (analyzer.context.entry_point_name == null) {
+ if (context.entry_point_name == null) {
if (name == null || name != "main") {
// method must be called "main"
return false;
}
} else {
// custom entry point name
- if (get_full_name () != analyzer.context.entry_point_name) {
+ if (get_full_name () != context.entry_point_name) {
return false;
}
}
}
if (return_type is VoidType) {
- } else if (return_type.data_type == analyzer.int_type.data_type) {
+ } else if (return_type.data_type == context.analyzer.int_type.data_type) {
} else {
// return type must be void or int
return false;
}
var array_type = (ArrayType) param.variable_type;
- if (array_type.element_type.data_type != analyzer.string_type.data_type) {
+ if (array_type.element_type.data_type != context.analyzer.string_type.data_type) {
// parameter must be an array of strings
return false;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!call.check (analyzer)) {
+ if (!call.check (context)) {
/* if method resolving didn't succeed, skip this check */
error = true;
return false;
var mtype = call.value_type;
- if (mtype is ObjectType || (analyzer.context.profile == Profile.GOBJECT && call.symbol_reference == analyzer.object_type)) {
+ if (mtype is ObjectType || (context.profile == Profile.GOBJECT && call.symbol_reference == context.analyzer.object_type)) {
// constructor chain-up
- var cm = analyzer.find_current_method () as CreationMethod;
+ var cm = context.analyzer.find_current_method () as CreationMethod;
if (cm == null) {
error = true;
Report.error (source_reference, "invocation not supported in this context");
} else {
// GObject chain up
var cl = cm.parent_symbol as Class;
- if (cl == null || !cl.is_subtype_of (analyzer.object_type)) {
+ if (cl == null || !cl.is_subtype_of (context.analyzer.object_type)) {
error = true;
Report.error (source_reference, "chain up to `GLib.Object' not supported");
return false;
}
- call.value_type = new ObjectType (analyzer.object_type);
+ call.value_type = new ObjectType (context.analyzer.object_type);
mtype = call.value_type;
}
}
}
if (is_chainup ()) {
- var cm = analyzer.find_current_method () as CreationMethod;
+ var cm = context.analyzer.find_current_method () as CreationMethod;
if (cm != null) {
if (cm.chain_up) {
error = true;
struct_creation_expression.add_argument (arg);
}
struct_creation_expression.target_type = target_type;
- analyzer.replaced_nodes.add (this);
+ context.analyzer.replaced_nodes.add (this);
parent_node.replace_expression (this, struct_creation_expression);
- struct_creation_expression.check (analyzer);
+ struct_creation_expression.check (context);
return true;
} else if (call is MemberAccess
&& call.symbol_reference is CreationMethod) {
// constructor chain-up
- var cm = analyzer.find_current_method () as CreationMethod;
+ var cm = context.analyzer.find_current_method () as CreationMethod;
if (cm == null) {
error = true;
Report.error (source_reference, "use `new' operator to create new objects");
if (format_literal == null && args.size == params.size - 1) {
// insert "%s" to avoid issues with embedded %
format_literal = new StringLiteral ("\"%s\"");
- format_literal.target_type = analyzer.string_type.copy ();
+ format_literal.target_type = context.analyzer.string_type.copy ();
argument_list.insert (args.size - 1, format_literal);
// recreate iterator and skip to right position
if (c == 'd' || c == 'i' || c == 'c') {
// integer
if (length == -2) {
- param_type = analyzer.int8_type;
+ param_type = context.analyzer.int8_type;
} else if (length == -1) {
- param_type = analyzer.short_type;
+ param_type = context.analyzer.short_type;
} else if (length == 0) {
- param_type = analyzer.int_type;
+ param_type = context.analyzer.int_type;
} else if (length == 1) {
- param_type = analyzer.long_type;
+ param_type = context.analyzer.long_type;
} else if (length == 2) {
- param_type = analyzer.ssize_t_type;
+ param_type = context.analyzer.ssize_t_type;
}
} else if (c == 'o' || c == 'u' || c == 'x' || c == 'X') {
// unsigned integer
if (length == -2) {
- param_type = analyzer.uchar_type;
+ param_type = context.analyzer.uchar_type;
} else if (length == -1) {
- param_type = analyzer.ushort_type;
+ param_type = context.analyzer.ushort_type;
} else if (length == 0) {
- param_type = analyzer.uint_type;
+ param_type = context.analyzer.uint_type;
} else if (length == 1) {
- param_type = analyzer.ulong_type;
+ param_type = context.analyzer.ulong_type;
} else if (length == 2) {
- param_type = analyzer.size_t_type;
+ param_type = context.analyzer.size_t_type;
}
} else if (c == 'e' || c == 'E' || c == 'f' || c == 'F'
|| c == 'g' || c == 'G' || c == 'a' || c == 'A') {
// double
- param_type = analyzer.double_type;
+ param_type = context.analyzer.double_type;
} else if (c == 's') {
// string
- param_type = analyzer.string_type;
+ param_type = context.analyzer.string_type;
} else if (c == 'p') {
// pointer
param_type = new PointerType (new VoidType ());
}
foreach (Expression arg in get_argument_list ()) {
- arg.check (analyzer);
+ arg.check (context);
}
if (ret_type is VoidType) {
error = true;
Report.error (source_reference, "yield expression requires async method");
}
- if (analyzer.current_method == null || !analyzer.current_method.coroutine) {
+ if (context.analyzer.current_method == null || !context.analyzer.current_method.coroutine) {
error = true;
Report.error (source_reference, "yield expression not available outside async method");
}
- analyzer.current_method.yield_count++;
+ context.analyzer.current_method.yield_count++;
}
if (m != null && m.coroutine && !is_yield_expression && ((MemberAccess) call).member_name != "end") {
// .begin call of async method, no error can happen here
}
}
- if (!analyzer.check_arguments (this, mtype, params, get_argument_list ())) {
+ if (!context.analyzer.check_arguments (this, mtype, params, get_argument_list ())) {
error = true;
return false;
}
if (may_throw) {
if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
// simple statements, no side effects after method call
- } else if (!(analyzer.current_symbol is Block)) {
- if (analyzer.context.profile != Profile.DOVA) {
+ } else if (!(context.analyzer.current_symbol is Block)) {
+ if (context.profile != Profile.DOVA) {
// can't handle errors in field initializers
Report.error (source_reference, "Field initializers must not throw errors");
}
local.floating = true;
var decl = new DeclarationStatement (local, source_reference);
- insert_statement (analyzer.insert_block, decl);
+ insert_statement (context.analyzer.insert_block, decl);
Expression temp_access = new MemberAccess.simple (local.name, source_reference);
temp_access.target_type = target_type;
// don't set initializer earlier as this changes parent_node and parent_statement
local.initializer = this;
- decl.check (analyzer);
- temp_access.check (analyzer);
+ decl.check (context);
+ temp_access.check (context);
// move temp variable to insert block to ensure the
// variable is in the same block as the declaration
// otherwise there will be scoping issues in the generated code
- var block = (Block) analyzer.current_symbol;
+ var block = (Block) context.analyzer.current_symbol;
block.remove_local_variable (local);
- analyzer.insert_block.add_local_variable (local);
+ context.analyzer.insert_block.add_local_variable (local);
old_parent_node.replace_expression (this, temp_access);
}
return inner.is_pure ();
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
inner.target_type = target_type;
- if (!inner.check (analyzer)) {
+ if (!inner.check (context)) {
error = true;
return false;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
foreach (Namespace ns in namespaces) {
- ns.check (analyzer);
+ ns.check (context);
}
return !error;
return true;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
if (member_name != null) {
- member_name.check (analyzer);
+ member_name.check (context);
}
TypeSymbol type = null;
if (symbol_reference != null && symbol_reference.access == SymbolAccessibility.PRIVATE) {
bool in_target_type = false;
- for (Symbol this_symbol = analyzer.current_symbol; this_symbol != null; this_symbol = this_symbol.parent_symbol) {
+ for (Symbol this_symbol = context.analyzer.current_symbol; this_symbol != null; this_symbol = this_symbol.parent_symbol) {
if (this_symbol == cl) {
in_target_type = true;
break;
expected_num_type_args = st.get_type_parameters ().size;
- if (!struct_creation && !analyzer.context.deprecated) {
+ if (!struct_creation && !context.deprecated) {
Report.warning (source_reference, "deprecated syntax, don't use `new' to initialize structs");
}
}
foreach (Expression arg in args) {
- arg.check (analyzer);
+ arg.check (context);
}
- analyzer.check_arguments (this, new MethodType (m), m.get_parameters (), args);
+ context.analyzer.check_arguments (this, new MethodType (m), m.get_parameters (), args);
foreach (DataType error_type in m.get_error_types ()) {
may_throw = true;
}
} else if (type_reference is ErrorType) {
if (type_reference != null) {
- type_reference.check (analyzer);
+ type_reference.check (context);
}
if (member_name != null) {
- member_name.check (analyzer);
+ member_name.check (context);
}
foreach (Expression arg in argument_list) {
- arg.check (analyzer);
+ arg.check (context);
}
foreach (MemberInitializer init in object_initializer) {
- init.check (analyzer);
+ init.check (context);
}
if (get_argument_list ().size == 0) {
Iterator<Expression> arg_it = get_argument_list ().iterator ();
arg_it.next ();
var ex = arg_it.get ();
- if (ex.value_type == null || !ex.value_type.compatible (analyzer.string_type)) {
+ if (ex.value_type == null || !ex.value_type.compatible (context.analyzer.string_type)) {
error = true;
Report.error (source_reference, "Invalid type for argument 1");
}
}
foreach (MemberInitializer init in get_object_initializer ()) {
- analyzer.visit_member_initializer (init, type_reference);
+ context.analyzer.visit_member_initializer (init, type_reference);
}
if (may_throw) {
if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
// simple statements, no side effects after method call
- } else if (!(analyzer.current_symbol is Block)) {
- if (analyzer.context.profile != Profile.DOVA) {
+ } else if (!(context.analyzer.current_symbol is Block)) {
+ if (context.profile != Profile.DOVA) {
// can't handle errors in field initializers
Report.error (source_reference, "Field initializers must not throw errors");
}
local.floating = true;
var decl = new DeclarationStatement (local, source_reference);
- insert_statement (analyzer.insert_block, decl);
+ insert_statement (context.analyzer.insert_block, decl);
Expression temp_access = new MemberAccess.simple (local.name, source_reference);
temp_access.target_type = target_type;
// don't set initializer earlier as this changes parent_node and parent_statement
local.initializer = this;
- decl.check (analyzer);
- temp_access.check (analyzer);
+ decl.check (context);
+ temp_access.check (context);
// move temp variable to insert block to ensure the
// variable is in the same block as the declaration
// otherwise there will be scoping issues in the generated code
- var block = (Block) analyzer.current_symbol;
+ var block = (Block) context.analyzer.current_symbol;
block.remove_local_variable (local);
- analyzer.insert_block.add_local_variable (local);
+ context.analyzer.insert_block.add_local_variable (local);
old_parent_node.replace_expression (this, temp_access);
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
- if (!type_symbol.check (analyzer)) {
+ public override bool check (CodeContext context) {
+ if (!type_symbol.check (context)) {
return false;
}
- if (analyzer.context.profile == Profile.DOVA && type_symbol.get_full_name () == "Dova.Tuple") {
+ if (context.profile == Profile.DOVA && type_symbol.get_full_name () == "Dova.Tuple") {
// tuples have variadic generics
return true;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = parent_symbol;
+ context.analyzer.current_symbol = parent_symbol;
if (variable_type != null) {
if (variable_type is VoidType) {
Report.error (source_reference, "'void' not supported as parameter type");
return false;
}
- variable_type.check (analyzer);
+ variable_type.check (context);
}
if (!ellipsis) {
- variable_type.check (analyzer);
+ variable_type.check (context);
if (params_array && !(variable_type is ArrayType)) {
error = true;
if (initializer != null) {
initializer.target_type = variable_type.copy ();
- initializer.check (analyzer);
+ initializer.check (context);
}
}
if (!ellipsis) {
// check whether parameter type is at least as accessible as the method
- if (!analyzer.is_type_accessible (this, variable_type)) {
+ if (!context.analyzer.is_type_accessible (this, variable_type)) {
error = true;
Report.error (source_reference, "parameter type `%s` is less accessible than method `%s`".printf (variable_type.to_string (), parent_symbol.get_full_name ()));
}
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
return !error;
}
return inner.is_pure ();
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!inner.check (analyzer)) {
+ if (!inner.check (context)) {
return false;
}
if (inner.value_type == null) {
return false;
}
- public override bool check (SemanticAnalyzer analyzer) {
- error = !base_type.check (analyzer);
+ public override bool check (CodeContext context) {
+ error = !base_type.check (context);
return !error;
}
}
return false;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!inner.check (analyzer)) {
+ if (!inner.check (context)) {
error = true;
return false;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
}
}
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
if (property_type is VoidType) {
error = true;
return false;
}
- property_type.check (analyzer);
+ property_type.check (context);
if (get_accessor != null) {
- get_accessor.check (analyzer);
+ get_accessor.check (context);
}
if (set_accessor != null) {
- set_accessor.check (analyzer);
+ set_accessor.check (context);
}
if (initializer != null) {
- initializer.check (analyzer);
+ initializer.check (context);
}
// check whether property type is at least as accessible as the property
- if (!analyzer.is_type_accessible (this, property_type)) {
+ if (!context.analyzer.is_type_accessible (this, property_type)) {
error = true;
Report.error (source_reference, "property type `%s` is less accessible than property `%s`".printf (property_type.to_string (), get_full_name ()));
}
Report.error (initializer.source_reference, "Expected initializer of type `%s' but got `%s'".printf (property_type.to_string (), initializer.value_type.to_string ()));
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
return !error;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
- if (!value_type.check (analyzer)) {
+ if (!value_type.check (context)) {
error = true;
return false;
}
- var old_symbol = analyzer.current_symbol;
+ var old_symbol = context.analyzer.current_symbol;
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
if (prop.source_type == SourceFileType.SOURCE) {
if (body == null && !prop.interface_only && !prop.is_abstract) {
body = new Block (source_reference);
var ma = new MemberAccess.simple ("_%s".printf (prop.name), source_reference);
if (readable) {
- if (analyzer.context.profile == Profile.DOVA) {
+ if (context.profile == Profile.DOVA) {
body.add_statement (new ExpressionStatement (new Assignment (new MemberAccess.simple ("result", source_reference), ma, AssignmentOperator.SIMPLE, source_reference), source_reference));
body.add_statement (new ReturnStatement (null, source_reference));
} else {
}
if (body != null) {
- if (readable && analyzer.context.profile == Profile.DOVA) {
+ if (readable && context.profile == Profile.DOVA) {
result_var = new LocalVariable (value_type.copy (), "result", null, source_reference);
result_var.is_result = true;
- result_var.check (analyzer);
+ result_var.check (context);
} else if (writable || construction) {
value_parameter = new Parameter ("value", value_type, source_reference);
body.scope.add (value_parameter.name, value_parameter);
}
- body.check (analyzer);
+ body.check (context);
- if (analyzer.context.profile != Profile.DOVA) {
+ if (context.profile != Profile.DOVA) {
foreach (DataType body_error_type in body.get_error_types ()) {
if (!((ErrorType) body_error_type).dynamic_error) {
Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string()));
}
}
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_symbol = old_symbol;
return !error;
}
return value;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- var st = (Struct) analyzer.root_symbol.scope.lookup (get_type_name ());
+ var st = (Struct) context.analyzer.root_symbol.scope.lookup (get_type_name ());
// ensure attributes are already processed in case of bootstrapping dova-core
- st.check (analyzer);
+ st.check (context);
value_type = new FloatingType (st);
return false;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
inner.lvalue = true;
- inner.check (analyzer);
+ inner.check (context);
if (inner.error) {
/* if there was an error in the inner expression, skip type check */
return value;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!analyzer.context.experimental) {
+ if (!context.experimental) {
Report.warning (source_reference, "regular expression literals are experimental");
}
return false;
}
- value_type = analyzer.regex_type.copy ();
+ value_type = context.analyzer.regex_type.copy ();
return !error;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
if (return_expression != null) {
- return_expression.target_type = analyzer.current_return_type;
+ return_expression.target_type = context.analyzer.current_return_type;
}
- if (return_expression != null && !return_expression.check (analyzer)) {
+ if (return_expression != null && !return_expression.check (context)) {
// ignore inner error
error = true;
return false;
}
- if (analyzer.current_return_type == null) {
+ if (context.analyzer.current_return_type == null) {
error = true;
Report.error (source_reference, "Return not allowed in this context");
return false;
}
- if (analyzer.context.profile == Profile.DOVA) {
+ if (context.profile == Profile.DOVA) {
// no return expressions in Dova profile
return !error;
}
if (return_expression == null) {
- if (!(analyzer.current_return_type is VoidType)) {
+ if (!(context.analyzer.current_return_type is VoidType)) {
error = true;
Report.error (source_reference, "Return without value in non-void function");
}
return !error;
}
- if (analyzer.current_return_type is VoidType) {
+ if (context.analyzer.current_return_type is VoidType) {
Report.error (source_reference, "Return with value in void function");
return false;
}
return false;
}
- if (!return_expression.value_type.compatible (analyzer.current_return_type)) {
+ if (!return_expression.value_type.compatible (context.analyzer.current_return_type)) {
error = true;
- Report.error (source_reference, "Return: Cannot convert from `%s' to `%s'".printf (return_expression.value_type.to_string (), analyzer.current_return_type.to_string ()));
+ Report.error (source_reference, "Return: Cannot convert from `%s' to `%s'".printf (return_expression.value_type.to_string (), context.analyzer.current_return_type.to_string ()));
return false;
}
if (return_expression.value_type.is_disposable () &&
- !analyzer.current_return_type.value_owned) {
+ !context.analyzer.current_return_type.value_owned) {
error = true;
Report.error (source_reference, "Return value transfers ownership but method return type hasn't been declared to transfer ownership");
return false;
var local = return_expression.symbol_reference as LocalVariable;
if (local != null && local.variable_type.is_disposable () &&
- !analyzer.current_return_type.value_owned) {
+ !context.analyzer.current_return_type.value_owned) {
error = true;
Report.error (source_reference, "Local variable with strong reference used as return value and method return type has not been declared to transfer ownership");
return false;
}
if (return_expression is NullLiteral
- && !analyzer.current_return_type.nullable) {
- Report.warning (source_reference, "`null' incompatible with return type `%s`".printf (analyzer.current_return_type.to_string ()));
+ && !context.analyzer.current_return_type.nullable) {
+ Report.warning (source_reference, "`null' incompatible with return type `%s`".printf (context.analyzer.current_return_type.to_string ()));
}
add_error_types (return_expression.get_error_types ());
}
current_symbol = root_symbol;
- context.root.check (this);
+ context.root.check (context);
context.accept (this);
}
public override void visit_source_file (SourceFile file) {
current_source_file = file;
- file.check (this);
+ file.check (context);
}
// check whether type is at least as accessible as the specified symbol
bool ellipsis = false;
int i = 0;
foreach (Parameter param in params) {
- if (!param.check (this)) {
+ if (!param.check (context)) {
return false;
}
init.initializer.formal_target_type = member_type;
init.initializer.target_type = init.initializer.formal_target_type.get_actual_type (type, null, init);;
- init.check (this);
+ init.check (context);
if (init.initializer.value_type == null || !init.initializer.value_type.compatible (init.initializer.target_type)) {
init.error = true;
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- var set_type = new ObjectType ((Class) analyzer.context.root.scope.lookup ("Dova").scope.lookup ("Set"));
+ var set_type = new ObjectType ((Class) context.root.scope.lookup ("Dova").scope.lookup ("Set"));
set_type.value_owned = true;
bool fixed_element_type = false;
if (fixed_element_type) {
expr.target_type = element_type;
}
- if (!expr.check (analyzer)) {
+ if (!expr.check (context)) {
return false;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
- return_type.check (analyzer);
+ return_type.check (context);
foreach (Parameter param in parameters) {
- param.check (analyzer);
+ param.check (context);
}
if (!is_virtual && body != null) {
var cl = parent_symbol as ObjectTypeSymbol;
cl.add_hidden_method (default_handler);
- default_handler.check (analyzer);
+ default_handler.check (context);
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- type_reference.check (analyzer);
+ type_reference.check (context);
- value_type = analyzer.ulong_type;
+ value_type = context.analyzer.ulong_type;
return !error;
}
return false;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!container.check (analyzer)) {
+ if (!container.check (context)) {
error = true;
return false;
}
- if (!start.check (analyzer)) {
+ if (!start.check (context)) {
error = true;
return false;
}
- if (!stop.check (analyzer)) {
+ if (!stop.check (context)) {
error = true;
return false;
}
slice_call.add_argument (stop);
slice_call.target_type = this.target_type;
parent_node.replace_expression (this, slice_call);
- return slice_call.check (analyzer);
+ return slice_call.check (context);
}
error = true;
return mapped_file.get_length ();
}
- public bool check (SemanticAnalyzer analyzer) {
+ public bool check (CodeContext context) {
foreach (CodeNode node in nodes) {
- node.check (analyzer);
+ node.check (context);
}
return true;
}
return value;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- value_type = analyzer.string_type.copy ();
+ value_type = context.analyzer.string_type.copy ();
return !error;
}
return false;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
process_attributes ();
- var old_source_file = analyzer.current_source_file;
- var old_symbol = analyzer.current_symbol;
+ var old_source_file = context.analyzer.current_source_file;
+ var old_symbol = context.analyzer.current_symbol;
if (source_reference != null) {
- analyzer.current_source_file = source_reference.file;
+ context.analyzer.current_source_file = source_reference.file;
}
- analyzer.current_symbol = this;
+ context.analyzer.current_symbol = this;
if (base_type != null) {
- base_type.check (analyzer);
+ base_type.check (context);
if (!(base_type is ValueType)) {
error = true;
}
foreach (TypeParameter p in type_parameters) {
- p.check (analyzer);
+ p.check (context);
}
foreach (Field f in fields) {
- f.check (analyzer);
+ f.check (context);
if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (f.variable_type)) {
error = true;
}
foreach (Constant c in constants) {
- c.check (analyzer);
+ c.check (context);
}
foreach (Method m in methods) {
- m.check (analyzer);
+ m.check (context);
}
foreach (Property prop in properties) {
- prop.check (analyzer);
+ prop.check (context);
}
if (!external && !external_package) {
}
}
- analyzer.current_source_file = old_source_file;
- analyzer.current_symbol = old_symbol;
+ context.analyzer.current_source_file = old_source_file;
+ context.analyzer.current_symbol = old_symbol;
return !error;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (expression != null) {
- expression.check (analyzer);
+ expression.check (context);
var switch_statement = (SwitchStatement) section.parent_node;
if (!expression.is_constant ()) {
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
foreach (SwitchLabel label in get_labels ()) {
- label.check (analyzer);
+ label.check (context);
}
- owner = analyzer.current_symbol.scope;
+ owner = context.analyzer.current_symbol.scope;
- var old_symbol = analyzer.current_symbol;
- var old_insert_block = analyzer.insert_block;
- analyzer.current_symbol = this;
- analyzer.insert_block = this;
+ var old_symbol = context.analyzer.current_symbol;
+ var old_insert_block = context.analyzer.insert_block;
+ context.analyzer.current_symbol = this;
+ context.analyzer.insert_block = this;
foreach (Statement st in get_statements ()) {
- st.check (analyzer);
+ st.check (context);
}
foreach (LocalVariable local in get_local_variables ()) {
add_error_types (stmt.get_error_types ());
}
- analyzer.current_symbol = old_symbol;
- analyzer.insert_block = old_insert_block;
+ context.analyzer.current_symbol = old_symbol;
+ context.analyzer.insert_block = old_insert_block;
return !error;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (!expression.check (analyzer)) {
+ if (!expression.check (context)) {
error = true;
return false;
}
if (expression.value_type == null ||
(!(expression.value_type is IntegerType) &&
!(expression.value_type is EnumValueType) &&
- !expression.value_type.compatible (analyzer.string_type))) {
+ !expression.value_type.compatible (context.analyzer.string_type))) {
Report.error (expression.source_reference, "Integer or string expression expected");
error = true;
return false;
var labelset = new HashSet<string> (str_hash, str_equal);
foreach (SwitchSection section in sections) {
- section.check (analyzer);
+ section.check (context);
// check for duplicate literal case labels
// FIXME: make it work for all constant expressions
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
} else {
expr = stringify (expression_list[0]);
if (expression_list.size > 1) {
- if (analyzer.context.profile == Profile.DOVA) {
+ if (context.profile == Profile.DOVA) {
// varargs concat not yet supported
for (int i = 1; i < expression_list.size; i++) {
expr = new BinaryExpression (BinaryOperator.PLUS, expr, stringify (expression_list[i]), source_reference);
}
expr.target_type = target_type;
- analyzer.replaced_nodes.add (this);
+ context.analyzer.replaced_nodes.add (this);
parent_node.replace_expression (this, expr);
- return expr.check (analyzer);
+ return expr.check (context);
}
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (analyzer.context.profile == Profile.GOBJECT) {
+ if (context.profile == Profile.GOBJECT) {
error_expression.target_type = new ErrorType (null, null, source_reference);
} else {
- error_expression.target_type = analyzer.error_type.copy ();
+ error_expression.target_type = context.analyzer.error_type.copy ();
}
error_expression.target_type.value_owned = true;
if (error_expression != null) {
- if (!error_expression.check (analyzer)) {
+ if (!error_expression.check (context)) {
error = true;
return false;
}
return false;
}
- if (analyzer.context.profile == Profile.GOBJECT && !(error_expression.value_type is ErrorType)) {
+ if (context.profile == Profile.GOBJECT && !(error_expression.value_type is ErrorType)) {
Report.error (error_expression.source_reference, "`%s' is not an error type".printf (error_expression.value_type.to_string ()));
error = true;
return false;
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- body.check (analyzer);
+ body.check (context);
var error_types = new ArrayList<DataType> ();
foreach (DataType body_error_type in body.get_error_types ()) {
}
handled_error_types.clear ();
- clause.check (analyzer);
+ clause.check (context);
foreach (DataType body_error_type in clause.body.get_error_types ()) {
error_types.add (body_error_type);
}
}
if (finally_body != null) {
- finally_body.check (analyzer);
+ finally_body.check (context);
foreach (DataType body_error_type in finally_body.get_error_types ()) {
error_types.add (body_error_type);
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- if (analyzer.context.profile != Profile.DOVA) {
+ if (context.profile != Profile.DOVA) {
Report.error (source_reference, "tuples are not supported");
error = true;
return false;
}
- value_type = new ObjectType ((Class) analyzer.context.root.scope.lookup ("Dova").scope.lookup ("Tuple"));
+ value_type = new ObjectType ((Class) context.root.scope.lookup ("Dova").scope.lookup ("Tuple"));
value_type.value_owned = true;
foreach (var expr in expression_list) {
- if (!expr.check (analyzer)) {
+ if (!expr.check (context)) {
return false;
}
value_type.add_type_argument (expr.value_type.copy ());
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- expression.check (analyzer);
+ expression.check (context);
- type_reference.check (analyzer);
+ type_reference.check (context);
if (type_reference.data_type == null) {
/* if type resolving didn't succeed, skip this check */
return false;
}
- value_type = analyzer.bool_type;
+ value_type = context.analyzer.bool_type;
return !error;
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- type_reference.check (analyzer);
+ type_reference.check (context);
- value_type = analyzer.type_type;
+ value_type = context.analyzer.type_type;
return !error;
}
return null;
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
inner.target_type = target_type;
}
- if (!inner.check (analyzer)) {
+ if (!inner.check (context)) {
/* if there was an error in the inner expression, skip type check */
error = true;
return false;
value_type = inner.value_type;
} else if (operator == UnaryOperator.LOGICAL_NEGATION) {
// boolean type
- if (!inner.value_type.compatible (analyzer.bool_type)) {
+ if (!inner.value_type.compatible (context.analyzer.bool_type)) {
error = true;
Report.error (source_reference, "Operator not supported for `%s'".printf (inner.value_type.to_string ()));
return false;
var assignment = new Assignment (ma, bin, AssignmentOperator.SIMPLE, source_reference);
assignment.target_type = target_type;
- analyzer.replaced_nodes.add (this);
+ context.analyzer.replaced_nodes.add (this);
parent_node.replace_expression (this, assignment);
- assignment.check (analyzer);
+ assignment.check (context);
return true;
} else if (operator == UnaryOperator.REF || operator == UnaryOperator.OUT) {
var ea = inner as ElementAccess;
visitor.visit_unlock_statement (this);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (checked) {
return !error;
}
checked = true;
- resource.check (analyzer);
+ resource.check (context);
/* resource must be a member access and denote a Lockable */
if (!(resource is MemberAccess && resource.symbol_reference is Lockable)) {
}
/* parent symbol must be the current class */
- if (resource.symbol_reference.parent_symbol != analyzer.current_class) {
+ if (resource.symbol_reference.parent_symbol != context.analyzer.current_class) {
error = true;
resource.error = true;
Report.error (resource.source_reference, "Only members of the current class are lockable");
return false;
}
- public override bool check (SemanticAnalyzer analyzer) {
- return type_symbol.check (analyzer);
+ public override bool check (CodeContext context) {
+ return type_symbol.check (context);
}
}
return (literal != null && !literal.value);
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
// convert to simple loop
if (always_true (condition)) {
var parent_block = (Block) parent_node;
parent_block.replace_statement (this, loop);
- return loop.check (analyzer);
+ return loop.check (context);
}
}
}
}
- public override bool check (SemanticAnalyzer analyzer) {
+ public override bool check (CodeContext context) {
if (yield_expression != null) {
- yield_expression.check (analyzer);
+ yield_expression.check (context);
error = yield_expression.error;
}
- analyzer.current_method.yield_count++;
+ context.analyzer.current_method.yield_count++;
return !error;
}