[vala] Fix code generation for large integer literals
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix code generation for large integer literals
- Date: Mon, 22 Mar 2010 20:13:58 +0000 (UTC)
commit f91a04666caee7768c0a9dbb4b8eb62c9a767aab
Author: Jürg Billeter <j bitron ch>
Date: Mon Mar 22 21:12:38 2010 +0100
Fix code generation for large integer literals
Fixes bug 583669.
codegen/valaccodebasemodule.vala | 2 +-
vala/valaintegerliteral.vala | 74 +++++++++++++++++++------------------
2 files changed, 39 insertions(+), 37 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 8981e78..83aafae 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3482,7 +3482,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
public override void visit_integer_literal (IntegerLiteral expr) {
- expr.ccodenode = new CCodeConstant (expr.value);
+ expr.ccodenode = new CCodeConstant (expr.value + expr.type_suffix);
}
public override void visit_real_literal (RealLiteral expr) {
diff --git a/vala/valaintegerliteral.vala b/vala/valaintegerliteral.vala
index 6a84131..31afc93 100644
--- a/vala/valaintegerliteral.vala
+++ b/vala/valaintegerliteral.vala
@@ -1,6 +1,6 @@
/* valaintegerliteral.vala
*
- * Copyright (C) 2006-2008 Jürg Billeter
+ * Copyright (C) 2006-2010 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,8 @@ public class Vala.IntegerLiteral : Literal {
*/
public string value { get; set; }
+ public string type_suffix { get; set; }
+
/**
* Creates a new integer literal.
*
@@ -52,28 +54,31 @@ public class Vala.IntegerLiteral : Literal {
public override 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;
-
+
+ public override bool is_pure () {
+ return true;
+ }
+
+ public override bool check (SemanticAnalyzer analyzer) {
+ if (checked) {
+ return !error;
+ }
+
+ checked = true;
+
int l = 0;
- while (number.has_suffix ("l") || number.has_suffix ("L")) {
+ while (value.has_suffix ("l") || value.has_suffix ("L")) {
l++;
- number = number.ndup (number.size () - 1);
+ value = value.ndup (value.size () - 1);
}
bool u = false;
- if (number.has_suffix ("u") || number.has_suffix ("U")) {
+ if (value.has_suffix ("u") || value.has_suffix ("U")) {
u = true;
- number = number.ndup (number.size () - 1);
+ value = value.ndup (value.size () - 1);
}
- int64 n = number.to_int64 ();
+ int64 n = value.to_int64 ();
if (!u && n > 0x7fffffff) {
// value doesn't fit into signed 32-bit
l = 2;
@@ -82,46 +87,43 @@ public class Vala.IntegerLiteral : Literal {
l = 2;
}
+ string type_name;
if (l == 0) {
if (u) {
- return "uint";
+ type_suffix = "U";
+ type_name = "uint";
} else {
- return "int";
+ type_suffix = "";
+ type_name = "int";
}
} else if (l == 1) {
if (u) {
- return "ulong";
+ type_suffix = "UL";
+ type_name = "ulong";
} else {
- return "long";
+ type_suffix = "L";
+ type_name = "long";
}
} else if (CodeContext.get ().profile == Profile.DOVA) {
// long is 64-bit in Dova profile
if (u) {
- return "ulong";
+ type_suffix = "UL";
+ type_name = "ulong";
} else {
- return "long";
+ type_suffix = "L";
+ type_name = "long";
}
} else {
if (u) {
- return "uint64";
+ type_suffix = "ULL";
+ type_name = "uint64";
} else {
- return "int64";
+ type_suffix = "LL";
+ type_name = "int64";
}
}
- }
-
- public override bool is_pure () {
- return true;
- }
-
- public override bool check (SemanticAnalyzer analyzer) {
- if (checked) {
- return !error;
- }
-
- checked = true;
- value_type = new IntegerType ((Struct) analyzer.root_symbol.scope.lookup (get_type_name ()), value, get_type_name ());
+ value_type = new IntegerType ((Struct) analyzer.root_symbol.scope.lookup (type_name), value, type_name);
return !error;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]