Commit 0899abe8 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

separate declaration output remove comma at end of enum remove unused

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

	* ccode/valaccodeblock.vala, ccode/valaccodedeclaration.vala,
	  ccode/valaccodedeclarator.vala, ccode/valaccodefragment.vala,
	  ccode/valaccodefunctiondeclarator.vala, ccode/valaccodenode.vala,
	  ccode/valaccodeoncesection.vala, ccode/valaccodestruct.vala,
	  ccode/valaccodetypedefinition.vala,
	  ccode/valaccodevariabledeclarator.vala: separate declaration output
	* vala/parser.y: remove comma at end of enum
	* vala/valaclass.vala, vala/valastruct.vala: remove unused methods
	* vala/Makefile.am: update
	* gobject/valacodegeneratorsourcefile.vala: support declaration
	  separation in C code
	* gobject/valaclassregisterfunction.vala,
	  gobject/valainterfaceregisterfunction.vala,
	  gobject/valatyperegisterfunction.vala: move from vala directory,
	  move interface info declarations to the beginning of the block
	* gobject/Makefile.am: update

svn path=/trunk/; revision=315
parent 8e156af4
2007-05-10 Jürg Billeter <j@bitron.ch>
* ccode/valaccodeblock.vala, ccode/valaccodedeclaration.vala,
ccode/valaccodedeclarator.vala, ccode/valaccodefragment.vala,
ccode/valaccodefunctiondeclarator.vala, ccode/valaccodenode.vala,
ccode/valaccodeoncesection.vala, ccode/valaccodestruct.vala,
ccode/valaccodetypedefinition.vala,
ccode/valaccodevariabledeclarator.vala: separate declaration output
* vala/parser.y: remove comma at end of enum
* vala/valaclass.vala, vala/valastruct.vala: remove unused methods
* vala/Makefile.am: update
* gobject/valacodegeneratorsourcefile.vala: support declaration
separation in C code
* gobject/valaclassregisterfunction.vala,
gobject/valainterfaceregisterfunction.vala,
gobject/valatyperegisterfunction.vala: move from vala directory,
move interface info declarations to the beginning of the block
* gobject/Makefile.am: update
2007-05-09 Jürg Billeter <j@bitron.ch>
* ccode/valaccodeenum.vala: remove comma at end of generated enumerator
......
/* valaccodeblock.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -51,6 +51,9 @@ public class Vala.CCodeBlock : CCodeStatement {
public override void write (CCodeWriter! writer) {
writer.write_begin_block ();
foreach (CCodeNode statement in statements) {
statement.write_declaration (writer);
}
foreach (CCodeNode statement in statements) {
statement.write (writer);
}
......
/* valaccodedeclaration.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -52,10 +52,39 @@ public class Vala.CCodeDeclaration : CCodeStatement {
}
public override void write (CCodeWriter! writer) {
writer.write_indent ();
if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) {
// combined declaration and initialization for static variables
writer.write_indent ();
writer.write_string ("static ");
writer.write_string (type_name);
writer.write_string (" ");
bool first = true;
foreach (CCodeDeclarator decl in declarators) {
if (!first) {
writer.write_string (", ");
} else {
first = false;
}
decl.write (writer);
}
writer.write_string (";");
writer.write_newline ();
} else {
foreach (CCodeDeclarator decl in declarators) {
decl.write_initialization (writer);
}
}
}
public override void write_declaration (CCodeWriter! writer) {
if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) {
// no separate declaration for static variables
return;
}
writer.write_indent ();
if ((modifiers & CCodeModifiers.REGISTER) == CCodeModifiers.REGISTER) {
writer.write_string ("register ");
}
......@@ -69,7 +98,7 @@ public class Vala.CCodeDeclaration : CCodeStatement {
} else {
first = false;
}
decl.write (writer);
decl.write_declaration (writer);
}
writer.write_string (";");
......
/* valaccodedeclarator.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -26,4 +26,12 @@ using GLib;
* Represents a variable or function pointer declarator in the C code.
*/
public abstract class Vala.CCodeDeclarator : CCodeNode {
/**
* Writes initialization statements for this declarator with the
* specified C code writer if necessary.
*
* @param writer a C code writer
*/
public virtual void write_initialization (CCodeWriter! writer) {
}
}
/* valaccodefragment.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -51,4 +51,10 @@ public class Vala.CCodeFragment : CCodeNode {
node.write (writer);
}
}
public override void write_declaration (CCodeWriter! writer) {
foreach (CCodeNode node in children) {
node.write_declaration (writer);
}
}
}
/* valaccodefunctiondeclarator.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -47,6 +47,10 @@ public class Vala.CCodeFunctionDeclarator : CCodeDeclarator {
}
public override void write (CCodeWriter! writer) {
write_declaration (writer);
}
public override void write_declaration (CCodeWriter! writer) {
writer.write_string ("(*");
writer.write_string (name);
writer.write_string (") (");
......
/* valaccodenode.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -39,4 +39,13 @@ public abstract class Vala.CCodeNode {
* @param writer a C code writer
*/
public abstract void write (CCodeWriter! writer);
/**
* Writes declaration for this code node with the specified C code
* writer if necessary.
*
* @param writer a C code writer
*/
public virtual void write_declaration (CCodeWriter! writer) {
}
}
/* valaccodeoncesection.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -43,6 +43,9 @@ public class Vala.CCodeOnceSection : CCodeFragment {
writer.write_string ("#define ");
writer.write_string (define);
writer.write_newline ();
foreach (CCodeNode node in get_children ()) {
node.write_declaration (writer);
}
foreach (CCodeNode node in get_children ()) {
node.write (writer);
}
......@@ -50,4 +53,7 @@ public class Vala.CCodeOnceSection : CCodeFragment {
writer.write_string ("#endif");
writer.write_newline ();
}
public override void write_declaration (CCodeWriter! writer) {
}
}
/* valaccodestruct.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -63,7 +63,7 @@ public class Vala.CCodeStruct : CCodeNode {
writer.write_string (name);
writer.write_begin_block ();
foreach (CCodeDeclaration decl in declarations) {
decl.write (writer);
decl.write_declaration (writer);
}
writer.write_end_block ();
writer.write_string (";");
......
/* valaccodetypedefinition.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -42,6 +42,9 @@ public class Vala.CCodeTypeDefinition : CCodeNode {
}
public override void write (CCodeWriter! writer) {
}
public override void write_declaration (CCodeWriter! writer) {
writer.write_indent ();
writer.write_string ("typedef ");
......@@ -49,7 +52,7 @@ public class Vala.CCodeTypeDefinition : CCodeNode {
writer.write_string (" ");
declarator.write (writer);
declarator.write_declaration (writer);
writer.write_string (";");
writer.write_newline ();
......
/* valaccodevariabledeclarator.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -44,13 +44,30 @@ public class Vala.CCodeVariableDeclarator : CCodeDeclarator {
name = _name;
initializer = init;
}
public override void write (CCodeWriter! writer) {
writer.write_string (name);
if (initializer != null) {
writer.write_string (" = ");
initializer.write (writer);
}
}
public override void write_declaration (CCodeWriter! writer) {
writer.write_string (name);
}
public override void write_initialization (CCodeWriter! writer) {
if (initializer != null) {
writer.write_indent ();
writer.write_string (name);
writer.write_string (" = ");
initializer.write (writer);
writer.write_string (";");
writer.write_newline ();
}
}
}
......@@ -12,6 +12,9 @@ lib_LTLIBRARIES = \
libvala_la_SOURCES = \
gobject.vala.stamp \
valaclassregisterfunction.c \
valaclassregisterfunction.h \
valaclassregisterfunction.vala \
valacodegenerator.c \
valacodegenerator.h \
valacodegenerator.vala \
......@@ -42,11 +45,18 @@ libvala_la_SOURCES = \
valacodegeneratorstruct.c \
valacodegeneratorstruct.h \
valacodegeneratorstruct.vala \
valainterfaceregisterfunction.c \
valainterfaceregisterfunction.h \
valainterfaceregisterfunction.vala \
valatyperegisterfunction.c \
valatyperegisterfunction.h \
valatyperegisterfunction.vala \
$(NULL)
gobjectincludedir = $(includedir)/vala-1.0/gobject
gobjectinclude_HEADERS = \
valaclassregisterfunction.h \
valacodegenerator.h \
valacodegeneratorassignment.h \
valacodegeneratorclass.h \
......@@ -57,6 +67,8 @@ gobjectinclude_HEADERS = \
valacodegeneratorsignal.h \
valacodegeneratorsourcefile.h \
valacodegeneratorstruct.h \
valainterfaceregisterfunction.h \
valatyperegisterfunction.h \
$(NULL)
gobject.vala gobject.vala.stamp: $(filter %.vala,$(libvala_la_SOURCES))
......
......@@ -77,7 +77,7 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
}
}
public override ref CCodeFragment! get_type_interface_init_statements () {
public override ref CCodeFragment! get_type_interface_init_declaration () {
var frag = new CCodeFragment ();
foreach (TypeReference base_type in class_reference.get_base_types ()) {
......@@ -93,6 +93,23 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
ctypedecl.modifiers = CCodeModifiers.STATIC;
ctypedecl.add_declarator (new CCodeVariableDeclarator.with_initializer (iface_info_name, new CCodeConstant ("{ (GInterfaceInitFunc) %s_%s_interface_init, (GInterfaceFinalizeFunc) NULL, NULL}".printf (class_reference.get_lower_case_cname (null), iface.get_lower_case_cname (null)))));
frag.append (ctypedecl);
}
return frag;
}
public override ref CCodeFragment! get_type_interface_init_statements () {
var frag = new CCodeFragment ();
foreach (TypeReference base_type in class_reference.get_base_types ()) {
if (!(base_type.data_type is Interface)) {
continue;
}
var iface = (Interface) base_type.data_type;
var iface_info_name = "%s_info".printf (iface.get_lower_case_cname (null));
var reg_call = new CCodeFunctionCall (new CCodeIdentifier ("g_type_add_interface_static"));
reg_call.add_argument (new CCodeIdentifier ("%s_type_id".printf (class_reference.get_lower_case_cname (null))));
reg_call.add_argument (new CCodeIdentifier (iface.get_upper_case_cname ("TYPE_")));
......
......@@ -159,6 +159,7 @@ public class Vala.CodeGenerator {
once.append (new CCodeIdentifier ("G_END_DECLS"));
once.append (new CCodeNewline ());
once.append (new CCodeNewline ());
once.write_declaration (writer);
once.write (writer);
writer.close ();
......@@ -170,8 +171,10 @@ public class Vala.CodeGenerator {
writer.write_newline ();
source_include_directives.write (writer);
writer.write_newline ();
source_type_member_declaration.write_declaration (writer);
source_type_member_declaration.write (writer);
writer.write_newline ();
source_signal_marshaller_declaration.write_declaration (writer);
source_signal_marshaller_declaration.write (writer);
writer.write_newline ();
source_type_member_definition.write (writer);
......
......@@ -68,6 +68,9 @@ public abstract class Vala.TypeRegisterFunction {
ctypedecl.modifiers = CCodeModifiers.STATIC;
ctypedecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("g_define_type_info", new CCodeConstant ("{ sizeof (%s), (GBaseInitFunc) %s, (GBaseFinalizeFunc) NULL, (GClassInitFunc) %s, (GClassFinalizeFunc) NULL, NULL, %s, 0, (GInstanceInitFunc) %s }".printf (get_type_struct_name (), get_base_init_func_name (), get_class_init_func_name (), get_instance_struct_size (), get_instance_init_func_name ()))));
type_init.add_statement (ctypedecl);
type_init.add_statement (get_type_interface_init_declaration ());
CCodeFunctionCall reg_call;
if (!plugin) {
reg_call = new CCodeFunctionCall (new CCodeIdentifier ("g_type_register_static"));
......@@ -159,6 +162,15 @@ public abstract class Vala.TypeRegisterFunction {
return "0";
}
/**
* Returns additional C declarations to setup interfaces.
*
* @return C declarations
*/
public virtual ref CCodeFragment! get_type_interface_init_declaration () {
return new CCodeFragment ();
}
/**
* Returns additional C initialization statements to setup interfaces.
*
......
......@@ -70,9 +70,6 @@ libvalacore_la_SOURCES = \
valaclass.c \
valaclass.h \
valaclass.vala \
valaclassregisterfunction.c \
valaclassregisterfunction.h \
valaclassregisterfunction.vala \
valacodecontext.c \
valacodecontext.h \
valacodecontext.vala \
......@@ -160,9 +157,6 @@ libvalacore_la_SOURCES = \
valainterface.c \
valainterface.h \
valainterface.vala \
valainterfaceregisterfunction.c \
valainterfaceregisterfunction.h \
valainterfaceregisterfunction.vala \
valainterfacewriter.c \
valainterfacewriter.h \
valainterfacewriter.vala \
......@@ -313,9 +307,6 @@ libvalacore_la_SOURCES = \
valatypereference.c \
valatypereference.h \
valatypereference.vala \
valatyperegisterfunction.c \
valatyperegisterfunction.h \
valatyperegisterfunction.vala \
valaunaryexpression.c \
valaunaryexpression.h \
valaunaryexpression.vala \
......@@ -347,7 +338,6 @@ valainclude_HEADERS = \
valacatchclause.h \
valacharacterliteral.h \
valaclass.h \
valaclassregisterfunction.h \
valacodecontext.h \
valacodenode.h \
valacodevisitor.h \
......@@ -377,7 +367,6 @@ valainclude_HEADERS = \
valainstancecast.h \
valaintegerliteral.h \
valainterface.h \
valainterfaceregisterfunction.h \
valainterfacewriter.h \
valainvocationexpression.h \
valainvokable.h \
......@@ -428,7 +417,6 @@ valainclude_HEADERS = \
valatypeofexpression.h \
valatypeparameter.h \
valatypereference.h \
valatyperegisterfunction.h \
valaunaryexpression.h \
valavariabledeclarator.h \
valawhilestatement.h \
......
......@@ -47,7 +47,7 @@ typedef enum {
VALA_MODIFIER_ABSTRACT = 1 << 0,
VALA_MODIFIER_OVERRIDE = 1 << 1,
VALA_MODIFIER_STATIC = 1 << 2,
VALA_MODIFIER_VIRTUAL = 1 << 3,
VALA_MODIFIER_VIRTUAL = 1 << 3
} ValaModifier;
int yylex (YYSTYPE *yylval_param, YYLTYPE *yylloc_param, ValaParser *parser);
......
......@@ -294,11 +294,7 @@ public class Vala.Class : DataType {
}
return lower_case_csuffix;
}
private void set_lower_case_csuffix (string! csuffix) {
this.lower_case_csuffix = csuffix;
}
public override ref string get_lower_case_cname (string infix) {
if (infix == null) {
infix = "";
......
......@@ -177,11 +177,7 @@ public class Vala.Struct : DataType {
}
return lower_case_csuffix;
}
private void set_lower_case_csuffix (string! csuffix) {
this.lower_case_csuffix = csuffix;
}
public override ref string get_lower_case_cname (string infix) {
if (infix == null) {
infix = "";
......@@ -369,6 +365,7 @@ public class Vala.Struct : DataType {
return "g_value_get_pointer";
} else {
Report.error (source_reference, "The value type `%s` doesn't declare a GValue get function".printf (symbol.get_full_name ()));
return null;
}
} else {
return get_value_function;
......@@ -381,6 +378,7 @@ public class Vala.Struct : DataType {
return "g_value_set_pointer";
} else {
Report.error (source_reference, "The value type `%s` doesn't declare a GValue set function".printf (symbol.get_full_name ()));
return null;
}
} else {
return set_value_function;
......
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