+2006-09-02 Jürg Billeter <j@bitron.ch>
+
+ * vala/scanner.l: support integer and floating point suffixes
+ * vala/valasemanticanalyzer.vala: use correct type for integer and
+ floating point literals
+ * vala/valaintegerliteral.val, vala/valarealliteral.vala: add
+ get_type_name method
+ * vapi/glib-2.0.vala: add string to int64 conversion method
+
2006-09-02 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: use IntegerType, FloatingType, and
space [ \t\n]*
ident [[:alnum:]_]+
decimal_integer_literal (0|[1-9][[:digit:]]*)
-real_literal [[:digit:]]+"."[[:digit:]]*
+real_literal [[:digit:]]+"."[[:digit:]]*{real_suffix}?
hex_digit [[:digit:]A-fa-f]
octal_digit [0-7]
octal_integer_literal 0{octal_digit}+
hexadecimal_integer_literal 0x{hex_digit}+
+integer_suffix L|LL|U|UL|ULL
+real_suffix F
single_character [^\'\\]
single_string_literal_character [^\"\\]
simple_escape_sequence \\[\'\"\?\\abfnrtv]
string_literal_character ({single_string_literal_character}|{simple_escape_sequence})
character_literal \'{character}*\'
string_literal \"{string_literal_character}*\"
-integer_literal ({decimal_integer_literal}|{hexadecimal_integer_literal}|{octal_integer_literal})
+integer_literal ({decimal_integer_literal}|{hexadecimal_integer_literal}|{octal_integer_literal}){integer_suffix}?
literal ({integer_literal}|{real_literal}|{character_literal}|{string_literal})
%%
public override ref string! to_string () {
return value;
}
+
+ /**
+ * Returns the type name of the value this literal represents.
+ *
+ * @return the name of literal type
+ */
+ public string! get_type_name () {
+ string number = value;
+
+ int l = 0;
+ while (number.has_suffix ("L")) {
+ l++;
+ number = number.ndup (number.size () - 1);
+ }
+
+ bool u = false;
+ if (number.has_suffix ("U")) {
+ u = true;
+ number = number.ndup (number.size () - 1);
+ }
+
+ int64 n = number.to_int64 ();
+ if (!u && n > 0x7fffffff) {
+ // value doesn't fit into signed 32-bit
+ l = 2;
+ } else if (u && n > 0xffffffff) {
+ // value doesn't fit into unsigned 32-bit
+ l = 2;
+ }
+
+ if (l == 0) {
+ if (u) {
+ return "uint";
+ } else {
+ return "int";
+ }
+ } else if (l == 1) {
+ if (u) {
+ return "ulong";
+ } else {
+ return "long";
+ }
+ } else {
+ if (u) {
+ return "uint64";
+ } else {
+ return "int64";
+ }
+ }
+ }
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_real_literal (this);
}
+
+ /**
+ * Returns the type name of the value this literal represents.
+ *
+ * @return the name of literal type
+ */
+ public string! get_type_name () {
+ if (value.has_suffix ("F")) {
+ return "float";
+ }
+
+ return "double";
+ }
}
public override void visit_integer_literal (IntegerLiteral! expr) {
expr.static_type = new TypeReference ();
- expr.static_type.data_type = (DataType) root_symbol.lookup ("int").node;
+ expr.static_type.data_type = (DataType) root_symbol.lookup (expr.get_type_name ()).node;
}
public override void visit_real_literal (RealLiteral! expr) {
expr.static_type = new TypeReference ();
- expr.static_type.data_type = (DataType) root_symbol.lookup ("double").node;
+ expr.static_type.data_type = (DataType) root_symbol.lookup (expr.get_type_name ()).node;
}
public override void visit_string_literal (StringLiteral! expr) {
[CCode (cname = "gint64", cheader_filename = "glib.h", type_id = "G_TYPE_INT64", marshaller_type_name = "INT64")]
[IntegerType (rank = 14)]
public struct int64 {
+ [InstanceLast ()]
+ [CCode (cname = "g_strdup_printf")]
+ public ref string! to_string (string! format = "%lli");
}
[CCode (cname = "guint64", cheader_filename = "glib.h", type_id = "G_TYPE_UINT64", marshaller_type_name = "UINT64")]
[IntegerType (rank = 15)]
public struct uint64 {
+ [InstanceLast ()]
+ [CCode (cname = "g_strdup_printf")]
+ public ref string! to_string (string! format = "%llu");
}
[CCode (cname = "float", cheader_filename = "glib.h", type_id = "G_TYPE_FLOAT", marshaller_type_name = "FLOAT")]
}
[ReferenceType (dup_function = "g_strdup", free_function = "g_free", type_id = "G_TYPE_STRING", ref_function = "g_strdup")]
-[CCode (cname = "char", cheader_filename = "string.h,glib.h", type_id = "G_TYPE_STRING", marshaller_type_name = "STRING")]
+[CCode (cname = "char", cheader_filename = "stdlib.h,string.h,glib.h", type_id = "G_TYPE_STRING", marshaller_type_name = "STRING")]
public struct string {
[CCode (cname = "g_strstr")]
public string str (string! needle);
[CCode (cname = "atoi")]
public int to_int ();
+ [CCode (cname = "strtoll")]
+ public int64 to_int64 (out string endptr = null, int _base = 0);
[CCode (cname = "strlen")]
public long size ();
}