+2006-06-26 Jürg Billeter <j@bitron.ch>
+
+ * vala/parser.y: plug some memory leaks, adapt to Vala.Block changes
+ * vala/valaattribute.vala, vala/valabinaryexpression.vala,
+ vala/valablock.vala, vala/valabooleanexpression.vala,
+ vala/valabreakstatement.vala, vala/valaliteral.vala,
+ vala/valastatement.vala: replace public fields by properties / private
+ fields, don't mark properties as construct-only, use non-null types
+ * vala/valadatatype.vala: renamed from Vala.Type_ to Vala.DataType
+ * vala/valasymbolbuilder.vala, vala/valasymbolresolver.vala,
+ vala/valasemanticanalyzer.vala, vala/valacodegenerator.vala,
+ vala/valasourcefile.vala, vala/valacallback.vala, vala/valaclass.vala,
+ vala/valaclassregisterfunction.vala, vala/valaconstant.vala,
+ vala/valaenum.vala, vala/valaflags.vala, vala/valainstancecast.vala,
+ vala/valainterface.vala, vala/valainterfaceregisterfunction.vala,
+ vala/valamethod.vala, vala/valastruct.vala,
+ vala/valatypeparameter.vala, vala/valatypereference.vala,
+ vala/valatypergisterfunction.vala: adapt to renaming of Vala.Type_ to
+ Vala.DataType
+ * vala/Makefile.am: update
+
2006-06-22 Jürg Billeter <j@bitron.ch>
* vala/valaassignment.vala: don't mark properties as construct-only,
valacontinuestatement.c \
valacontinuestatement.h \
valacontinuestatement.vala \
+ valadatatype.c \
+ valadatatype.h \
+ valadatatype.vala \
valadeclarationstatement.c \
valadeclarationstatement.h \
valadeclarationstatement.vala \
valasymbolresolver.c \
valasymbolresolver.h \
valasymbolresolver.vala \
- valatype.c \
- valatype.h \
- valatype.vala \
valatypecheck.c \
valatypecheck.h \
valatypecheck.vala \
vala_type_reference_add_type_argument ($$, l->data);
g_object_unref (l->data);
}
+ g_list_free ($2);
}
| IDENTIFIER DOT IDENTIFIER opt_type_argument_list
{
vala_type_reference_add_type_argument ($$, l->data);
g_object_unref (l->data);
}
+ g_list_free ($4);
}
;
: OPEN_BRACE opt_statement_list CLOSE_BRACE
{
ValaSourceReference *src = src(@1);
- $$ = VALA_STATEMENT (vala_block_new ($2, src));
+ $$ = VALA_STATEMENT (vala_block_new (src));
if ($2 != NULL) {
+ GList *l;
+ for (l = $2; l != NULL; l = l->next) {
+ vala_block_add_statement (VALA_BLOCK ($$), l->data);
+ g_object_unref (l->data);
+ }
g_list_free ($2);
}
g_object_unref (src);
vala_type_reference_add_type_argument ($$, l->data);
g_object_unref (l->data);
}
+ g_list_free ($2);
g_object_unref ($1);
}
| REF primary_expression opt_type_argument_list opt_op_neg
vala_type_reference_add_type_argument ($$, l->data);
g_object_unref (l->data);
}
+ g_list_free ($3);
g_object_unref ($2);
}
| local_variable_type array_qualifier
VALA_CODE_NODE(current_class)->attributes = $2;
if ($3 != 0) {
- VALA_TYPE_(current_class)->access = $3;
+ VALA_DATA_TYPE(current_class)->access = $3;
}
for (l = $7; l != NULL; l = l->next) {
vala_class_add_type_parameter (current_class, l->data);
}
VALA_CODE_NODE($$)->attributes = $2;
if ($3 != 0) {
- VALA_TYPE_($$)->access = $3;
+ VALA_DATA_TYPE($$)->access = $3;
}
g_free ($5);
VALA_CODE_NODE($$)->attributes = $2;
if ($3 != 0) {
- VALA_TYPE_($$)->access = $3;
+ VALA_DATA_TYPE($$)->access = $3;
}
for (l = $6; l != NULL; l = l->next) {
vala_enum_add_value ($$, l->data);
$$ = vala_callback_new ($6, $5, src);
g_object_unref (src);
if ($3 != 0) {
- VALA_TYPE_($$)->access = $3;
+ VALA_DATA_TYPE($$)->access = $3;
}
VALA_CODE_NODE($$)->attributes = $2;
namespace Vala {
public class Attribute : CodeNode {
- public string name { get; construct; }
- public SourceReference source_reference { get; construct; }
+ public string! name { get; set construct; }
+ public SourceReference source_reference { get; set; }
public List<NamedArgument> args;
- public static ref Attribute new (string name, SourceReference source) {
+ public static ref Attribute! new (string! name, SourceReference source) {
return (new Attribute (name = name, source_reference = source));
}
- public void add_argument (NamedArgument arg) {
+ public void add_argument (NamedArgument! arg) {
args.append (arg);
}
}
namespace Vala {
public class BinaryExpression : Expression {
- public BinaryOperator operator { get; construct; }
- public Expression left { get; construct; }
- public Expression right { get; construct; }
+ public BinaryOperator operator { get; set construct; }
+ public Expression! left { get; set construct; }
+ public Expression! right { get; set construct; }
- public static ref BinaryExpression new (BinaryOperator op, Expression left, Expression right, SourceReference source) {
+ public static ref BinaryExpression! new (BinaryOperator op, Expression! left, Expression! right, SourceReference source) {
return (new BinaryExpression (operator = op, left = left, right = right, source_reference = source));
}
- public override void accept (CodeVisitor visitor) {
+ public override void accept (CodeVisitor! visitor) {
left.accept (visitor);
right.accept (visitor);
namespace Vala {
public class Block : Statement {
- public List<Statement> statement_list { get; construct; }
- public bool contains_jump_statement;
+ private List<Statement> statement_list;
+ public bool contains_jump_statement { get; set; }
private List<VariableDeclarator> local_variables;
- public static ref Block new (List<Statement> statement_list, SourceReference source) {
- return (new Block (statement_list = statement_list, source_reference = source));
+ public static ref Block! new (SourceReference source) {
+ return (new Block (source_reference = source));
}
public void add_statement (Statement! stmt) {
- _statement_list.append (stmt);
+ statement_list.append (stmt);
+ }
+
+ public ref List<Statement> get_statements () {
+ return statement_list;
}
public void add_local_variable (VariableDeclarator! decl) {
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_block (this);
- foreach (Statement stmt in statement_list) {
+ foreach (Statement! stmt in statement_list) {
stmt.accept (visitor);
}
namespace Vala {
public class BooleanLiteral : Literal {
- public bool value { get; construct; }
- public SourceReference source_reference { get; construct; }
+ public bool value { get; set; }
+ public SourceReference source_reference { get; set; }
- public static ref BooleanLiteral new (bool b, SourceReference source) {
+ public static ref BooleanLiteral! new (bool b, SourceReference source) {
return (new BooleanLiteral (value = b, source_reference = source));
}
- public override void accept (CodeVisitor visitor) {
+ public override void accept (CodeVisitor! visitor) {
visitor.visit_boolean_literal (this);
}
}
namespace Vala {
public class BreakStatement : Statement {
- public static ref BreakStatement new (SourceReference source) {
+ public static ref BreakStatement! new (SourceReference source) {
return (new BreakStatement (source_reference = source));
}
- public override void accept (CodeVisitor visitor) {
+ public override void accept (CodeVisitor! visitor) {
visitor.visit_break_statement (this);
}
}
using GLib;
namespace Vala {
- public class Callback : Type_ {
+ public class Callback : DataType {
public TypeReference return_type { get; construct; }
public List<FormalParameter> parameters;
using GLib;
namespace Vala {
- public class Class : Type_ {
+ public class Class : DataType {
List<string> type_parameters;
public List<TypeReference> base_types;
public Class base_class;
if (lit is StringLiteral) {
var val = ((StringLiteral) lit).eval ();
foreach (string filename in val.split (",")) {
- cheader_filenames.append (filename);
+ add_cheader_filename (filename);
}
}
}
public class ClassRegisterFunction : TypeRegisterFunction {
public Class class_reference { get; construct; }
- public override Type_ get_type_declaration () {
+ public override DataType get_type_declaration () {
return class_reference;
}
}
public override void visit_constant (Constant! c) {
- if (c.symbol.parent_symbol.node is Type_) {
- var t = (Type_) c.symbol.parent_symbol.node;
+ if (c.symbol.parent_symbol.node is DataType) {
+ var t = (DataType) c.symbol.parent_symbol.node;
var cdecl = new CCodeDeclaration (type_name = c.type_reference.get_const_cname ());
var arr = "";
if (c.type_reference.array) {
if (f.instance) {
instance_priv_struct.add_field (f.type_reference.get_cname (), f.get_cname ());
} else {
- if (f.symbol.parent_symbol.node is Type_) {
- var t = (Type_) f.symbol.parent_symbol.node;
+ if (f.symbol.parent_symbol.node is DataType) {
+ var t = (DataType) f.symbol.parent_symbol.node;
var cdecl = new CCodeDeclaration (type_name = f.type_reference.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator (name = "%s_%s".printf (t.get_lower_case_cname (null), f.get_cname ())));
cdecl.modifiers = CCodeModifiers.STATIC;
}
}
- private ref CCodeStatement create_type_check_statement (Method! m, Type_! t, bool non_null, string! var_name) {
+ private ref CCodeStatement create_type_check_statement (Method! m, DataType! t, bool non_null, string! var_name) {
var ccheck = new CCodeFunctionCall ();
var ctype_check = new CCodeFunctionCall (call = new CCodeIdentifier (name = t.get_upper_case_cname ("IS_")));
if (m.instance) {
var this_type = new TypeReference ();
- this_type.type = (Type_) m.symbol.parent_symbol.node;
+ this_type.type = (DataType) m.symbol.parent_symbol.node;
if (!m.is_override) {
var cparam = new CCodeFormalParameter (type_name = this_type.get_cname (), name = "self");
function.add_parameter (cparam);
} else {
var base_type = new TypeReference ();
- base_type.type = (Type_) m.base_method.symbol.parent_symbol.node;
+ base_type.type = (DataType) m.base_method.symbol.parent_symbol.node;
var cparam = new CCodeFormalParameter (type_name = base_type.get_cname (), name = "base");
function.add_parameter (cparam);
}
var vfunc = new CCodeFunction (name = m.get_cname (), return_type = m.return_type.get_cname ());
var this_type = new TypeReference ();
- this_type.type = (Type_) m.symbol.parent_symbol.node;
+ this_type.type = (DataType) m.symbol.parent_symbol.node;
var cparam = new CCodeFormalParameter (type_name = this_type.get_cname (), name = "self");
vfunc.add_parameter (cparam);
var cblock = new CCodeBlock ();
- foreach (Statement stmt in b.statement_list) {
+ foreach (Statement stmt in b.get_statements ()) {
var src = stmt.source_reference;
if (src != null && src.comment != null) {
cblock.add_statement (new CCodeComment (text = src.comment));
visit_expression (expr);
}
- private void process_cmember (Expression! expr, CCodeExpression pub_inst, Type_ base_type) {
+ private void process_cmember (Expression! expr, CCodeExpression pub_inst, DataType base_type) {
if (expr.symbol_reference.node is Method) {
var m = (Method) expr.symbol_reference.node;
if (!m.is_override) {
if (f.instance) {
ref CCodeExpression typed_inst;
if (f.symbol.parent_symbol.node != base_type) {
- typed_inst = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((Type_) f.symbol.parent_symbol.node).get_upper_case_cname (null)));
+ typed_inst = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((DataType) f.symbol.parent_symbol.node).get_upper_case_cname (null)));
((CCodeFunctionCall) typed_inst).add_argument (pub_inst);
} else {
typed_inst = pub_inst;
}
expr.ccodenode = new CCodeMemberAccess (inner = inst, member_name = f.get_cname (), is_pointer = true);
} else {
- if (f.symbol.parent_symbol.node is Type_) {
- var t = (Type_) f.symbol.parent_symbol.node;
+ if (f.symbol.parent_symbol.node is DataType) {
+ var t = (DataType) f.symbol.parent_symbol.node;
expr.ccodenode = new CCodeIdentifier (name = "%s_%s".printf (t.get_lower_case_cname (null), f.get_cname ()));
} else {
expr.ccodenode = new CCodeIdentifier (name = f.get_cname ());
ccast.add_argument (pub_inst);
typed_pub_inst = ccast;
} else if (prop.symbol.parent_symbol.node != base_type) {
- var ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((Type_) prop.symbol.parent_symbol.node).get_upper_case_cname (null)));
+ var ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((DataType) prop.symbol.parent_symbol.node).get_upper_case_cname (null)));
ccast.add_argument (pub_inst);
typed_pub_inst = ccast;
}
public override void visit_simple_name (SimpleName! expr) {
var pub_inst = new CCodeIdentifier (name = "self");
- var base_type = (Type_) current_type_symbol.node;
+ var base_type = (DataType) current_type_symbol.node;
process_cmember (expr, pub_inst, base_type);
public override void visit_member_access (MemberAccess! expr) {
var pub_inst = (CCodeExpression) expr.inner.ccodenode;
- Type_ base_type = null;
+ DataType base_type = null;
if (expr.inner.static_type != null) {
base_type = expr.inner.static_type.type;
}
Report.error (expr.source_reference, "unsupported method invocation");
}
- if (req_cast && ((Type_) m.symbol.parent_symbol.node).is_reference_type ()) {
- var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((Type_) base_method.symbol.parent_symbol.node).get_upper_case_cname (null)));
+ if (req_cast && ((DataType) m.symbol.parent_symbol.node).is_reference_type ()) {
+ var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((DataType) base_method.symbol.parent_symbol.node).get_upper_case_cname (null)));
ccall.add_argument (instance);
instance = ccall;
}
return;
}
- if (req_cast && ((Type_) prop.symbol.parent_symbol.node).is_reference_type ()) {
- var ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((Type_) prop.symbol.parent_symbol.node).get_upper_case_cname (null)));
+ if (req_cast && ((DataType) prop.symbol.parent_symbol.node).is_reference_type ()) {
+ var ccast = new CCodeFunctionCall (call = new CCodeIdentifier (name = ((DataType) prop.symbol.parent_symbol.node).get_upper_case_cname (null)));
ccast.add_argument (instance);
instance = ccast;
}
string cname;
public string get_cname () {
if (cname == null) {
- if (symbol.parent_symbol.node is Type_) {
- var t = (Type_) symbol.parent_symbol.node;
+ if (symbol.parent_symbol.node is DataType) {
+ var t = (DataType) symbol.parent_symbol.node;
cname = "%s_%s".printf (t.get_upper_case_cname (null), name);
} else {
var ns = (Namespace) symbol.parent_symbol.node;
using GLib;
namespace Vala {
- public abstract class Type_ : CodeNode {
- public string name { get; construct; }
- public SourceReference source_reference { get; construct; }
+ public abstract class DataType : CodeNode {
+ public string! name { get; set construct; }
+ public SourceReference source_reference { get; set; }
public weak Namespace @namespace;
public MemberAccessibility access;
public abstract ref string get_upper_case_cname (string infix);
public abstract ref string get_lower_case_cname (string infix);
- public List<weak string> cheader_filenames;
+ private List<string> cheader_filenames;
public ref List<string> get_cheader_filenames () {
if (cheader_filenames == null) {
- cheader_filenames = @namespace.get_cheader_filenames ();
+ /* default to header filenames of the namespace */
+ foreach (string filename in @namespace.get_cheader_filenames ()) {
+ add_cheader_filename (filename);
+ }
}
return cheader_filenames.copy ();
}
+
+ public void add_cheader_filename (string! filename) {
+ cheader_filenames.append (filename);
+ }
}
}
using GLib;
namespace Vala {
- public class Enum : Type_ {
+ public class Enum : DataType {
List<EnumValue> values;
public static ref Enum new (string name, SourceReference source) {
if (lit is StringLiteral) {
var val = ((StringLiteral) lit).eval ();
foreach (string filename in val.split (",", 0)) {
- cheader_filenames.append (filename);
+ add_cheader_filename (filename);
}
}
}
using GLib;
namespace Vala {
- public class Flags : Type_ {
+ public class Flags : DataType {
List<FlagsValue> values;
public static ref Flags new (string name, SourceReference source) {
namespace Vala {
public class InstanceCast : CCodeFunctionCall {
- public Type_ type_reference { get; construct; }
+ public DataType type_reference { get; construct; }
public CCodeExpression inner { get; construct; }
InstanceCast () {
using GLib;
namespace Vala {
- public class Interface : Type_ {
+ public class Interface : DataType {
List<string> type_parameters;
public List<TypeReference> base_types;
public class InterfaceRegisterFunction : TypeRegisterFunction {
public Interface interface_reference { get; construct; }
- public override Type_ get_type_declaration () {
+ public override DataType get_type_declaration () {
return interface_reference;
}
namespace Vala {
public abstract class Literal : CodeNode {
- public TypeReference static_type;
+ public TypeReference static_type { get; set; }
}
}
public string get_cname () {
if (cname == null) {
var parent = symbol.parent_symbol.node;
- if (parent is Type_) {
- cname = "%s_%s".printf (((Type_) parent).get_lower_case_cname (null), name);
+ if (parent is DataType) {
+ cname = "%s_%s".printf (((DataType) parent).get_lower_case_cname (null), name);
} else if (parent is Namespace) {
cname = "%s%s".printf (((Namespace) parent).get_lower_case_cprefix (), name);
} else {
TypeReference bool_type;
TypeReference string_type;
- Type_ initially_unowned_type;
+ DataType initially_unowned_type;
public void analyze (CodeContext context) {
root_symbol = context.root;
bool_type = new TypeReference ();
- bool_type.type = (Type_) root_symbol.lookup ("bool").node;
+ bool_type.type = (DataType) root_symbol.lookup ("bool").node;
string_type = new TypeReference ();
- string_type.type = (Type_) root_symbol.lookup ("string").node;
+ string_type.type = (DataType) root_symbol.lookup ("string").node;
var glib_ns = root_symbol.lookup ("GLib");
- initially_unowned_type = (Type_) glib_ns.lookup ("InitiallyUnowned").node;
+ initially_unowned_type = (DataType) glib_ns.lookup ("InitiallyUnowned").node;
current_symbol = root_symbol;
context.accept (this);
public override void visit_character_literal (CharacterLiteral! expr) {
expr.static_type = new TypeReference ();
- expr.static_type.type = (Type_) root_symbol.lookup ("char").node;
+ expr.static_type.type = (DataType) root_symbol.lookup ("char").node;
}
public override void visit_integer_literal (IntegerLiteral! expr) {
expr.static_type = new TypeReference ();
- expr.static_type.type = (Type_) root_symbol.lookup ("int").node;
+ expr.static_type.type = (DataType) root_symbol.lookup ("int").node;
}
public override void visit_real_literal (IntegerLiteral! expr) {
expr.static_type = new TypeReference ();
- expr.static_type.type = (Type_) root_symbol.lookup ("double").node;
+ expr.static_type.type = (DataType) root_symbol.lookup ("double").node;
}
public override void visit_string_literal (StringLiteral! expr) {
return decl.type_reference;
} else if (node is EnumValue) {
var type = new TypeReference ();
- type.type = (Type_) node.symbol.parent_symbol.node;
+ type.type = (DataType) node.symbol.parent_symbol.node;
return type;
}
return null;
}
if (expr.inner.static_type == null) {
- if (expr.inner.symbol_reference.node is Namespace || expr.inner.symbol_reference.node is Type_) {
+ if (expr.inner.symbol_reference.node is Namespace || expr.inner.symbol_reference.node is DataType) {
expr.symbol_reference = expr.inner.symbol_reference.lookup (expr.member_name);
}
}
public int mark; // used for cycle detection, 0 = white (not yet visited), 1 = gray (currently visiting), 2 = black (already visited)
public void add_symbol_dependency (Symbol sym, SourceFileDependencyType dep_type) {
- Type_ t;
+ DataType t;
- if (sym.node is Type_) {
- t = (Type_) sym.node;
+ if (sym.node is DataType) {
+ t = (DataType) sym.node;
} else if (sym.node is Method || sym.node is Field) {
- if (sym.parent_symbol.node is Type_) {
- t = (Type_) sym.parent_symbol.node;
+ if (sym.parent_symbol.node is DataType) {
+ t = (DataType) sym.parent_symbol.node;
} else {
return;
}
} else if (sym.node is Property) {
- t = (Type_) sym.parent_symbol.node;
+ t = (DataType) sym.parent_symbol.node;
} else if (sym.node is FormalParameter) {
var fp = (FormalParameter) sym.node;
t = fp.type_reference.type;
namespace Vala {
public abstract class Statement : CodeNode {
- public SourceReference source_reference { get; construct; }
+ public SourceReference source_reference { get; set; }
}
}
using GLib;
namespace Vala {
- public class Struct : Type_ {
+ public class Struct : DataType {
List<TypeParameter> type_parameters;
List<Constant> constants;
List<Field> fields;
if (lit is StringLiteral) {
var val = ((StringLiteral) lit).eval ();
foreach (string filename in val.split (",", 0)) {
- cheader_filenames.append (filename);
+ add_cheader_filename (filename);
}
}
}
if (m.instance) {
m.this_parameter = new FormalParameter (name = "this", type_reference = new TypeReference ());
- m.this_parameter.type_reference.type = (Type_) m.symbol.parent_symbol.node;
+ m.this_parameter.type_reference.type = (DataType) m.symbol.parent_symbol.node;
m.this_parameter.symbol = new Symbol (node = m.this_parameter);
current_symbol.add (m.this_parameter.name, m.this_parameter.symbol);
}
current_symbol = prop.symbol;
prop.this_parameter = new FormalParameter (name = "this", type_reference = new TypeReference ());
- prop.this_parameter.type_reference.type = (Type_) prop.symbol.parent_symbol.node;
+ prop.this_parameter.type_reference.type = (DataType) prop.symbol.parent_symbol.node;
prop.this_parameter.symbol = new Symbol (node = prop.this_parameter);
current_symbol.add (prop.this_parameter.name, prop.this_parameter.symbol);
}
if (sym.node is TypeParameter) {
type.type_parameter = (TypeParameter) sym.node;
} else {
- type.type = (Type_) sym.node;
+ type.type = (DataType) sym.node;
}
} else {
var ns_symbol = root_symbol.lookup (type.namespace_name);
Report.error (type.source_reference, "The type name `%s' does not exist in the namespace `%s'".printf (type.type_name, type.namespace_name));
return;
}
- type.type = (Type_) sym.node;
+ type.type = (DataType) sym.node;
}
if (type.type != null && !type.type.is_reference_type ()) {
public class TypeParameter : CodeNode {
public string name { get; construct; }
public SourceReference source_reference { get; construct; }
- public weak Type_ type;
+ public weak DataType type;
public static ref TypeParameter new (string name, SourceReference source) {
return (new TypeParameter (name = name, source_reference = source));
public bool array { get; set; }
public bool array_own { get; set; }
public bool non_null { get; set; }
- public weak Type_ type;
+ public weak DataType type;
public TypeParameter type_parameter;
public bool floating_reference { get; set; }
block = type_block;
}
- public abstract Type_ get_type_declaration ();
+ public abstract DataType get_type_declaration ();
public abstract ref string get_type_struct_name ();
public abstract ref string get_class_init_func_name ();
public abstract ref string get_instance_struct_size ();