Commit 12da8411 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

add support for partial structs, patch by Mathias Hasselmann

2007-08-28  Juerg Billeter  <j@bitron.ch>

	* vala/parser.y: add support for partial structs,
	  patch by Mathias Hasselmann

	* vapigen/valagidlparser.vala: support partial structs and classes in
	  -custom.vala files, fixes bug 470855

	* vapi/gtk+-2.0.vala, vapi/packages/pango/pango-custom.vala,
	  vapi/pango.vala: updated

svn path=/trunk/; revision=516
parent b584d460
2007-08-28 Jürg Billeter <j@bitron.ch>
* vala/parser.y: add support for partial structs,
patch by Mathias Hasselmann
* vapigen/valagidlparser.vala: support partial structs and classes in
-custom.vala files, fixes bug 470855
* vapi/gtk+-2.0.vala, vapi/packages/pango/pango-custom.vala,
vapi/pango.vala: updated
2007-08-28 Jürg Billeter <j@bitron.ch>
* vapi/Makefile.am, vapi/glib-2.0.vala, vapi/math.vala: move math
......@@ -25,7 +36,7 @@
* vala/valacodenode.vala: include type-name in to_string result
* vala/valaunaryexpression.vala: implement to_string method,
fixes bug 470778
fixes bug 470778
2007-08-27 Jürg Billeter <j@bitron.ch>
......
......@@ -55,6 +55,7 @@ static ValaSymbol *pop_symbol (void);
static gboolean check_is_namespace (ValaSymbol *symbol, ValaSourceReference *src);
static gboolean check_is_class (ValaSymbol *symbol, ValaSourceReference *src);
static gboolean check_is_struct (ValaSymbol *symbol, ValaSourceReference *src);
%}
%defines
......@@ -72,7 +73,6 @@ static gboolean check_is_class (ValaSymbol *symbol, ValaSourceReference *src);
ValaExpression *expression;
ValaStatement *statement;
ValaBlock *block;
ValaStruct *struct_;
ValaInterface *interface;
ValaEnumValue *enum_value;
ValaConstant *constant;
......@@ -321,7 +321,6 @@ static gboolean check_is_class (ValaSymbol *symbol, ValaSourceReference *src);
%type <property_accessor> get_accessor_declaration
%type <property_accessor> opt_set_accessor_declaration
%type <property_accessor> set_accessor_declaration
%type <struct_> struct_header
%type <constant> constant_declaration
%type <field> field_declaration
%type <list> variable_declarators
......@@ -2229,7 +2228,6 @@ class_declaration
}
g_object_unref (parent_symbol);
push_symbol (current_symbol);
}
class_body
......@@ -2909,17 +2907,6 @@ destructor_declaration
;
struct_declaration
: struct_header
{
push_symbol (VALA_SYMBOL ($1));
}
struct_body
{
g_object_unref (pop_symbol ());
}
;
struct_header
: comment opt_attributes opt_access_modifier STRUCT identifier opt_name_specifier opt_type_parameter_list opt_class_base
{
GList *l;
......@@ -2953,35 +2940,47 @@ struct_header
}
src = src_com(@5, $1);
$$ = vala_struct_new (name, src);
g_free (name);
g_object_unref (src);
if (VALA_IS_CLASS (parent_symbol)) {
vala_class_add_struct (VALA_CLASS (parent_symbol), $$);
} else if (VALA_IS_NAMESPACE (parent_symbol)) {
vala_namespace_add_struct (VALA_NAMESPACE (parent_symbol), $$);
vala_source_file_add_node (current_source_file, VALA_CODE_NODE ($$));
ValaSymbol *current_symbol = vala_scope_lookup (parent_scope, name);
if (current_symbol != NULL) {
if (check_is_struct (current_symbol, src)) {
// merge class declarations
}
} else {
g_assert_not_reached ();
}
current_symbol = vala_struct_new (name, src);
g_free (name);
g_object_unref (src);
for (l = $7; l != NULL; l = l->next) {
vala_struct_add_type_parameter ($$, l->data);
}
VALA_CODE_NODE($$)->attributes = $2;
if ($3 != 0) {
VALA_DATA_TYPE($$)->access = $3;
}
if ($8 != NULL) {
for (l = $8; l != NULL; l = l->next) {
vala_struct_add_base_type ($$, l->data);
g_object_unref (l->data);
if (VALA_IS_CLASS (parent_symbol)) {
vala_class_add_struct (VALA_CLASS (parent_symbol), VALA_STRUCT (current_symbol));
} else if (VALA_IS_NAMESPACE (parent_symbol)) {
vala_namespace_add_struct (VALA_NAMESPACE (parent_symbol), VALA_STRUCT (current_symbol));
vala_source_file_add_node (current_source_file, VALA_CODE_NODE (current_symbol));
} else {
g_assert_not_reached ();
}
for (l = $7; l != NULL; l = l->next) {
vala_struct_add_type_parameter (VALA_STRUCT (current_symbol), l->data);
}
VALA_CODE_NODE(current_symbol)->attributes = $2;
if ($3 != 0) {
VALA_DATA_TYPE(current_symbol)->access = $3;
}
if ($8 != NULL) {
for (l = $8; l != NULL; l = l->next) {
vala_struct_add_base_type (VALA_STRUCT (current_symbol), l->data);
g_object_unref (l->data);
}
g_list_free ($8);
}
g_list_free ($8);
}
g_object_unref (parent_symbol);
push_symbol (current_symbol);
}
struct_body
{
g_object_unref (pop_symbol ());
}
;
......@@ -3603,3 +3602,14 @@ static gboolean check_is_class (ValaSymbol *symbol, ValaSourceReference *src) {
return TRUE;
}
static gboolean check_is_struct (ValaSymbol *symbol, ValaSourceReference *src) {
if (!VALA_IS_STRUCT (symbol)) {
char *sym_name = vala_symbol_get_full_name (symbol);
char *error_msg = g_strdup_printf ("`%s` already exists but is not a struct", sym_name);
g_free (sym_name);
vala_report_error (src, error_msg);
g_free (error_msg);
return FALSE;
}
return TRUE;
}
This diff is collapsed.
......@@ -21,6 +21,7 @@
*/
namespace Pango {
[ReferenceType]
public struct Language {
[Import ()]
public weak string! to_string ();
......
......@@ -374,6 +374,17 @@ namespace Pango {
}
[ReferenceType]
[CCode (cheader_filename = "pango/pango.h")]
public struct Language {
public weak string! to_string ();
public static weak Pango.Language from_string (string language);
public static weak Pango.Language get_default ();
public weak string get_sample_string ();
public static GLib.Type get_type ();
public bool includes_script (Pango.Script script);
public bool matches (string range_list);
}
[ReferenceType]
[CCode (cheader_filename = "pango/pango.h")]
public struct Analysis {
public weak Pango.EngineShape shape_engine;
public weak Pango.EngineLang lang_engine;
......@@ -621,17 +632,6 @@ namespace Pango {
public Item ();
public weak Pango.Item split (int split_index, int split_offset);
}
[ReferenceType]
[CCode (cheader_filename = "pango/pango.h")]
public struct Language {
public static weak Pango.Language from_string (string language);
public static weak Pango.Language get_default ();
public weak string get_sample_string ();
public static GLib.Type get_type ();
public bool includes_script (Pango.Script script);
public bool matches (string range_list);
public weak string! to_string ();
}
[ReferenceType (free_function = "pango_layout_iter_free")]
[CCode (cheader_filename = "pango/pango.h")]
public struct LayoutIter {
......
......@@ -188,37 +188,18 @@ public class Vala.GIdlParser : CodeVisitor {
ns.add_callback (cb);
current_source_file.add_node (cb);
} else if (node.type == IdlNodeTypeId.STRUCT) {
var st = parse_struct ((IdlNodeStruct) node);
if (st == null) {
continue;
}
st.name = fix_type_name (st.name, module);
ns.add_struct (st);
current_source_file.add_node (st);
parse_struct ((IdlNodeStruct) node, ns, module);
} else if (node.type == IdlNodeTypeId.BOXED) {
var st = parse_boxed ((IdlNodeBoxed) node);
st.name = fix_type_name (st.name, module);
ns.add_struct (st);
st.set_type_id (st.get_upper_case_cname ("TYPE_"));
current_source_file.add_node (st);
parse_boxed ((IdlNodeBoxed) node, ns, module);
} else if (node.type == IdlNodeTypeId.ENUM) {
var en = parse_enum ((IdlNodeEnum) node);
en.name = fix_type_name (en.name, module);
ns.add_enum (en);
current_source_file.add_node (en);
} else if (node.type == IdlNodeTypeId.OBJECT) {
var cl = parse_object ((IdlNodeInterface) node);
if (cl == null) {
continue;
}
cl.name = fix_type_name (cl.name, module);
ns.add_class (cl);
current_source_file.add_node (cl);
parse_object ((IdlNodeInterface) node, ns, module);
} else if (node.type == IdlNodeTypeId.INTERFACE) {
var iface = parse_interface ((IdlNodeInterface) node);
iface.name = fix_type_name (iface.name, module);
ns.add_interface (iface);
current_source_file.add_node (iface);
parse_interface ((IdlNodeInterface) node, ns, module);
} else if (node.type == IdlNodeTypeId.CONSTANT) {
var c = parse_constant ((IdlNodeConstant) node);
c.name = fix_const_name (c.name, module);
......@@ -270,34 +251,42 @@ public class Vala.GIdlParser : CodeVisitor {
return cb;
}
private Struct parse_struct (IdlNodeStruct! st_node) {
private void parse_struct (IdlNodeStruct! st_node, Namespace! ns, IdlModule! module) {
weak IdlNode node = (IdlNode) st_node;
if (st_node.deprecated) {
return null;
return;
}
var st = new Struct (node.name, current_source_reference);
st.access = MemberAccessibility.PUBLIC;
st.set_is_reference_type (true);
var st_attributes = get_attributes (node.name);
if (st_attributes != null) {
foreach (string attr in st_attributes) {
var nv = attr.split ("=", 2);
if (nv[0] == "cheader_filename") {
st.add_cheader_filename (eval (nv[1]));
} else if (nv[0] == "is_value_type" && eval (nv[1]) == "1") {
st.set_is_reference_type (false);
} else if (nv[0] == "hidden") {
if (eval (nv[1]) == "1") {
return null;
string name = fix_type_name (node.name, module);
var st = ns.scope.lookup (name) as Struct;
if (st == null) {
st = new Struct (name, current_source_reference);
st.access = MemberAccessibility.PUBLIC;
st.set_is_reference_type (true);
var st_attributes = get_attributes (node.name);
if (st_attributes != null) {
foreach (string attr in st_attributes) {
var nv = attr.split ("=", 2);
if (nv[0] == "cheader_filename") {
st.add_cheader_filename (eval (nv[1]));
} else if (nv[0] == "is_value_type" && eval (nv[1]) == "1") {
st.set_is_reference_type (false);
} else if (nv[0] == "hidden") {
if (eval (nv[1]) == "1") {
return;
}
}
}
}
ns.add_struct (st);
current_source_file.add_node (st);
}
current_data_type = st;
string ref_function = null;
......@@ -336,28 +325,35 @@ public class Vala.GIdlParser : CodeVisitor {
}
current_data_type = null;
return st;
}
private Struct parse_boxed (IdlNodeBoxed! boxed_node) {
private void parse_boxed (IdlNodeBoxed! boxed_node, Namespace! ns, IdlModule! module) {
weak IdlNode node = (IdlNode) boxed_node;
var st = new Struct (node.name, current_source_reference);
st.access = MemberAccessibility.PUBLIC;
string name = fix_type_name (node.name, module);
st.set_is_reference_type (true);
var st = ns.scope.lookup (name) as Struct;
if (st == null) {
st = new Struct (name, current_source_reference);
st.access = MemberAccessibility.PUBLIC;
var st_attributes = get_attributes (node.name);
if (st_attributes != null) {
foreach (string attr in st_attributes) {
var nv = attr.split ("=", 2);
if (nv[0] == "cheader_filename") {
st.add_cheader_filename (eval (nv[1]));
} else if (nv[0] == "is_value_type" && eval (nv[1]) == "1") {
st.set_is_reference_type (false);
st.set_is_reference_type (true);
var st_attributes = get_attributes (node.name);
if (st_attributes != null) {
foreach (string attr in st_attributes) {
var nv = attr.split ("=", 2);
if (nv[0] == "cheader_filename") {
st.add_cheader_filename (eval (nv[1]));
} else if (nv[0] == "is_value_type" && eval (nv[1]) == "1") {
st.set_is_reference_type (false);
}
}
}
ns.add_struct (st);
st.set_type_id (st.get_upper_case_cname ("TYPE_"));
current_source_file.add_node (st);
}
current_data_type = st;
......@@ -398,8 +394,6 @@ public class Vala.GIdlParser : CodeVisitor {
}
current_data_type = null;
return st;
}
private Enum parse_enum (IdlNodeEnum! en_node) {
......@@ -439,24 +433,32 @@ public class Vala.GIdlParser : CodeVisitor {
return en;
}
private Class parse_object (IdlNodeInterface! node) {
var cl = new Class (node.gtype_name, current_source_reference);
cl.access = MemberAccessibility.PUBLIC;
var attributes = get_attributes (cl.name);
if (attributes != null) {
foreach (string attr in attributes) {
var nv = attr.split ("=", 2);
if (nv[0] == "cheader_filename") {
cl.add_cheader_filename (eval (nv[1]));
} else if (nv[0] == "hidden") {
if (eval (nv[1]) == "1") {
return null;
private void parse_object (IdlNodeInterface! node, Namespace! ns, IdlModule! module) {
string name = fix_type_name (node.gtype_name, module);
var cl = ns.scope.lookup (name) as Class;
if (cl == null) {
cl = new Class (name, current_source_reference);
cl.access = MemberAccessibility.PUBLIC;
var attributes = get_attributes (node.gtype_name);
if (attributes != null) {
foreach (string attr in attributes) {
var nv = attr.split ("=", 2);
if (nv[0] == "cheader_filename") {
cl.add_cheader_filename (eval (nv[1]));
} else if (nv[0] == "hidden") {
if (eval (nv[1]) == "1") {
return;
}
}
}
}
ns.add_class (cl);
current_source_file.add_node (cl);
}
if (node.parent != null) {
var parent = new TypeReference ();
parse_type_string (parent, node.parent);
......@@ -528,28 +530,34 @@ public class Vala.GIdlParser : CodeVisitor {
current_data_type = null;
current_type_symbol_set = null;
return cl;
}
private Interface parse_interface (IdlNodeInterface! node) {
var iface = new Interface (node.gtype_name, current_source_reference);
iface.access = MemberAccessibility.PUBLIC;
var attributes = get_attributes (iface.name);
if (attributes != null) {
foreach (string attr in attributes) {
var nv = attr.split ("=", 2);
if (nv[0] == "cheader_filename") {
iface.add_cheader_filename (eval (nv[1]));
private void parse_interface (IdlNodeInterface! node, Namespace! ns, IdlModule! module) {
string name = fix_type_name (node.gtype_name, module);
var iface = ns.scope.lookup (name) as Interface;
if (iface == null) {
iface = new Interface (name, current_source_reference);
iface.access = MemberAccessibility.PUBLIC;
var attributes = get_attributes (node.gtype_name);
if (attributes != null) {
foreach (string attr in attributes) {
var nv = attr.split ("=", 2);
if (nv[0] == "cheader_filename") {
iface.add_cheader_filename (eval (nv[1]));
}
}
}
}
foreach (string prereq_name in node.prerequisites) {
var prereq = new TypeReference ();
parse_type_string (prereq, prereq_name);
iface.add_prerequisite (prereq);
foreach (string prereq_name in node.prerequisites) {
var prereq = new TypeReference ();
parse_type_string (prereq, prereq_name);
iface.add_prerequisite (prereq);
}
ns.add_interface (iface);
current_source_file.add_node (iface);
}
current_data_type = iface;
......@@ -578,8 +586,6 @@ public class Vala.GIdlParser : CodeVisitor {
}
current_data_type = null;
return iface;
}
private TypeReference parse_type (IdlNodeType! type_node) {
......@@ -830,7 +836,7 @@ public class Vala.GIdlParser : CodeVisitor {
}
if (current_data_type != null) {
var sig_attributes = get_attributes ("%s::%s".printf (current_data_type.name, node.name));
var sig_attributes = get_attributes ("%s::%s".printf (current_data_type.get_cname (), node.name));
if (sig_attributes != null) {
foreach (string attr in sig_attributes) {
var nv = attr.split ("=", 2);
......@@ -880,7 +886,7 @@ public class Vala.GIdlParser : CodeVisitor {
if (current_data_type != null &&
param.type.is_interface &&
(param_node.name == "self" ||
param.type.@interface.has_suffix (current_data_type.name))) {
param.type.@interface.has_suffix (current_data_type.get_cname ()))) {
// instance method
if (!current_data_type.is_reference_type () &&
......@@ -988,7 +994,7 @@ public class Vala.GIdlParser : CodeVisitor {
prop.access = MemberAccessibility.PUBLIC;
prop.interface_only = true;
var attributes = get_attributes ("%s:%s".printf (current_data_type.name, node.name));
var attributes = get_attributes ("%s:%s".printf (current_data_type.get_cname (), node.name));
if (attributes != null) {
foreach (string attr in attributes) {
var nv = attr.split ("=", 2);
......@@ -1032,7 +1038,7 @@ public class Vala.GIdlParser : CodeVisitor {
return null;
}
var attributes = get_attributes ("%s.%s".printf (current_data_type.name, node.name));
var attributes = get_attributes ("%s.%s".printf (current_data_type.get_cname (), node.name));
if (attributes != null) {
foreach (string attr in attributes) {
var nv = attr.split ("=", 2);
......@@ -1086,7 +1092,7 @@ public class Vala.GIdlParser : CodeVisitor {
var sig = new Signal (fix_prop_name (node.name), parse_param (sig_node.result), current_source_reference);
sig.access = MemberAccessibility.PUBLIC;
var attributes = get_attributes ("%s::%s".printf (current_data_type.name, sig.name));
var attributes = get_attributes ("%s::%s".printf (current_data_type.get_cname (), sig.name));
if (attributes != null) {
foreach (string attr in attributes) {
var nv = attr.split ("=", 2);
......
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