+2008-03-31 Jürg Billeter <j@bitron.ch>
+
+ * vala/Makefile.am, vala/parser.y, vala/vala.h,
+ vala/valaattribute.vala, vala/valabooleanliteral.vala,
+ vala/valacharacterliteral.vala, vala/valacodecontext.vala,
+ vala/valacodegenerator.vala, vala/valacodevisitor.vala,
+ vala/valaintegerliteral.vala, vala/valaliteral.vala,
+ vala/valanullliteral.vala, vala/valarealliteral.vala,
+ vala/valasemanticanalyzer.vala, vala/valastringliteral.vala,
+ gobject/valaccodeelementaccessbinding.vala,
+ gobject/valaccodegenerator.vala:
+
+ Merge Literal and LiteralExpression
+
2008-03-31 Jürg Billeter <j@bitron.ch>
* vala/valainterfacewriter.vala: fix output of enums with methods
/* valaccodeelementaccessbinding.vala
*
- * Copyright (C) 2006-2007 Jürg Billeter, Raffaele Sandrini
+ * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
var cindex = (CCodeExpression) indices[0].ccodenode;
if (expr.container.symbol_reference is ArrayLengthField) {
/* Figure if cindex is a constant expression and calculate dim...*/
- var lit = indices[0] as LiteralExpression;
+ var lit = indices[0] as IntegerLiteral;
var memberaccess = expr.container as MemberAccess;
- if (lit != null &&
- lit.literal is IntegerLiteral &&
- memberaccess != null) {
- int dim = (lit.literal as IntegerLiteral).value.to_int ();
+ if (lit != null && memberaccess != null) {
+ int dim = lit.value.to_int ();
codenode = codegen.get_array_length_cexpression (memberaccess.inner, dim + 1);
}
} else if (container_type == codegen.string_type.data_type) {
public override void visit_boolean_literal (BooleanLiteral! expr) {
expr.ccodenode = new CCodeConstant (expr.value ? "TRUE" : "FALSE");
+
+ visit_expression (expr);
}
public override void visit_character_literal (CharacterLiteral! expr) {
} else {
expr.ccodenode = new CCodeConstant ("%uU".printf (expr.get_char ()));
}
+
+ visit_expression (expr);
}
public override void visit_integer_literal (IntegerLiteral! expr) {
expr.ccodenode = new CCodeConstant (expr.value);
+
+ visit_expression (expr);
}
public override void visit_real_literal (RealLiteral! expr) {
expr.ccodenode = new CCodeConstant (expr.value);
+
+ visit_expression (expr);
}
public override void visit_string_literal (StringLiteral! expr) {
expr.ccodenode = new CCodeConstant (expr.value);
+
+ visit_expression (expr);
}
public override void visit_null_literal (NullLiteral! expr) {
expr.ccodenode = new CCodeConstant ("NULL");
- }
- public override void visit_literal_expression (LiteralExpression! expr) {
- expr.ccodenode = expr.literal.ccodenode;
-
visit_expression (expr);
}
ccall.add_argument (new CCodeIdentifier (constant.get_cname ()));
return ccall;
}
- } else if (array_expr is LiteralExpression) {
- var lit = (LiteralExpression) array_expr;
- if (lit.literal is NullLiteral) {
- return new CCodeConstant ("0");
- }
+ } else if (array_expr is NullLiteral) {
+ return new CCodeConstant ("0");
}
if (!is_out) {
var ccall = new CCodeFunctionCall (dupexpr);
- if (((context.non_null && !expr.static_type.requires_null_check) && expr.static_type.type_parameter == null) || expr is LiteralExpression) {
+ if (((context.non_null && !expr.static_type.requires_null_check) && expr.static_type.type_parameter == null) || expr is StringLiteral) {
// expression is non-null
ccall.add_argument ((CCodeExpression) expr.ccodenode);
return null;
}
- public override CodeBinding create_literal_expression_binding (LiteralExpression! node) {
- return null;
- }
-
public override CodeBinding create_parenthesized_expression_binding (ParenthesizedExpression! node) {
return null;
}
valainvocationexpression.vala \
valalambdaexpression.vala \
valaliteral.vala \
- valaliteralexpression.vala \
valalocalvariabledeclaration.vala \
valalockable.vala \
valalockstatement.vala \
int num;
char *str;
GList *list;
- ValaLiteral *literal;
ValaUnresolvedSymbol *unresolved_symbol;
ValaDataType *type_reference;
ValaExpression *expression;
%type <str> comment
%type <str> identifier
%type <str> identifier_or_keyword
-%type <literal> literal
-%type <literal> boolean_literal
+%type <expression> literal
+%type <expression> boolean_literal
%type <num> stars
%type <unresolved_symbol> symbol_name
%type <type_reference> type_name
| INTEGER_LITERAL
{
ValaSourceReference *src = src(@1);
- $$ = VALA_LITERAL (vala_code_context_create_integer_literal (context, $1, src));
+ $$ = VALA_EXPRESSION (vala_code_context_create_integer_literal (context, $1, src));
g_object_unref (src);
g_free ($1);
}
| REAL_LITERAL
{
ValaSourceReference *src = src(@1);
- $$ = VALA_LITERAL (vala_code_context_create_real_literal (context, $1, src));
+ $$ = VALA_EXPRESSION (vala_code_context_create_real_literal (context, $1, src));
g_free ($1);
g_object_unref (src);
}
| CHARACTER_LITERAL
{
ValaSourceReference *src = src(@1);
- $$ = VALA_LITERAL (vala_code_context_create_character_literal (context, $1, src));
+ $$ = VALA_EXPRESSION (vala_code_context_create_character_literal (context, $1, src));
g_object_unref (src);
g_free ($1);
}
| STRING_LITERAL
{
ValaSourceReference *src = src(@1);
- $$ = VALA_LITERAL (vala_code_context_create_string_literal (context, $1, src));
+ $$ = VALA_EXPRESSION (vala_code_context_create_string_literal (context, $1, src));
g_object_unref (src);
g_free ($1);
}
| VALA_NULL
{
ValaSourceReference *src = src(@1);
- $$ = VALA_LITERAL (vala_code_context_create_null_literal (context, src));
+ $$ = VALA_EXPRESSION (vala_code_context_create_null_literal (context, src));
g_object_unref (src);
}
;
: VALA_TRUE
{
ValaSourceReference *src = src(@1);
- $$ = VALA_LITERAL (vala_code_context_create_boolean_literal (context, TRUE, src));
+ $$ = VALA_EXPRESSION (vala_code_context_create_boolean_literal (context, TRUE, src));
g_object_unref (src);
}
| VALA_FALSE
{
ValaSourceReference *src = src(@1);
- $$ = VALA_LITERAL (vala_code_context_create_boolean_literal (context, FALSE, src));
+ $$ = VALA_EXPRESSION (vala_code_context_create_boolean_literal (context, FALSE, src));
g_object_unref (src);
}
;
primary_no_array_creation_expression
: literal
- {
- ValaSourceReference *src = src(@1);
- $$ = VALA_EXPRESSION (vala_code_context_create_literal_expression (context, $1, src));
- g_object_unref (src);
- g_object_unref ($1);
- }
| simple_name
| parenthesized_expression
| member_access
#include <vala/valainvocationexpression.h>
#include <vala/valalambdaexpression.h>
#include <vala/valaliteral.h>
-#include <vala/valaliteralexpression.h>
#include <vala/valalocalvariabledeclaration.h>
#include <vala/valalockstatement.h>
#include <vala/valamemberaccess.h>
// FIXME: use hash table
foreach (NamedArgument arg in args) {
if (arg.name == name) {
- if (arg.argument is LiteralExpression) {
- var lit = ((LiteralExpression) arg.argument).literal;
- if (lit is StringLiteral) {
- return ((StringLiteral) lit).eval ();
- }
+ var lit = arg.argument as StringLiteral;
+ if (lit != null) {
+ return lit.eval ();
}
}
}
// FIXME: use hash table
foreach (NamedArgument arg in args) {
if (arg.name == name) {
- if (arg.argument is LiteralExpression) {
- var lit = ((LiteralExpression) arg.argument).literal;
- if (lit is IntegerLiteral) {
- return ((IntegerLiteral) lit).value.to_int ();
- }
+ var lit = arg.argument as IntegerLiteral;
+ if (lit != null) {
+ return lit.value.to_int ();
}
}
}
// FIXME: use hash table
foreach (NamedArgument arg in args) {
if (arg.name == name) {
- if (arg.argument is LiteralExpression) {
- var lit = ((LiteralExpression) arg.argument).literal;
- if (lit is RealLiteral) {
- return ((RealLiteral) lit).value.to_double ();
- } else if (lit is IntegerLiteral) {
- return ((IntegerLiteral) lit).value.to_int ();
- }
+ if (arg.argument is RealLiteral) {
+ var lit = (RealLiteral) arg.argument;
+ return lit.value.to_double ();
+ } else if (arg.argument is IntegerLiteral) {
+ var lit = (IntegerLiteral) arg.argument;
+ return lit.value.to_int ();
} else if (arg.argument is UnaryExpression) {
var unary = (UnaryExpression) arg.argument;
if (unary.operator == UnaryOperator.MINUS) {
- if (unary.inner is LiteralExpression) {
- var lit = ((LiteralExpression) unary.inner).literal;
- if (lit is RealLiteral) {
- return -((RealLiteral) lit).value.to_double ();
- } else if (lit is IntegerLiteral) {
- return -((IntegerLiteral) lit).value.to_int ();
- }
+ if (unary.inner is RealLiteral) {
+ var lit = (RealLiteral) unary.inner;
+ return -lit.value.to_double ();
+ } else if (unary.inner is IntegerLiteral) {
+ var lit = (IntegerLiteral) unary.inner;
+ return -lit.value.to_int ();
}
}
}
// FIXME: use hash table
foreach (NamedArgument arg in args) {
if (arg.name == name) {
- if (arg.argument is LiteralExpression) {
- var lit = ((LiteralExpression) arg.argument).literal;
- if (lit is BooleanLiteral) {
- return ((BooleanLiteral) lit).value;
- }
+ var lit = arg.argument as BooleanLiteral;
+ if (lit != null) {
+ return lit.value;
}
}
}
/* valabooleanliteral.vala
*
- * Copyright (C) 2006-2007 Jürg Billeter
+ * Copyright (C) 2006-2008 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
return "false";
}
}
+
+ public override bool is_pure () {
+ return true;
+ }
}
/* valacharacterliteral.vala
*
- * Copyright (C) 2006-2007 Jürg Billeter, Raffaele Sandrini
+ * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
public unichar get_char () {
return value.next_char ().get_char ();
}
+
+ public override bool is_pure () {
+ return true;
+ }
}
return node;
}
- public LiteralExpression! create_literal_expression (Literal! literal, SourceReference source_reference = null) {
- var node = new LiteralExpression (literal, source_reference);
- node.code_binding = codegen.create_literal_expression_binding (node);
- return node;
- }
-
public ParenthesizedExpression! create_parenthesized_expression (Expression! inner, SourceReference source_reference) {
var node = new ParenthesizedExpression (inner, source_reference);
node.code_binding = codegen.create_parenthesized_expression_binding (node);
return null;
}
- public virtual CodeBinding create_literal_expression_binding (LiteralExpression! node) {
- return null;
- }
-
public virtual CodeBinding create_parenthesized_expression_binding (ParenthesizedExpression! node) {
return null;
}
public virtual void visit_null_literal (NullLiteral! lit) {
}
- /**
- * Visit operation called for literal expressions.
- *
- * @param expr a literal expression
- */
- public virtual void visit_literal_expression (LiteralExpression! expr) {
- }
-
/**
* Visit operation called for parenthesized expressions.
*
/* valaintegerliteral.vala
*
- * Copyright (C) 2006-2007 Jürg Billeter
+ * Copyright (C) 2006-2008 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
}
}
}
+
+ public override bool is_pure () {
+ return true;
+ }
}
/* valaliteral.vala
*
- * Copyright (C) 2006-2007 Jürg Billeter
+ * Copyright (C) 2006-2008 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
/**
* Base class for all literals in the source code.
*/
-public abstract class Vala.Literal : CodeNode {
- /**
- * Specifies the type of this literal.
- */
- public DataType static_type { get; set; }
+public abstract class Vala.Literal : Expression {
+ public override bool is_pure () {
+ return true;
+ }
}
+++ /dev/null
-/* valaliteralexpression.vala
- *
- * Copyright (C) 2006-2007 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
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Author:
- * Jürg Billeter <j@bitron.ch>
- */
-
-using GLib;
-
-/**
- * Represents a literal expression in the source code.
- */
-public class Vala.LiteralExpression : Expression {
- /**
- * The literal.
- */
- public Literal literal { get; construct; }
-
- /**
- * Creates a new literal expression.
- *
- * @param literal a literal
- * @param source reference to source code
- * @return newly created literal expression
- */
- public LiteralExpression (Literal! _literal, SourceReference source = null) {
- literal = _literal;
- source_reference = source;
- }
-
- public override void accept (CodeVisitor! visitor) {
- literal.accept (visitor);
-
- visitor.visit_literal_expression (this);
- }
-
- public override string! to_string () {
- return literal.to_string ();
- }
-
- public override bool is_pure () {
- return true;
- }
-}
/* valanullliteral.vala
*
- * Copyright (C) 2006-2007 Jürg Billeter
+ * Copyright (C) 2006-2008 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
public override string! to_string () {
return "null";
}
+
+ public override bool is_pure () {
+ return true;
+ }
}
/* valarealliteral.vala
*
- * Copyright (C) 2006 Jürg Billeter
+ * Copyright (C) 2006-2008 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
return "double";
}
+
+ public override bool is_pure () {
+ return true;
+ }
}
}
}
- private int create_sizes_from_initializer_list (InitializerList! il, int rank, Gee.List<LiteralExpression>! sl) {
- var init = new LiteralExpression (new IntegerLiteral (il.size.to_string (), il.source_reference), il.source_reference);
+ private int create_sizes_from_initializer_list (InitializerList! il, int rank, Gee.List<Literal>! sl) {
+ var init = new IntegerLiteral (il.size.to_string (), il.source_reference);
init.accept (this);
sl.add (init);
e.accept (this);
}
- var calc_sizes = new ArrayList<LiteralExpression> ();
+ var calc_sizes = new ArrayList<Literal> ();
if (initlist != null) {
initlist.expected_type = new ArrayType (expr.element_type, expr.rank, expr.source_reference);
initlist.expected_type.add_type_argument (expr.element_type);
expr.static_type = new NullType (expr.source_reference);
}
- public override void visit_literal_expression (LiteralExpression! expr) {
- expr.static_type = expr.literal.static_type;
- }
-
private DataType get_static_type_for_symbol (Symbol! sym) {
if (sym is Field) {
var f = (Field) sym;
}
if (diag && prev_arg != null) {
- var format_arg = prev_arg;
- if (format_arg is LiteralExpression) {
- var format_lit = (StringLiteral) ((LiteralExpression) format_arg).literal;
- format_lit.value = "\"%s:%d: %s".printf (Path.get_basename (expr.source_reference.file.filename), expr.source_reference.first_line, format_lit.value.offset (1));
+ var format_arg = prev_arg as StringLiteral;
+ if (format_arg != null) {
+ format_arg.value = "\"%s:%d: %s".printf (Path.get_basename (expr.source_reference.file.filename), expr.source_reference.first_line, format_arg.value.offset (1));
}
}
}
var old_value = new MemberAccess (ma.inner, ma.member_name, expr.inner.source_reference);
- var bin = new BinaryExpression (expr.operator == UnaryOperator.INCREMENT ? BinaryOperator.PLUS : BinaryOperator.MINUS, old_value, new LiteralExpression (new IntegerLiteral ("1")), expr.source_reference);
+ var bin = new BinaryExpression (expr.operator == UnaryOperator.INCREMENT ? BinaryOperator.PLUS : BinaryOperator.MINUS, old_value, new IntegerLiteral ("1"), expr.source_reference);
var assignment = context.create_assignment (ma, bin, AssignmentOperator.SIMPLE, expr.source_reference);
var parenthexp = new ParenthesizedExpression (assignment, expr.source_reference);
/* valastringliteral.vala
*
- * Copyright (C) 2006-2007 Jürg Billeter
+ * Copyright (C) 2006-2008 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
public override void accept (CodeVisitor! visitor) {
visitor.visit_string_literal (this);
}
+
+ public override bool is_pure () {
+ return true;
+ }
}