1 /* valacharacterliteral.vala
3 * Copyright (C) 2006-2010 Jürg Billeter
4 * Copyright (C) 2006-2009 Raffaele Sandrini
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * Jürg Billeter <j@bitron.ch>
22 * Raffaele Sandrini <raffaele@sandrini.ch>
28 * Represents a single literal character.
30 public class Vala
.CharacterLiteral
: Literal
{
41 if (!value
.validate ()) {
47 private string _value
;
50 * Creates a new character literal.
53 * @param source reference to source code
54 * @return newly created character literal
56 public CharacterLiteral (string c
, SourceReference? source
= null) {
58 source_reference
= source
;
62 public override void accept (CodeVisitor visitor
) {
63 visitor
.visit_character_literal (this
);
65 visitor
.visit_expression (this
);
69 * Returns the unicode character value this character literal
72 * @return unicode character value
74 public unichar
get_char () {
75 return value
.next_char ().get_char ();
78 public override bool is_pure () {
82 public override string to_string () {
86 public override bool check (CodeContext context
) {
93 if (context
.profile
== Profile
.DOVA
) {
94 value_type
= new
IntegerType ((Struct
) context
.analyzer
.root_symbol
.scope
.lookup ("char"), get_char ().to_string (), "int");
96 if (get_char () < 128) {
97 value_type
= new
IntegerType ((Struct
) context
.analyzer
.root_symbol
.scope
.lookup ("char"));
99 value_type
= new
IntegerType ((Struct
) context
.analyzer
.root_symbol
.scope
.lookup ("unichar"));
106 public override void emit (CodeGenerator codegen
) {
107 codegen
.visit_character_literal (this
);
109 codegen
.visit_expression (this
);