1 /* valaintegerliteral.vala
3 * Copyright (C) 2006-2010 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
26 * Represents an integer literal in the source code.
28 public class Vala
.IntegerLiteral
: Literal
{
32 public string value
{ get; set; }
34 public string type_suffix
{ get; set; }
37 * Creates a new integer literal.
39 * @param i literal value
40 * @param source reference to source code
41 * @return newly created integer literal
43 public IntegerLiteral (string i
, SourceReference? source
= null) {
45 source_reference
= source
;
48 public override void accept (CodeVisitor visitor
) {
49 visitor
.visit_integer_literal (this
);
51 visitor
.visit_expression (this
);
54 public override string to_string () {
58 public override bool is_pure () {
62 public override bool check (CodeContext context
) {
70 while (value
.has_suffix ("l") || value
.has_suffix ("L")) {
72 value
= value
.substring (0, value
.length
- 1);
76 if (value
.has_suffix ("u") || value
.has_suffix ("U")) {
78 value
= value
.substring (0, value
.length
- 1);
81 int64 n
= int64.parse (value
);
82 if (!u
&& (n
> int.MAX
|| n
< int.MIN
)) {
83 // value doesn't fit into signed 32-bit
85 } else if (u
&& n
> uint.MAX
) {
86 // value doesn't fit into unsigned 32-bit
110 type_name
= "uint64";
117 var st
= (Struct
) context
.root
.scope
.lookup (type_name
);
118 // ensure attributes are already processed
121 value_type
= new
IntegerType (st
, value
, type_name
);
126 public override void emit (CodeGenerator codegen
) {
127 codegen
.visit_integer_literal (this
);
129 codegen
.visit_expression (this
);