/**
* The literal value.
*/
- public string! value { get; set construct; }
+ public string! value {
+ get {
+ return _value;
+ }
+ set construct {
+ _value = value;
+
+ if (!value.validate () || (value.len () != 3 && value.next_char ().get_char () != '\\')) {
+ error = true;
+ }
+ }
+ }
+
+ private string! _value;
/**
* Creates a new character literal.
public construct (string! c, SourceReference source) {
value = c;
source_reference = source;
+
+ if (error) {
+ Report.error (source_reference, "invalid character literal");
+ }
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_character_literal (this);
}
+
+ /**
+ * Returns the unicode character value this character literal
+ * represents.
+ *
+ * @return unicode character value
+ */
+ public uint get_char () {
+ // FIXME: unichar return type
+ return (uint) value.next_char ().get_char ();
+ }
}
private int next_temp_var_id = 0;
TypeReference bool_type;
+ TypeReference char_type;
+ TypeReference unichar_type;
+ TypeReference short_type;
+ TypeReference ushort_type;
TypeReference int_type;
TypeReference uint_type;
TypeReference long_type;
TypeReference ulong_type;
+ TypeReference int64_type;
+ TypeReference uint64_type;
TypeReference string_type;
TypeReference float_type;
TypeReference double_type;
bool_type = new TypeReference ();
bool_type.data_type = (DataType) root_symbol.lookup ("bool").node;
+ char_type = new TypeReference ();
+ char_type.data_type = (DataType) root_symbol.lookup ("char").node;
+
+ unichar_type = new TypeReference ();
+ unichar_type.data_type = (DataType) root_symbol.lookup ("unichar").node;
+
+ short_type = new TypeReference ();
+ short_type.data_type = (DataType) root_symbol.lookup ("short").node;
+
+ ushort_type = new TypeReference ();
+ ushort_type.data_type = (DataType) root_symbol.lookup ("ushort").node;
+
int_type = new TypeReference ();
int_type.data_type = (DataType) root_symbol.lookup ("int").node;
ulong_type = new TypeReference ();
ulong_type.data_type = (DataType) root_symbol.lookup ("ulong").node;
+ int64_type = new TypeReference ();
+ int64_type.data_type = (DataType) root_symbol.lookup ("int64").node;
+
+ uint64_type = new TypeReference ();
+ uint64_type.data_type = (DataType) root_symbol.lookup ("uint64").node;
+
float_type = new TypeReference ();
float_type.data_type = (DataType) root_symbol.lookup ("float").node;
if (ret_type.is_reference_type ()) {
ccheck.add_argument (new CCodeConstant ("NULL"));
- } else if (ret_type.name == "bool") {
+ } else if (ret_type == bool_type.data_type) {
ccheck.add_argument (new CCodeConstant ("FALSE"));
- } else if (ret_type.name == "int" || ret_type.name == "long" || ret_type.name == "double" || ret_type.name == "float" || ret_type.name == "uint" || ret_type.name == "ulong" || ret_type is Enum || ret_type is Flags) {
+ } else if (ret_type == char_type.data_type ||
+ ret_type == unichar_type.data_type ||
+ ret_type == short_type.data_type ||
+ ret_type == ushort_type.data_type ||
+ ret_type == int_type.data_type ||
+ ret_type == uint_type.data_type ||
+ ret_type == long_type.data_type ||
+ ret_type == ulong_type.data_type ||
+ ret_type == int64_type.data_type ||
+ ret_type == uint64_type.data_type ||
+ ret_type == double_type.data_type ||
+ ret_type == float_type.data_type ||
+ ret_type is Enum || ret_type is Flags) {
ccheck.add_argument (new CCodeConstant ("0"));
} else {
Report.error (method_node.source_reference, "not supported return type for runtime type checks");
}
public override void visit_character_literal (CharacterLiteral! expr) {
- expr.ccodenode = new CCodeConstant (expr.value);
+ if (expr.get_char () >= 0x20 && expr.get_char () < 0x80) {
+ expr.ccodenode = new CCodeConstant (expr.value);
+ } else {
+ expr.ccodenode = new CCodeConstant ("%uU".printf (expr.get_char ()));
+ }
}
public override void visit_integer_literal (IntegerLiteral! expr) {