Commit c9f266a1 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

support sizeof expression update add struct_size param to GLib.Source

2007-05-31  Jürg Billeter  <j@bitron.ch>

	* vala/scanner.l, vala/parser.y, vala/valasemanticanalyzer.vala,
	  vala/valacodevisitor.vala, vala/valasizeofexpression.vala,
	  gobject/valacodegenerator.vala: support sizeof expression
	* vala/vala.h, vala/Makefile.am: update
	* vapi/glib-2.0.vala: add struct_size param to GLib.Source construction
	  method

svn path=/trunk/; revision=317
parent 04e86121
2007-05-31 Jürg Billeter <j@bitron.ch>
* vala/scanner.l, vala/parser.y, vala/valasemanticanalyzer.vala,
vala/valacodevisitor.vala, vala/valasizeofexpression.vala,
gobject/valacodegenerator.vala: support sizeof expression
* vala/vala.h, vala/Makefile.am: update
* vapi/glib-2.0.vala: add struct_size param to GLib.Source construction
method
2007-05-14 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: improve argument checks of invocation
......
......@@ -1897,6 +1897,12 @@ public class Vala.CodeGenerator : CodeVisitor {
visit_expression (expr);
}
public override void visit_sizeof_expression (SizeofExpression! expr) {
var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
csizeof.add_argument (new CCodeIdentifier (expr.type_reference.data_type.get_cname ()));
expr.ccodenode = csizeof;
}
public override void visit_typeof_expression (TypeofExpression! expr) {
expr.ccodenode = new CCodeIdentifier (expr.type_reference.data_type.get_type_id ());
}
......
......@@ -253,6 +253,9 @@ libvalacore_la_SOURCES = \
valasignal.c \
valasignal.h \
valasignal.vala \
valasizeofexpression.c \
valasizeofexpression.h \
valasizeofexpression.vala \
valasourcefile.c \
valasourcefile.h \
valasourcefile.vala \
......@@ -399,6 +402,7 @@ valainclude_HEADERS = \
valareturnstatement.h \
valasemanticanalyzer.h \
valasignal.h \
valasizeofexpression.h \
valasourcefile.h \
valasourcefilecycle.h \
valasourcereference.h \
......
......@@ -187,6 +187,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
%token RETURN "return"
%token SET "set"
%token SIGNAL "signal"
%token SIZEOF "sizeof"
%token STATIC "static"
%token STRUCT "struct"
%token SWITCH "switch"
......@@ -240,6 +241,7 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
%type <expression> post_increment_expression
%type <expression> post_decrement_expression
%type <expression> object_creation_expression
%type <expression> sizeof_expression
%type <expression> typeof_expression
%type <expression> unary_expression
%type <expression> pre_increment_expression
......@@ -700,6 +702,7 @@ primary_no_array_creation_expression
| post_increment_expression
| post_decrement_expression
| object_creation_expression
| sizeof_expression
| typeof_expression
;
......@@ -857,6 +860,15 @@ object_creation_expression
}
;
sizeof_expression
: SIZEOF open_parens type_name CLOSE_PARENS
{
ValaSourceReference *src = src(@1);
$$ = VALA_EXPRESSION (vala_sizeof_expression_new ($3, src));
g_object_unref ($3);
g_object_unref (src);
}
typeof_expression
: TYPEOF open_parens type_name CLOSE_PARENS
{
......
......@@ -163,6 +163,7 @@ literal ({integer_literal}|{real_literal}|{character_literal}|{string_literal
"ref" { uploc; return REF; }
"set" { uploc; return SET; }
"signal" { uploc; return SIGNAL; }
"sizeof" { uploc; return SIZEOF; }
"static" { uploc; return STATIC; }
"struct" { uploc; return STRUCT; }
"switch" { uploc; return SWITCH; }
......
......@@ -61,6 +61,7 @@
#include <vala/valareport.h>
#include <vala/valareturnstatement.h>
#include <vala/valasignal.h>
#include <vala/valasizeofexpression.h>
#include <vala/valasourcefile.h>
#include <vala/valasourcereference.h>
#include <vala/valastringliteral.h>
......
......@@ -724,6 +724,14 @@ public abstract class Vala.CodeVisitor {
public virtual void visit_end_object_creation_expression (ObjectCreationExpression! expr) {
}
/**
* Visit operation called for sizeof expressions.
*
* @param expr a sizeof expression
*/
public virtual void visit_sizeof_expression (SizeofExpression! expr) {
}
/**
* Visit operation called for typeof expressions.
*
......
......@@ -45,6 +45,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
TypeReference string_type;
TypeReference int_type;
TypeReference uint_type;
TypeReference ulong_type;
TypeReference type_type;
DataType pointer_type;
DataType initially_unowned_type;
......@@ -79,6 +80,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
uint_type = new TypeReference ();
uint_type.data_type = (DataType) root_symbol.lookup ("uint").node;
ulong_type = new TypeReference ();
ulong_type.data_type = (DataType) root_symbol.lookup ("ulong").node;
// TODO: don't require GLib namespace in semantic analyzer
var glib_ns = root_symbol.lookup ("GLib");
if (glib_ns != null) {
......@@ -1550,6 +1554,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
}
public override void visit_sizeof_expression (SizeofExpression! expr) {
expr.static_type = ulong_type;
}
public override void visit_typeof_expression (TypeofExpression! expr) {
expr.static_type = type_type;
}
......
/* valasizeofexpression.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 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 sizeof expression in the source code.
*/
public class Vala.SizeofExpression : Expression {
/**
* The type whose size to be retrieved.
*/
public TypeReference! type_reference { get; set construct; }
/**
* Creates a new sizeof expression.
*
* @param type a data type
* @param source reference to source code
* @return newly created sizeof expression
*/
public SizeofExpression (TypeReference! type, SourceReference source) {
type_reference = type;
source_reference = source;
}
public override void accept (CodeVisitor! visitor) {
type_reference.accept (visitor);
visitor.visit_sizeof_expression (this);
}
}
......@@ -712,7 +712,7 @@ namespace GLib {
[ReferenceType (dup_function = "g_source_ref", free_function = "g_source_unref")]
public struct Source {
public Source (SourceFuncs source_funcs);
public Source (SourceFuncs source_funcs, uint struct_size /* = sizeof (Source) */);
public void set_funcs (SourceFuncs funcs);
public uint attach (MainContext context);
public void destroy ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment