girparser: Do not add Object prerequisite before symbol resolution
[vala-lang.git] / vala / valacharacterliteral.vala
blobd38a0e6de3aea8fabe90a95abe569a865b789b11
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
20 * Author:
21 * Jürg Billeter <j@bitron.ch>
22 * Raffaele Sandrini <raffaele@sandrini.ch>
25 using GLib;
27 /**
28 * Represents a single literal character.
30 public class Vala.CharacterLiteral : Literal {
31 /**
32 * The literal value.
34 public string value {
35 get {
36 return _value;
38 set {
39 _value = value;
41 if (!value.validate ()) {
42 error = true;
47 private string _value;
49 /**
50 * Creates a new character literal.
52 * @param c character
53 * @param source reference to source code
54 * @return newly created character literal
56 public CharacterLiteral (string c, SourceReference? source = null) {
57 value = c;
58 source_reference = source;
62 public override void accept (CodeVisitor visitor) {
63 visitor.visit_character_literal (this);
65 visitor.visit_expression (this);
68 /**
69 * Returns the unicode character value this character literal
70 * represents.
72 * @return unicode character value
74 public unichar get_char () {
75 return value.next_char ().get_char ();
78 public override bool is_pure () {
79 return true;
82 public override string to_string () {
83 return value;
86 public override bool check (CodeContext context) {
87 if (checked) {
88 return !error;
91 checked = true;
93 if (context.profile == Profile.DOVA) {
94 value_type = new IntegerType ((Struct) context.analyzer.root_symbol.scope.lookup ("char"), get_char ().to_string (), "int");
95 } else {
96 if (get_char () < 128) {
97 value_type = new IntegerType ((Struct) context.analyzer.root_symbol.scope.lookup ("char"));
98 } else {
99 value_type = new IntegerType ((Struct) context.analyzer.root_symbol.scope.lookup ("unichar"));
103 return !error;
106 public override void emit (CodeGenerator codegen) {
107 codegen.visit_character_literal (this);
109 codegen.visit_expression (this);