and don't apply type-argument check on external symbols.
push_line (f.source_reference);
visit_member (f);
- check_type (f.variable_type);
-
var cl = f.parent_symbol as Class;
bool is_gtypeinstance = (cl != null && !cl.is_compact);
return false;
}
- public override void visit_formal_parameter (Parameter p) {
- if (!p.ellipsis) {
- check_type (p.variable_type);
- }
- }
-
public override void visit_property (Property prop) {
visit_member (prop);
- check_type (prop.property_type);
-
if (prop.get_accessor != null) {
prop.get_accessor.accept (this);
}
}
public override void visit_local_variable (LocalVariable local) {
- check_type (local.variable_type);
-
/* Declaration */
generate_type_declaration (local.variable_type, cfile);
}
}
- bool is_reference_type_argument (DataType type_arg) {
- if (type_arg is ErrorType || (type_arg.data_type != null && type_arg.data_type.is_reference_type ())) {
- return true;
- } else {
- return false;
- }
- }
-
- bool is_nullable_value_type_argument (DataType type_arg) {
- if (type_arg is ValueType && type_arg.nullable) {
- return true;
- } else {
- return false;
- }
- }
-
- bool is_signed_integer_type_argument (DataType type_arg) {
- var st = type_arg.data_type as Struct;
- if (type_arg is EnumValueType) {
- return true;
- } else if (type_arg.nullable) {
- return false;
- } else if (st == null) {
- return false;
- } else if (st.is_subtype_of (bool_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (char_type.data_type)) {
- return true;
- } else if (unichar_type != null && st.is_subtype_of (unichar_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (short_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (int_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (long_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (int8_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (int16_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (int32_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (gtype_type)) {
- return true;
- } else {
- return false;
- }
- }
-
- bool is_unsigned_integer_type_argument (DataType type_arg) {
- var st = type_arg.data_type as Struct;
- if (st == null) {
- return false;
- } else if (type_arg.nullable) {
- return false;
- } else if (st.is_subtype_of (uchar_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (ushort_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (uint_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (ulong_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (uint8_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (uint16_type.data_type)) {
- return true;
- } else if (st.is_subtype_of (uint32_type.data_type)) {
- return true;
- } else {
- return false;
- }
- }
-
- public void check_type (DataType type) {
- var array_type = type as ArrayType;
- if (array_type != null) {
- check_type (array_type.element_type);
- if (array_type.element_type is ArrayType) {
- Report.error (type.source_reference, "Stacked arrays are not supported");
- } else if (array_type.element_type is DelegateType) {
- var delegate_type = (DelegateType) array_type.element_type;
- if (delegate_type.delegate_symbol.has_target) {
- Report.error (type.source_reference, "Delegates with target are not supported as array element type");
- }
- }
- }
- foreach (var type_arg in type.get_type_arguments ()) {
- check_type (type_arg);
- check_type_argument (type_arg);
- }
- }
-
- public void check_type_arguments (MemberAccess access) {
- foreach (var type_arg in access.get_type_arguments ()) {
- check_type (type_arg);
- check_type_argument (type_arg);
- }
- }
-
- void check_type_argument (DataType type_arg) {
- if (type_arg is GenericType
- || type_arg is PointerType
- || is_reference_type_argument (type_arg)
- || is_nullable_value_type_argument (type_arg)
- || is_signed_integer_type_argument (type_arg)
- || is_unsigned_integer_type_argument (type_arg)) {
- // no error
- } else if (type_arg is DelegateType) {
- var delegate_type = (DelegateType) type_arg;
- if (delegate_type.delegate_symbol.has_target) {
- Report.error (type_arg.source_reference, "Delegates with target are not supported as generic type arguments");
- }
- } else {
- Report.error (type_arg.source_reference, "`%s' is not a supported generic type argument, use `?' to box value types".printf (type_arg.to_string ()));
- }
- }
-
public virtual void generate_class_declaration (Class cl, CCodeFile decl_space) {
if (add_symbol_declaration (decl_space, cl, get_ccode_name (cl))) {
return;
CCodeExpression instance = null;
CCodeExpression creation_expr = null;
- check_type (expr.type_reference);
-
var st = expr.type_reference.data_type as Struct;
if ((st != null && (!st.is_simple_type () || get_ccode_name (st) == "va_list")) || expr.get_object_initializer ().size > 0) {
// value-type initialization or object creation expression with object initializer
}
public CCodeExpression convert_from_generic_pointer (CCodeExpression cexpr, DataType actual_type) {
+ unowned SemanticAnalyzer analyzer = context.analyzer;
var result = cexpr;
- if (is_reference_type_argument (actual_type) || is_nullable_value_type_argument (actual_type)) {
+ if (analyzer.is_reference_type_argument (actual_type) || analyzer.is_nullable_value_type_argument (actual_type)) {
generate_type_declaration (actual_type, cfile);
result = new CCodeCastExpression (cexpr, get_ccode_name (actual_type));
- } else if (is_signed_integer_type_argument (actual_type)) {
+ } else if (analyzer.is_signed_integer_type_argument (actual_type)) {
result = new CCodeCastExpression (new CCodeCastExpression (cexpr, "gintptr"), get_ccode_name (actual_type));
- } else if (is_unsigned_integer_type_argument (actual_type)) {
+ } else if (analyzer.is_unsigned_integer_type_argument (actual_type)) {
result = new CCodeCastExpression (new CCodeCastExpression (cexpr, "guintptr"), get_ccode_name (actual_type));
}
return result;
}
public CCodeExpression convert_to_generic_pointer (CCodeExpression cexpr, DataType actual_type) {
+ unowned SemanticAnalyzer analyzer = context.analyzer;
var result = cexpr;
- if (is_signed_integer_type_argument (actual_type)) {
+ if (analyzer.is_signed_integer_type_argument (actual_type)) {
result = new CCodeCastExpression (new CCodeCastExpression (cexpr, "gintptr"), "gpointer");
- } else if (is_unsigned_integer_type_argument (actual_type)) {
+ } else if (analyzer.is_unsigned_integer_type_argument (actual_type)) {
result = new CCodeCastExpression (new CCodeCastExpression (cexpr, "guintptr"), "gpointer");
}
return result;
m = ((MethodType) itype).method_symbol;
if (!get_ccode_simple_generics (m)) {
- check_type_arguments (ma);
+ context.analyzer.check_type_arguments (ma);
}
if (ma.inner != null && ma.inner.value_type is EnumValueType && ((EnumValueType) ma.inner.value_type).get_to_string_method() == m) {
bool in_gobject_creation_method = false;
bool in_fundamental_creation_method = false;
- check_type (m.return_type);
-
bool profile = m.get_attribute ("Profile") != null;
if (m is CreationMethod) {
}
variable_type.check (context);
+ if (!external_package) {
+ context.analyzer.check_type (variable_type);
+ }
// check whether field type is at least as accessible as the field
if (!context.analyzer.is_type_accessible (this, variable_type)) {
return false;
}
variable_type.check (context);
+ if (!external_package) {
+ context.analyzer.check_type (variable_type);
+ }
}
// Catch initializer list transformation:
return_type.floating_reference = returns_floating_reference;
return_type.check (context);
+ if (!external_package) {
+ context.analyzer.check_type (return_type);
+ }
var init_attr = get_attribute ("ModuleInit");
if (init_attr != null) {
}
}
- TypeSymbol type = null;
+ TypeSymbol type;
if (type_reference == null) {
if (member_name == null) {
type = (TypeSymbol) type_sym;
type_reference = new StructValueType ((Struct) type);
} else if (type_sym is ErrorCode) {
+ type = (TypeSymbol) type_sym;
type_reference = new ErrorType ((ErrorDomain) type_sym.parent_symbol, (ErrorCode) type_sym, source_reference);
symbol_reference = type_sym;
} else {
}
}
+ if (!type.external_package) {
+ context.analyzer.check_type (type_reference);
+ }
+
foreach (MemberInitializer init in get_object_initializer ()) {
context.analyzer.visit_member_initializer (init, type_reference);
}
}
if (!ellipsis) {
+ if (!external_package) {
+ context.analyzer.check_type (variable_type);
+ }
+
// check whether parameter type is at least as accessible as the method
if (!context.analyzer.is_type_accessible (this, variable_type)) {
error = true;
}
property_type.check (context);
+ if (!external_package) {
+ context.analyzer.check_type (property_type);
+ }
if (get_accessor == null && set_accessor == null) {
error = true;
public DataType void_type = new VoidType ();
public DataType bool_type;
- public DataType string_type;
- public DataType regex_type;
+ public DataType char_type;
public DataType uchar_type;
public DataType short_type;
public DataType ushort_type;
public DataType uint_type;
public DataType long_type;
public DataType ulong_type;
+ public DataType int8_type;
+ public DataType uint8_type;
+ public DataType int16_type;
+ public DataType uint16_type;
+ public DataType int32_type;
+ public DataType uint32_type;
public DataType size_t_type;
public DataType ssize_t_type;
- public DataType int8_type;
public DataType unichar_type;
public DataType double_type;
+ public DataType string_type;
+ public DataType regex_type;
public DataType type_type;
public DataType va_list_type;
public Class object_type;
var root_symbol = context.root;
bool_type = new BooleanType ((Struct) root_symbol.scope.lookup ("bool"));
- string_type = new ObjectType ((Class) root_symbol.scope.lookup ("string"));
- int_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int"));
- uint_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint"));
-
+ char_type = new IntegerType ((Struct) root_symbol.scope.lookup ("char"));
uchar_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uchar"));
- int8_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int8"));
short_type = new IntegerType ((Struct) root_symbol.scope.lookup ("short"));
ushort_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ushort"));
+ int_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int"));
+ uint_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint"));
long_type = new IntegerType ((Struct) root_symbol.scope.lookup ("long"));
ulong_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ulong"));
+ int8_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int8"));
+ uint8_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint8"));
+ int16_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int16"));
+ uint16_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint16"));
+ int32_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int32"));
+ uint32_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint32"));
size_t_type = new IntegerType ((Struct) root_symbol.scope.lookup ("size_t"));
ssize_t_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ssize_t"));
double_type = new FloatingType ((Struct) root_symbol.scope.lookup ("double"));
+ string_type = new ObjectType ((Class) root_symbol.scope.lookup ("string"));
va_list_type = new StructValueType ((Struct) root_symbol.scope.lookup ("va_list"));
var unichar_struct = (Struct) root_symbol.scope.lookup ("unichar");
}
return false;
}
+
+ public bool is_reference_type_argument (DataType type_arg) {
+ if (type_arg is ErrorType || (type_arg.data_type != null && type_arg.data_type.is_reference_type ())) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public bool is_nullable_value_type_argument (DataType type_arg) {
+ if (type_arg is ValueType && type_arg.nullable) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public bool is_signed_integer_type_argument (DataType type_arg) {
+ var st = type_arg.data_type as Struct;
+ if (type_arg is EnumValueType) {
+ return true;
+ } else if (type_arg.nullable) {
+ return false;
+ } else if (st == null) {
+ return false;
+ } else if (st.is_subtype_of (bool_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (char_type.data_type)) {
+ return true;
+ } else if (unichar_type != null && st.is_subtype_of (unichar_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (short_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (int_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (long_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (int8_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (int16_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (int32_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (type_type.data_type)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public bool is_unsigned_integer_type_argument (DataType type_arg) {
+ var st = type_arg.data_type as Struct;
+ if (st == null) {
+ return false;
+ } else if (type_arg.nullable) {
+ return false;
+ } else if (st.is_subtype_of (uchar_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (ushort_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (uint_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (ulong_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (uint8_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (uint16_type.data_type)) {
+ return true;
+ } else if (st.is_subtype_of (uint32_type.data_type)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public void check_type (DataType type) {
+ foreach (var type_arg in type.get_type_arguments ()) {
+ check_type (type_arg);
+ check_type_argument (type_arg);
+ }
+ }
+
+ public void check_type_arguments (MemberAccess access) {
+ foreach (var type_arg in access.get_type_arguments ()) {
+ check_type (type_arg);
+ check_type_argument (type_arg);
+ }
+ }
+
+ void check_type_argument (DataType type_arg) {
+ if (type_arg is GenericType
+ || type_arg is PointerType
+ || is_reference_type_argument (type_arg)
+ || is_nullable_value_type_argument (type_arg)
+ || is_signed_integer_type_argument (type_arg)
+ || is_unsigned_integer_type_argument (type_arg)) {
+ // no error
+ } else if (type_arg is DelegateType) {
+ var delegate_type = (DelegateType) type_arg;
+ if (delegate_type.delegate_symbol.has_target) {
+ Report.error (type_arg.source_reference, "Delegates with target are not supported as generic type arguments");
+ }
+ } else {
+ Report.error (type_arg.source_reference, "`%s' is not a supported generic type argument, use `?' to box value types".printf (type_arg.to_string ()));
+ }
+ }
}