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

support namespace fields and public static class fields, fixes bug 464985

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

	* vala/valafield.vala, gobject/valacodegenerator.vala,
	  gobject/valacodegeneratorclass.vala: support namespace fields and
	  public static class fields, fixes bug 464985

svn path=/trunk/; revision=486
parent 7553dce0
2007-08-20 Jürg Billeter <j@bitron.ch>
* vala/valafield.vala, gobject/valacodegenerator.vala,
gobject/valacodegeneratorclass.vala: support namespace fields and
public static class fields, fixes bug 464985
2007-08-20 Raffaele Sandrini <raffaele@sandrini.ch>
* vala/valasemanticanalyzer.vala: enclose prefix increment and decrement unary
expressions transformend to binary expressions into parenthesis
* vala/valasemanticanalyzer.vala: enclose prefix increment and decrement
unary expressions transformend to binary expressions into parenthesis
2007-08-20 Jürg Billeter <j@bitron.ch>
......
......@@ -52,6 +52,7 @@ public class Vala.CodeGenerator : CodeVisitor {
CCodeFragment source_type_member_declaration;
CCodeFragment source_signal_marshaller_declaration;
CCodeFragment source_type_member_definition;
CCodeFragment class_init_fragment;
CCodeFragment instance_init_fragment;
CCodeFragment instance_dispose_fragment;
CCodeFragment source_signal_marshaller_definition;
......@@ -404,23 +405,42 @@ public class Vala.CodeGenerator : CodeVisitor {
st = instance_struct;
if (f.instance) {
lhs = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), f.get_cname ());
} else {
var cdecl = new CCodeDeclaration (f.type_reference.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator (f.get_cname ()));
header_type_member_declaration.append (cdecl);
cdecl = new CCodeDeclaration (f.type_reference.get_cname ());
var var_decl = new CCodeVariableDeclarator (f.get_cname ());
if (f.initializer != null) {
var init = (CCodeExpression) f.initializer.ccodenode;
if (is_constant_ccode_expression (init)) {
var_decl.initializer = init;
}
}
cdecl.add_declarator (var_decl);
source_type_member_declaration.append (cdecl);
lhs = new CCodeIdentifier (f.get_cname ());
}
} else if (f.access == MemberAccessibility.PRIVATE) {
if (f.instance) {
st = instance_priv_struct;
lhs = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), f.get_cname ());
} else {
if (f.parent_symbol is DataType) {
var t = (DataType) f.parent_symbol;
var cdecl = new CCodeDeclaration (f.type_reference.get_cname ());
var var_decl = new CCodeVariableDeclarator (f.get_cname ());
if (f.initializer != null) {
var_decl.initializer = (CCodeExpression) f.initializer.ccodenode;
var cdecl = new CCodeDeclaration (f.type_reference.get_cname ());
var var_decl = new CCodeVariableDeclarator (f.get_cname ());
if (f.initializer != null) {
var init = (CCodeExpression) f.initializer.ccodenode;
if (is_constant_ccode_expression (init)) {
var_decl.initializer = init;
}
cdecl.add_declarator (var_decl);
cdecl.modifiers = CCodeModifiers.STATIC;
source_type_member_declaration.append (cdecl);
}
cdecl.add_declarator (var_decl);
cdecl.modifiers = CCodeModifiers.STATIC;
source_type_member_declaration.append (cdecl);
lhs = new CCodeIdentifier (f.get_cname ());
}
}
......@@ -470,9 +490,26 @@ public class Vala.CodeGenerator : CodeVisitor {
ma.symbol_reference = f;
instance_dispose_fragment.append (new CCodeExpressionStatement (get_unref_expression (lhs, f.type_reference, ma)));
}
} else {
if (f.initializer != null) {
var rhs = (CCodeExpression) f.initializer.ccodenode;
if (!is_constant_ccode_expression (rhs)) {
if (f.parent_symbol is Class) {
class_init_fragment.append (new CCodeExpressionStatement (new CCodeAssignment (lhs, rhs)));
} else {
f.error = true;
Report.error (f.source_reference, "Non-constant field initializers not supported in this context");
return;
}
}
}
}
}
private bool is_constant_ccode_expression (CCodeExpression! cexpr) {
return (cexpr is CCodeConstant);
}
public override void visit_formal_parameter (FormalParameter! p) {
p.accept_children (this);
......
......@@ -32,6 +32,7 @@ public class Vala.CodeGenerator {
var old_type_struct = type_struct;
var old_instance_priv_struct = instance_priv_struct;
var old_prop_enum = prop_enum;
var old_class_init_fragment = class_init_fragment;
var old_instance_init_fragment = instance_init_fragment;
var old_instance_dispose_fragment = instance_dispose_fragment;
current_symbol = cl;
......@@ -47,6 +48,7 @@ public class Vala.CodeGenerator {
instance_priv_struct = new CCodeStruct ("_%sPrivate".printf (cl.get_cname ()));
prop_enum = new CCodeEnum ();
prop_enum.add_value ("%s_DUMMY_PROPERTY".printf (cl.get_upper_case_cname (null)), null);
class_init_fragment = new CCodeFragment ();
instance_init_fragment = new CCodeFragment ();
instance_dispose_fragment = new CCodeFragment ();
......@@ -149,6 +151,7 @@ public class Vala.CodeGenerator {
type_struct = old_type_struct;
instance_priv_struct = old_instance_priv_struct;
prop_enum = old_prop_enum;
class_init_fragment = old_class_init_fragment;
instance_init_fragment = old_instance_init_fragment;
instance_dispose_fragment = old_instance_dispose_fragment;
}
......@@ -285,6 +288,8 @@ public class Vala.CodeGenerator {
foreach (Signal sig in cl.get_signals ()) {
init_block.add_statement (new CCodeExpressionStatement (get_signal_creation (sig, cl)));
}
init_block.add_statement (class_init_fragment);
source_type_member_definition.append (class_init);
}
......
......@@ -99,7 +99,7 @@ public class Vala.Field : Member, Invokable, Lockable {
public string! get_cname () {
if (cname == null) {
if (!instance) {
cname = "%s_%s".printf (parent_symbol.get_lower_case_cname (null), name);
cname = parent_symbol.get_lower_case_cprefix () + name;
} else {
cname = name;
}
......
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