error = true;
return false;
}
- var ea = inner as ElementAccess;
+
+ unowned ElementAccess? ea = inner as ElementAccess;
if (inner is MemberAccess && inner.symbol_reference is Variable) {
// address of variable is always possible
} else if (ea != null &&
return true;
}
- var target_array_type = target_type as ArrayType;
+ unowned ArrayType? target_array_type = target_type as ArrayType;
if (target_array_type == null) {
return false;
}
}
public override DataType? infer_type_argument (TypeParameter type_param, DataType value_type) {
- var array_type = value_type as ArrayType;
+ unowned ArrayType? array_type = value_type as ArrayType;
if (array_type != null) {
return element_type.infer_type_argument (type_param, array_type.element_type);
}
} else if (left.value_type is ArrayType && operator == BinaryOperator.PLUS) {
// array concatenation
- var array_type = (ArrayType) left.value_type;
+ unowned ArrayType array_type = (ArrayType) left.value_type;
if (right.value_type == null || !right.value_type.compatible (array_type.element_type)) {
error = true;
|| operator == BinaryOperator.DIV) {
// check for pointer arithmetic
if (left.value_type is PointerType) {
- var pointer_type = (PointerType) left.value_type;
+ unowned PointerType pointer_type = (PointerType) left.value_type;
if (pointer_type.base_type is VoidType) {
error = true;
Report.error (source_reference, "Pointer arithmetic not supported for `void*'");
return false;
}
- var offset_type = right.value_type.type_symbol as Struct;
+ unowned Struct? offset_type = right.value_type.type_symbol as Struct;
if (offset_type != null && offset_type.is_integer_type ()) {
if (operator == BinaryOperator.PLUS
|| operator == BinaryOperator.MINUS) {
public List<Statement> get_statements () {
var list = new ArrayList<Statement> ();
foreach (Statement stmt in statement_list) {
- var stmt_list = stmt as StatementList;
+ unowned StatementList? stmt_list = stmt as StatementList;
if (stmt_list != null) {
for (int i = 0; i < stmt_list.length; i++) {
list.add (stmt_list.get (i));
* @param local a variable declarator
*/
public void add_local_variable (LocalVariable local) {
- var parent_block = parent_symbol;
+ unowned Symbol? parent_block = parent_symbol;
while (parent_block is Block || parent_block is Method || parent_block is PropertyAccessor) {
if (parent_block.scope.lookup (local.name) != null) {
Report.error (local.source_reference, "Local variable `%s' conflicts with a local variable or constant declared in a parent scope".printf (local.name));
}
public void add_local_constant (Constant constant) {
- var parent_block = parent_symbol;
+ unowned Symbol? parent_block = parent_symbol;
while (parent_block is Block || parent_block is Method || parent_block is PropertyAccessor) {
if (parent_block.scope.lookup (constant.name) != null) {
Report.error (constant.source_reference, "Local constant `%s' conflicts with a local variable or constant declared in a parent scope".printf (constant.name));
StringBuilder builder = new StringBuilder ();
// Append return-type
- var return_type = get_return_type ();
+ unowned DataType return_type = get_return_type ();
if (return_type.is_weak ()) {
builder.append ("unowned ");
}
builder.append_c ('(');
int i = 1;
// add sender parameter for internal signal-delegates
- var delegate_type = this as DelegateType;
+ unowned DelegateType? delegate_type = this as DelegateType;
if (delegate_type != null) {
- var delegate_symbol = delegate_type.delegate_symbol;
+ unowned Delegate delegate_symbol = delegate_type.delegate_symbol;
if (delegate_symbol.parent_symbol is Signal && delegate_symbol.sender_type != null) {
builder.append (delegate_symbol.sender_type.to_qualified_string ());
i++;
m.name = ".new";
}
- var cm = (CreationMethod) m;
+ unowned CreationMethod cm = (CreationMethod) m;
if (cm.class_name != null && cm.class_name != name) {
// class_name is null for constructors generated by GIdlParser
Report.error (m.source_reference, "missing return type in method `%s.%s´".printf (get_full_name (), cm.class_name));
/* all abstract symbols defined in base types have to be at least defined (or implemented) also in this type */
foreach (DataType base_type in get_base_types ()) {
if (base_type.type_symbol is Interface) {
- Interface iface = (Interface) base_type.type_symbol;
+ unowned Interface iface = (Interface) base_type.type_symbol;
if (base_class != null && base_class.is_subtype_of (iface)) {
// reimplementation of interface, class is not required to reimplement all methods
foreach (Method m in iface.get_methods ()) {
if (m.is_abstract) {
var implemented = false;
- var base_class = this;
+ unowned Class? base_class = this;
while (base_class != null && !implemented) {
foreach (var impl in base_class.get_methods ()) {
if (impl.base_interface_method == m || (base_class != this
foreach (Property prop in iface.get_properties ()) {
if (prop.is_abstract) {
Symbol sym = null;
- var base_class = this;
+ unowned Class? base_class = this;
while (base_class != null && !(sym is Property)) {
sym = base_class.scope.lookup (prop.name);
base_class = base_class.base_class;
/* all abstract symbols defined in base classes have to be implemented in non-abstract classes */
if (!is_abstract) {
- var base_class = base_class;
+ unowned Class? base_class = base_class;
while (base_class != null && base_class.is_abstract) {
foreach (Method base_method in base_class.get_methods ()) {
if (base_method.is_abstract) {
}
private void write_type_suffix (DataType type) {
- var array_type = type as ArrayType;
+ unowned ArrayType? array_type = type as ArrayType;
if (array_type != null && array_type.fixed_length) {
write_string ("[");
array_type.length.accept (this);
}
private void write_attributes (CodeNode node) {
- var sym = node as Symbol;
+ unowned Symbol? sym = node as Symbol;
var need_cheaders = type != CodeWriterType.FAST && sym != null && !(sym is Namespace) && sym.parent_symbol is Namespace;
// support translated string constants for efficiency / convenience
// even though the expression is not a compile-time constant
- var call = value as MethodCall;
+ unowned MethodCall? call = value as MethodCall;
if (call != null) {
- var method_type = call.call.value_type as MethodType;
+ unowned MethodType? method_type = call.call.value_type as MethodType;
if (method_type != null && method_type.method_symbol.get_full_name () == "GLib._") {
// first argument is string
var literal = call.get_argument_list ().get (0) as StringLiteral;
if (type is ValueType) {
return true;
} else if (type is ArrayType) {
- var array_type = type as ArrayType;
+ unowned ArrayType array_type = (ArrayType) type;
return check_const_type (array_type.element_type, context);
} else if (type.type_symbol.is_subtype_of (context.analyzer.string_type.type_symbol)) {
return true;
if (body != null) {
body.check (context);
- var cl = parent_symbol as Class;
+ unowned Class? cl = parent_symbol as Class;
// ensure we chain up to base constructor
if (!chain_up && cl != null && cl.base_class != null) {
}
if (type_symbol is Struct && target_type.type_symbol is Struct) {
- var expr_struct = (Struct) type_symbol;
- var expect_struct = (Struct) target_type.type_symbol;
+ unowned Struct expr_struct = (Struct) type_symbol;
+ unowned Struct expect_struct = (Struct) target_type.type_symbol;
/* integer types may be implicitly cast to floating point types */
if (expr_struct.is_integer_type () && expect_struct.is_floating_type ()) {
}
return string.nfill (array_type.rank, 'a') + element_type_signature;
- } else if (type_symbol != null && type_symbol is Enum && type_symbol.get_attribute_bool ("DBus", "use_string_marshalling")) {
+ } else if (type_symbol is Enum && type_symbol.get_attribute_bool ("DBus", "use_string_marshalling")) {
return "s";
} else if (type_symbol != null) {
string sig = type_symbol.get_attribute_string ("CCode", "type_signature");
if (source_reference == null) {
source_reference = this.source_reference;
}
- var local = declaration as LocalVariable;
+ unowned LocalVariable? local = declaration as LocalVariable;
if (local != null && local.initializer != null) {
local.initializer.get_error_types (collection, source_reference);
}
}
public override void get_defined_variables (Collection<Variable> collection) {
- var local = declaration as LocalVariable;
+ unowned LocalVariable? local = declaration as LocalVariable;
if (local != null) {
- var array_type = local.variable_type as ArrayType;
+ unowned ArrayType? array_type = local.variable_type as ArrayType;
if (local.initializer != null) {
local.initializer.get_defined_variables (collection);
collection.add (local);
}
public override void get_used_variables (Collection<Variable> collection) {
- var local = declaration as LocalVariable;
+ unowned LocalVariable? local = declaration as LocalVariable;
if (local != null && local.initializer != null) {
local.initializer.get_used_variables (collection);
}
}
public override bool compatible (DataType target_type) {
- var dt_target = target_type as DelegateType;
+ unowned DelegateType? dt_target = target_type as DelegateType;
if (dt_target == null) {
return false;
}
}
bool always_true (Expression condition) {
- var literal = condition as BooleanLiteral;
+ unowned BooleanLiteral? literal = condition as BooleanLiteral;
return (literal != null && literal.value);
}
if (always_true (condition)) {
var loop = new Loop (body, source_reference);
- var parent_block = (Block) parent_node;
+ unowned Block parent_block = (Block) parent_node;
parent_block.replace_statement (this, loop);
if (!loop.check (context)) {
block.add_statement (new Loop (body, source_reference));
- var parent_block = (Block) parent_node;
+ unowned Block parent_block = (Block) parent_node;
parent_block.replace_statement (this, block);
if (!block.check (context)) {
bool index_int_type_check = true;
- var pointer_type = container.value_type as PointerType;
+ unowned PointerType? pointer_type = container.value_type as PointerType;
/* assign a value_type when possible */
if (container.value_type is ArrayType) {
- var array_type = (ArrayType) container.value_type;
+ unowned ArrayType array_type = (ArrayType) container.value_type;
value_type = array_type.element_type.copy ();
if (!lvalue) {
value_type.value_owned = false;
} else {
- var ma = container as MemberAccess;
+ unowned MemberAccess? ma = container as MemberAccess;
if (context.profile == Profile.GOBJECT && ma != null && ma.symbol_reference is ArrayLengthField) {
// propagate lvalue for gobject length access
ma.inner.lvalue = true;
} else {
if (lvalue) {
var set_method = container.value_type.get_member ("set") as Method;
- var assignment = parent_node as Assignment;
+ unowned Assignment? assignment = parent_node as Assignment;
if (set_method != null && set_method.return_type is VoidType && assignment != null) {
return !error;
}
return true;
}
- var et = target_type as ErrorType;
+ unowned ErrorType? et = target_type as ErrorType;
/* error types are only compatible to error types */
if (et == null) {
}
public override bool equals (DataType type2) {
- var et = type2 as ErrorType;
+ unowned ErrorType? et = type2 as ErrorType;
if (et == null) {
return false;
public Statement? parent_statement {
get {
- var expr = parent_node as Expression;
- var stmt = parent_node as Statement;
- var local = parent_node as LocalVariable;
- var initializer = parent_node as MemberInitializer;
+ unowned Expression? expr = parent_node as Expression;
+ unowned Statement? stmt = parent_node as Statement;
+ unowned LocalVariable? local = parent_node as LocalVariable;
+ unowned MemberInitializer? initializer = parent_node as MemberInitializer;
if (stmt != null) {
return (Statement) parent_node;
} else if (expr != null) {
current_block.add_node (stmt);
- var local = stmt.declaration as LocalVariable;
+ unowned LocalVariable? local = stmt.declaration as LocalVariable;
if (local != null && local.initializer != null) {
handle_errors (local.initializer);
}
handle_errors (stmt);
if (stmt.expression is MethodCall) {
- var expr = (MethodCall) stmt.expression;
- var ma = expr.call as MemberAccess;
+ unowned MethodCall expr = (MethodCall) stmt.expression;
+ unowned MemberAccess? ma = expr.call as MemberAccess;
if (ma != null && ma.symbol_reference != null && ma.symbol_reference.get_attribute ("NoReturn") != null) {
mark_unreachable ();
return;
}
bool always_true (Expression condition) {
- var literal = condition as BooleanLiteral;
+ unowned BooleanLiteral? literal = condition as BooleanLiteral;
return (literal != null && literal.value);
}
bool always_false (Expression condition) {
- var literal = condition as BooleanLiteral;
+ unowned BooleanLiteral? literal = condition as BooleanLiteral;
return (literal != null && !literal.value);
}
var error_types = new ArrayList<DataType> ();
node.get_error_types (error_types);
foreach (DataType error_data_type in error_types) {
- var error_type = error_data_type as ErrorType;
- var error_class = error_data_type.type_symbol as Class;
+ unowned ErrorType? error_type = error_data_type as ErrorType;
+ unowned Class? error_class = error_data_type.type_symbol as Class;
current_block = last_block;
unreachable_reported = true;
if (catch_clause.error_type != null) {
if (context.profile == Profile.GOBJECT) {
- var error_type = (ErrorType) catch_clause.error_type;
+ unowned ErrorType error_type = (ErrorType) catch_clause.error_type;
jump_stack.add (new JumpTarget.error_target (error_block, catch_clause, catch_clause.error_type.type_symbol as ErrorDomain, error_type.error_code, null));
} else {
- var error_class = catch_clause.error_type.type_symbol as Class;
+ unowned Class? error_class = catch_clause.error_type.type_symbol as Class;
jump_stack.add (new JumpTarget.error_target (error_block, catch_clause, null, null, error_class));
}
} else {
}
bool always_true (Expression condition) {
- var literal = condition as BooleanLiteral;
+ unowned BooleanLiteral? literal = condition as BooleanLiteral;
return (literal != null && literal.value);
}
bool always_false (Expression condition) {
- var literal = condition as BooleanLiteral;
+ unowned BooleanLiteral? literal = condition as BooleanLiteral;
return (literal != null && !literal.value);
}
block.add_statement (new Loop (body, source_reference));
- var parent_block = (Block) parent_node;
+ unowned Block parent_block = (Block) parent_node;
parent_block.replace_statement (this, block);
if (!block.check (context)) {
var expr = parse_expression ();
- var call = expr as MethodCall;
- var object_creation = expr as ObjectCreationExpression;
+ unowned MethodCall? call = expr as MethodCall;
+ unowned ObjectCreationExpression? object_creation = expr as ObjectCreationExpression;
if (call == null && object_creation == null) {
Report.error (expr.source_reference, "syntax error, expected method call");
throw new ParseError.SYNTAX ("expected method call");
expect_terminator ();
// constant arrays don't own their element
- var array_type = type as ArrayType;
+ unowned ArrayType? array_type = type as ArrayType;
if (array_type != null) {
array_type.element_type.value_owned = false;
}
return false;
} else if (target_type is ArrayType) {
/* initializer is used as array initializer */
- var array_type = (ArrayType) target_type;
+ unowned ArrayType array_type = (ArrayType) target_type;
bool requires_constants_only = false;
unowned CodeNode? node = parent_node;
}
} else if (target_type.type_symbol is Struct) {
/* initializer is used as struct initializer */
- var st = (Struct) target_type.type_symbol;
+ unowned Struct st = (Struct) target_type.type_symbol;
while (st.base_struct != null) {
st = st.base_struct;
}
continue;
}
- var unary = e as UnaryExpression;
+ unowned UnaryExpression? unary = e as UnaryExpression;
if (unary != null && (unary.operator == UnaryOperator.REF || unary.operator == UnaryOperator.OUT)) {
// TODO check type for ref and out expressions
} else if (!e.value_type.compatible (e.target_type)) {
// local reference variables are considered nullable
// except when using experimental non-null enhancements
if (variable_type is ReferenceType) {
- var array_type = variable_type as ArrayType;
+ unowned ArrayType? array_type = variable_type as ArrayType;
if (array_type != null && array_type.fixed_length) {
// local fixed length arrays are not nullable
} else {
// current_symbol is a Method if this is the `result'
// variable used for postconditions
- var block = context.analyzer.current_symbol as Block;
+ unowned Block? block = context.analyzer.current_symbol as Block;
if (block != null) {
block.add_local_variable (this);
}
private void find_base_class_method (Class cl) {
var sym = cl.scope.lookup (name);
if (sym is Signal) {
- var sig = (Signal) sym;
+ unowned Signal sig = (Signal) sym;
sym = sig.default_handler;
}
if (sym is Method) {
- var base_method = (Method) sym;
+ unowned Method base_method = (Method) sym;
if (base_method.is_abstract || base_method.is_virtual) {
string invalid_match;
if (!compatible (base_method, out invalid_match)) {
var sym = type.type_symbol.scope.lookup (name);
if (sym is Signal) {
- var sig = (Signal) sym;
+ unowned Signal sig = (Signal) sym;
sym = sig.default_handler;
}
if (sym is Method) {
- var base_method = (Method) sym;
+ unowned Method base_method = (Method) sym;
if (base_method.is_abstract || base_method.is_virtual) {
if (base_interface_type == null) {
// check for existing explicit implementation
}
if (parent_symbol is Class && (is_abstract || is_virtual)) {
- var cl = (Class) parent_symbol;
+ unowned Class cl = (Class) parent_symbol;
if (cl.is_compact && cl.base_class != null) {
error = true;
Report.error (source_reference, "Abstract and virtual methods may not be declared in derived compact classes");
if (is_abstract) {
if (parent_symbol is Class) {
- var cl = (Class) parent_symbol;
+ unowned Class cl = (Class) parent_symbol;
if (!cl.is_abstract) {
error = true;
Report.error (source_reference, "Abstract methods may not be declared in non-abstract classes");
if (error_types != null) {
foreach (DataType error_type in error_types) {
- error_type.check (context);
+ error_type.check (context);
- // check whether error type is at least as accessible as the method
- 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;
+ // check whether error type is at least as accessible as the method
+ 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 (context);
}
if (base_interface_type != null && base_interface_method != null && parent_symbol is Class) {
- var cl = (Class) parent_symbol;
+ unowned Class cl = (Class) parent_symbol;
foreach (var m in cl.get_methods ()) {
if (m != this && m.base_interface_method == base_interface_method) {
m.checked = true;
return false;
}
- var array_type = (ArrayType) param.variable_type;
+ unowned ArrayType array_type = (ArrayType) param.variable_type;
if (array_type.element_type.type_symbol != context.analyzer.string_type.type_symbol) {
// parameter must be an array of strings
return false;
}
public override bool compatible (DataType target_type) {
- var dt = target_type as DelegateType;
+ unowned DelegateType? dt = target_type as DelegateType;
if (dt == null) {
// method types incompatible to anything but delegates
return false;
symbol_reference = constructor;
// inner expression can also be base access when chaining constructors
- var ma = member_name.inner as MemberAccess;
+ unowned MemberAccess? ma = member_name.inner as MemberAccess;
if (ma != null) {
type_args = ma.get_type_arguments ();
}
}
public override bool stricter (DataType target_type) {
- var obj_target_type = target_type as ObjectType;
+ unowned ObjectType? obj_target_type = target_type as ObjectType;
if (obj_target_type == null) {
return false;
}
}
public override bool is_invokable () {
- var cl = type_symbol as Class;
+ unowned Class? cl = type_symbol as Class;
if (cl != null && cl.default_construction_method != null) {
return true;
} else {
}
public override unowned DataType? get_return_type () {
- var cl = type_symbol as Class;
+ unowned Class? cl = type_symbol as Class;
if (cl != null && cl.default_construction_method != null) {
return cl.default_construction_method.return_type;
} else {
}
public override unowned List<Parameter>? get_parameters () {
- var cl = type_symbol as Class;
+ unowned Class? cl = type_symbol as Class;
if (cl != null && cl.default_construction_method != null) {
return cl.default_construction_method.get_parameters ();
} else {
}
}
- var m = parent_symbol as Method;
+ unowned Method? m = parent_symbol as Method;
if (m != null) {
- Method base_method = m.base_method != null ? m.base_method : m.base_interface_method;
+ unowned Method? base_method = m.base_method != null ? m.base_method : m.base_interface_method;
if (base_method != null && base_method != m) {
int index = m.get_parameters ().index_of (this);
if (index >= 0) {
if (init_list.size > 0 && inner is MemberAccess) {
// struct creation expression
- var member = (MemberAccess) inner;
+ unowned MemberAccess member = (MemberAccess) inner;
member.creation_member = true;
var expr = new ObjectCreationExpression (member, src);
var expr = parse_expression ();
- var call = expr as MethodCall;
- var object_creation = expr as ObjectCreationExpression;
+ unowned MethodCall? call = expr as MethodCall;
+ unowned ObjectCreationExpression? object_creation = expr as ObjectCreationExpression;
if (call == null && object_creation == null) {
Report.error (expr.source_reference, "syntax error, expected method call");
throw new ParseError.SYNTAX ("expected method call");
if (operator != UnaryOperator.NONE) {
next ();
var op = parse_unary_expression ();
- var lit = op as IntegerLiteral;
+ unowned IntegerLiteral? lit = op as IntegerLiteral;
if (lit != null) {
if (operator == UnaryOperator.PLUS) {
return lit;
var constant_type = parse_type (false, false);
// constant arrays don't own their element
- var array_type = constant_type as ArrayType;
+ unowned ArrayType? array_type = constant_type as ArrayType;
if (array_type != null) {
array_type.element_type.value_owned = false;
}
type = parse_inline_array_type (type);
// constant arrays don't own their element
- var array_type = type as ArrayType;
+ unowned ArrayType? array_type = type as ArrayType;
if (array_type != null) {
array_type.element_type.value_owned = false;
}
public override bool compatible (DataType target_type) {
if (target_type is PointerType) {
- var tt = target_type as PointerType;
+ unowned PointerType? tt = target_type as PointerType;
if (tt.base_type is VoidType || base_type is VoidType) {
return true;
}
public override Symbol? get_pointer_member (string member_name) {
- Symbol base_symbol = base_type.type_symbol;
+ unowned Symbol? base_symbol = base_type.type_symbol;
if (base_symbol == null) {
return null;
}
public override DataType? infer_type_argument (TypeParameter type_param, DataType value_type) {
- var pointer_type = value_type as PointerType;
+ unowned PointerType? pointer_type = value_type as PointerType;
if (pointer_type != null) {
return base_type.infer_type_argument (type_param, pointer_type.base_type);
}
public override void get_defined_variables (Collection<Variable> collection) {
inner.get_defined_variables (collection);
- var local = inner.symbol_reference as LocalVariable;
- var param = inner.symbol_reference as Parameter;
+ unowned LocalVariable? local = inner.symbol_reference as LocalVariable;
+ unowned Parameter? param = inner.symbol_reference as Parameter;
if (local != null) {
collection.add (local);
} else if (param != null && param.direction == ParameterDirection.OUT) {
}
if (inner is MemberAccess) {
- var ma = (MemberAccess) inner;
+ unowned MemberAccess ma = (MemberAccess) inner;
if (ma.prototype_access) {
error = true;
return false;
}
} else if (inner is ElementAccess) {
- var ea = (ElementAccess) inner;
+ unowned ElementAccess ea = (ElementAccess) inner;
if (!(ea.container.value_type is ArrayType)) {
error = true;
Report.error (source_reference, "unsupported lvalue in postfix expression");
}
if (inner is MemberAccess) {
- var ma = (MemberAccess) inner;
+ unowned MemberAccess ma = (MemberAccess) inner;
if (ma.symbol_reference is Property) {
- var prop = (Property) ma.symbol_reference;
+ unowned Property prop = (Property) ma.symbol_reference;
if (prop.set_accessor == null || !prop.set_accessor.writable) {
ma.error = true;
public override void get_defined_variables (Collection<Variable> collection) {
inner.get_defined_variables (collection);
- var local = inner.symbol_reference as LocalVariable;
- var param = inner.symbol_reference as Parameter;
+ unowned LocalVariable? local = inner.symbol_reference as LocalVariable;
+ unowned Parameter? param = inner.symbol_reference as Parameter;
if (local != null) {
collection.add (local);
} else if (param != null && param.direction == ParameterDirection.OUT) {
public override void get_used_variables (Collection<Variable> collection) {
inner.get_used_variables (collection);
- var local = inner.symbol_reference as LocalVariable;
- var param = inner.symbol_reference as Parameter;
+ unowned LocalVariable? local = inner.symbol_reference as LocalVariable;
+ unowned Parameter? param = inner.symbol_reference as Parameter;
if (local != null) {
collection.add (local);
} else if (param != null && param.direction == ParameterDirection.OUT) {
return false;
}
- var local = return_expression.symbol_reference as LocalVariable;
+ unowned LocalVariable? local = return_expression.symbol_reference as LocalVariable;
if (local != null && local.variable_type.is_disposable () &&
!context.analyzer.current_return_type.value_owned) {
error = true;
}
if (is_generic) {
- var cl = (ObjectTypeSymbol) parent_symbol;
+ unowned ObjectTypeSymbol cl = (ObjectTypeSymbol) parent_symbol;
foreach (var type_param in cl.get_type_parameters ()) {
generated_delegate.add_type_parameter (new TypeParameter (type_param.name, type_param.source_reference));
}
// parameter types must refer to the delegate type parameters
// instead of to the class type parameters
foreach (var param in generated_delegate.get_parameters ()) {
- var generic_type = param.variable_type as GenericType;
+ unowned GenericType? generic_type = param.variable_type as GenericType;
if (generic_type != null) {
generic_type.type_parameter = generated_delegate.get_type_parameters ().get (generated_delegate.get_type_parameter_index (generic_type.type_parameter.name));
}
checked = true;
// parent_symbol may be null for dynamic signals
- var parent_cl = parent_symbol as Class;
+ unowned Class? parent_cl = parent_symbol as Class;
if (parent_cl != null && parent_cl.is_compact) {
error = true;
Report.error (source_reference, "Signals are not supported in compact classes");
default_handler.add_parameter (param);
}
- var cl = parent_symbol as ObjectTypeSymbol;
+ unowned ObjectTypeSymbol? cl = parent_symbol as ObjectTypeSymbol;
cl.add_hidden_method (default_handler);
default_handler.check (context);
}
emitter.body = body;
- var cl = parent_symbol as ObjectTypeSymbol;
+ unowned ObjectTypeSymbol? cl = parent_symbol as ObjectTypeSymbol;
cl.add_hidden_method (emitter);
emitter.check (context);
}
if (container.value_type is ArrayType) {
- var array_type = (ArrayType) container.value_type;
+ unowned ArrayType array_type = (ArrayType) container.value_type;
start.target_type = array_type.length_type.copy ();
stop.target_type = array_type.length_type.copy ();
}
}
public static StringLiteral? get_format_literal (Expression expr) {
- var format_literal = expr as StringLiteral;
+ unowned StringLiteral? format_literal = expr as StringLiteral;
if (format_literal != null) {
return format_literal;
}
- var call = expr as MethodCall;
+ unowned MethodCall? call = expr as MethodCall;
if (call != null) {
return call.get_format_literal ();
}
* @return true if this is a boolean type, false otherwise
*/
public bool is_boolean_type () {
- var st = base_struct;
+ unowned Struct? st = base_struct;
if (st != null && st.is_boolean_type ()) {
return true;
}
* @return true if this is an integer type, false otherwise
*/
public bool is_integer_type () {
- var st = base_struct;
+ unowned Struct? st = base_struct;
if (st != null && st.is_integer_type ()) {
return true;
}
* @return true if this is a floating point type, false otherwise
*/
public bool is_floating_type () {
- var st = base_struct;
+ unowned Struct? st = base_struct;
if (st != null && st.is_floating_type ()) {
return true;
}
}
public bool is_decimal_floating_type () {
- var st = base_struct;
+ unowned Struct? st = base_struct;
if (st != null && st.is_decimal_floating_type ()) {
return true;
}
* instances are passed by value.
*/
public bool is_simple_type () {
- var st = base_struct;
+ unowned Struct? st = base_struct;
if (st != null && st.is_simple_type ()) {
return true;
}
}
bool is_recursive_value_type (DataType type) {
- var struct_type = type as StructValueType;
+ unowned StructValueType? struct_type = type as StructValueType;
if (struct_type != null && !struct_type.nullable) {
- var st = (Struct) struct_type.type_symbol;
+ unowned Struct st = (Struct) struct_type.type_symbol;
if (st == this) {
return true;
}
}
public override bool is_invokable () {
- var st = type_symbol as Struct;
+ unowned Struct? st = type_symbol as Struct;
if (st != null && st.default_construction_method != null) {
return true;
} else {
}
public override unowned DataType? get_return_type () {
- var st = type_symbol as Struct;
+ unowned Struct? st = type_symbol as Struct;
if (st != null && st.default_construction_method != null) {
return st.default_construction_method.return_type;
} else {
}
public override unowned List<Parameter>? get_parameters () {
- var st = type_symbol as Struct;
+ unowned Struct? st = type_symbol as Struct;
if (st != null && st.default_construction_method != null) {
return st.default_construction_method.get_parameters ();
} else {
if (sym is Delegate) {
type = new DelegateType ((Delegate) sym);
} else if (sym is Class) {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.is_error_base) {
type = new ErrorType (null, null, unresolved_type.source_reference);
} else {
}
if (operator == UnaryOperator.REF || operator == UnaryOperator.OUT) {
- var field = inner.symbol_reference as Field;
+ unowned Field? field = inner.symbol_reference as Field;
if (field != null && field.binding == MemberBinding.STATIC) {
return true;
} else {
}
bool is_numeric_type (DataType type) {
- if (type.nullable || !(type.type_symbol is Struct)) {
+ unowned Struct? st = type.type_symbol as Struct;
+ if (type.nullable || st == null) {
return false;
}
- var st = (Struct) type.type_symbol;
return st.is_integer_type () || st.is_floating_type ();
}
bool is_integer_type (DataType type) {
- if (type.nullable || !(type.type_symbol is Struct)) {
+ unowned Struct? st = type.type_symbol as Struct;
+ if (type.nullable || st == null) {
return false;
}
- var st = (Struct) type.type_symbol;
return st.is_integer_type ();
}
assignment.check (context);
return true;
} else if (operator == UnaryOperator.REF || operator == UnaryOperator.OUT) {
- var ea = inner as ElementAccess;
+ unowned ElementAccess? ea = inner as ElementAccess;
if (inner.symbol_reference is Field || inner.symbol_reference is Parameter || inner.symbol_reference is LocalVariable ||
(ea != null && ea.container.value_type is ArrayType)) {
// ref and out can only be used with fields, parameters, local variables, and array element access
public override void get_defined_variables (Collection<Variable> collection) {
inner.get_defined_variables (collection);
if (operator == UnaryOperator.OUT || operator == UnaryOperator.REF) {
- var local = inner.symbol_reference as LocalVariable;
- var param = inner.symbol_reference as Parameter;
+ unowned LocalVariable? local = inner.symbol_reference as LocalVariable;
+ unowned Parameter? param = inner.symbol_reference as Parameter;
if (local != null) {
collection.add (local);
}
}
public static UnresolvedSymbol? new_from_expression (Expression expr) {
- var ma = expr as MemberAccess;
+ unowned MemberAccess? ma = expr as MemberAccess;
if (ma != null) {
if (ma.inner != null) {
return new UnresolvedSymbol (new_from_expression (ma.inner), ma.member_name, ma.source_reference);
}
bool always_true (Expression condition) {
- var literal = condition as BooleanLiteral;
+ unowned BooleanLiteral? literal = condition as BooleanLiteral;
return (literal != null && literal.value);
}
bool always_false (Expression condition) {
- var literal = condition as BooleanLiteral;
+ unowned BooleanLiteral? literal = condition as BooleanLiteral;
return (literal != null && !literal.value);
}
var loop = new Loop (body, source_reference);
- var parent_block = (Block) parent_node;
+ unowned Block parent_block = (Block) parent_node;
parent_block.replace_statement (this, loop);
if (!loop.check (context)) {