Commit 98a267b2 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Add CCodeStructModule

2008-10-24  Jürg Billeter  <j@bitron.ch>

	* gobject/Makefile.am:
	* gobject/valaccodegenerator.vala:
	* gobject/valaccodemodule.vala:
	* gobject/valaccodestructmodule.vala:

	Add CCodeStructModule

svn path=/trunk/; revision=1899
parent bfbe0588
2008-10-24 Jürg Billeter <j@bitron.ch>
* gobject/Makefile.am:
* gobject/valaccodegenerator.vala:
* gobject/valaccodemodule.vala:
* gobject/valaccodestructmodule.vala:
Add CCodeStructModule
2008-10-24 Jürg Billeter <j@bitron.ch>
* gobject/Makefile.am:
......
......@@ -21,11 +21,11 @@ libvala_la_VALASOURCES = \
valaccodeelementaccessmodule.vala \
valaccodegenerator.vala \
valaccodegeneratorsourcefile.vala \
valaccodegeneratorstruct.vala \
valaccodeinvocationexpressionmodule.vala \
valaccodememberaccessmodule.vala \
valaccodemethodmodule.vala \
valaccodemodule.vala \
valaccodestructmodule.vala \
valaclassregisterfunction.vala \
valadbusmodule.vala \
valagirwriter.vala \
......
......@@ -142,6 +142,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
public CCodeGenerator () {
head = new CCodeBaseModule (this, head);
head = new CCodeStructModule (this, head);
head = new CCodeMethodModule (this, head);
head = new CCodeMemberAccessModule (this, head);
head = new CCodeElementAccessModule (this, head);
......@@ -308,6 +309,10 @@ public class Vala.CCodeGenerator : CodeGenerator {
head.visit_interface (iface);
}
public override void visit_struct (Struct st) {
head.visit_struct (st);
}
public override void visit_enum (Enum en) {
cenum = new CCodeEnum (en.get_cname ());
......
......@@ -60,6 +60,10 @@ public abstract class Vala.CCodeModule {
next.visit_interface (iface);
}
public virtual void visit_struct (Struct st) {
next.visit_struct (st);
}
public virtual void visit_method (Method m) {
next.visit_method (m);
}
......
/* valaccodegeneratorstruct.vala
/* valaccodestructmodule.vala
*
* Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini
*
......@@ -23,23 +23,27 @@
using GLib;
public class Vala.CCodeGenerator {
public class Vala.CCodeStructModule : CCodeModule {
public CCodeStructModule (CCodeGenerator codegen, CCodeModule? next) {
base (codegen, next);
}
public override void visit_struct (Struct st) {
var old_type_symbol = current_type_symbol;
var old_instance_struct = instance_struct;
var old_instance_finalize_fragment = instance_finalize_fragment;
current_type_symbol = st;
instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
instance_finalize_fragment = new CCodeFragment ();
var old_type_symbol = codegen.current_type_symbol;
var old_instance_struct = codegen.instance_struct;
var old_instance_finalize_fragment = codegen.instance_finalize_fragment;
codegen.current_type_symbol = st;
codegen.instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
codegen.instance_finalize_fragment = new CCodeFragment ();
CCodeFragment decl_frag;
CCodeFragment def_frag;
if (st.access != SymbolAccessibility.PRIVATE) {
decl_frag = header_type_declaration;
def_frag = header_type_definition;
decl_frag = codegen.header_type_declaration;
def_frag = codegen.header_type_definition;
} else {
decl_frag = source_type_declaration;
def_frag = source_type_definition;
decl_frag = codegen.source_type_declaration;
def_frag = codegen.source_type_definition;
}
if (st.source_reference.file.cycle == null) {
......@@ -49,18 +53,18 @@ public class Vala.CCodeGenerator {
if (st.source_reference.comment != null) {
def_frag.append (new CCodeComment (st.source_reference.comment));
}
def_frag.append (instance_struct);
def_frag.append (codegen.instance_struct);
st.accept_children (this);
st.accept_children (codegen);
if (st.is_disposable ()) {
add_struct_copy_function (st);
add_struct_destroy_function (st);
}
current_type_symbol = old_type_symbol;
instance_struct = old_instance_struct;
instance_finalize_fragment = old_instance_finalize_fragment;
codegen.current_type_symbol = old_type_symbol;
codegen.instance_struct = old_instance_struct;
codegen.instance_finalize_fragment = old_instance_finalize_fragment;
}
void add_struct_copy_function (Struct st) {
......@@ -73,16 +77,16 @@ public class Vala.CCodeGenerator {
function.add_parameter (new CCodeFormalParameter ("dest", st.get_cname () + "*"));
if (st.access != SymbolAccessibility.PRIVATE) {
header_type_member_declaration.append (function.copy ());
codegen.header_type_member_declaration.append (function.copy ());
} else {
source_type_member_declaration.append (function.copy ());
codegen.source_type_member_declaration.append (function.copy ());
}
var cblock = new CCodeBlock ();
function.block = cblock;
source_type_member_definition.append (function);
codegen.source_type_member_definition.append (function);
}
void add_struct_destroy_function (Struct st) {
......@@ -94,18 +98,18 @@ public class Vala.CCodeGenerator {
function.add_parameter (new CCodeFormalParameter ("self", st.get_cname () + "*"));
if (st.access != SymbolAccessibility.PRIVATE) {
header_type_member_declaration.append (function.copy ());
codegen.header_type_member_declaration.append (function.copy ());
} else {
source_type_member_declaration.append (function.copy ());
codegen.source_type_member_declaration.append (function.copy ());
}
var cblock = new CCodeBlock ();
cblock.add_statement (instance_finalize_fragment);
cblock.add_statement (codegen.instance_finalize_fragment);
function.block = cblock;
source_type_member_definition.append (function);
codegen.source_type_member_definition.append (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