Commit 6a6d38f1 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

adapt to changes in InvocationExpression, LocalVariableDeclaration, and

2006-07-10  Jürg Billeter  <j@bitron.ch>

	* vala/parser.y: adapt to changes in InvocationExpression,
	  LocalVariableDeclaration, and InitializerList
	* vala/valasemanticanalyzer.vala: add some implicit casts, fix assigning
	  callback to field, adapt to changes in InvocationExpression
	* vala/valamemorymanager.vala: adapt to change in InvocationExpression
	* vala/valacodegenerator.vala: fix signal handler without parameters,
	  fix access to value-type struct members, adapt to changes in
	  LocalVariableDeclaration, InitializerList, and InvocationExprssion
	* vala/valaclass.vala: don't let private static fields influence
	  has_private_fields, correct marshaller type name
	* vala/valaifstatement.vala, vala/valainitializerlist.vala,
	  vala/valainstancecast.vala, vala/valaintegerliteral.vala,
	  vala/valainvocationexpression.vala, vala/valaliteralexpression.vala,
	  vala/valalocalvariabledeclaration.vala: add interface documentation,
	  use implicit namespace specification
	* compiler/valacompiler.vala: fix --vapidir handling
	* vapi/glib-2.0.vala: add MainLoop, MainContext, IdleSource, Source, and
	  Thread

svn path=/trunk/; revision=76
parent 3cf0fef2
2006-07-10 Jürg Billeter <j@bitron.ch>
* vala/parser.y: adapt to changes in InvocationExpression,
LocalVariableDeclaration, and InitializerList
* vala/valasemanticanalyzer.vala: add some implicit casts, fix assigning
callback to field, adapt to changes in InvocationExpression
* vala/valamemorymanager.vala: adapt to change in InvocationExpression
* vala/valacodegenerator.vala: fix signal handler without parameters,
fix access to value-type struct members, adapt to changes in
LocalVariableDeclaration, InitializerList, and InvocationExprssion
* vala/valaclass.vala: don't let private static fields influence
has_private_fields, correct marshaller type name
* vala/valaifstatement.vala, vala/valainitializerlist.vala,
vala/valainstancecast.vala, vala/valaintegerliteral.vala,
vala/valainvocationexpression.vala, vala/valaliteralexpression.vala,
vala/valalocalvariabledeclaration.vala: add interface documentation,
use implicit namespace specification
* compiler/valacompiler.vala: fix --vapidir handling
* vapi/glib-2.0.vala: add MainLoop, MainContext, IdleSource, Source, and
Thread
2006-07-08 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: don't allow write access to read-only
......
......@@ -63,7 +63,6 @@ class Vala.Compiler {
return filename;
}
}
vapi_directories = null;
}
var filename = Path.build_filename ("/usr/share/vala/vapi", basename, null);
......
......@@ -550,12 +550,18 @@ invocation_expression
: primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
{
ValaSourceReference *src = src(@1);
$$ = VALA_EXPRESSION (vala_invocation_expression_new ($1, $3, src));
$$ = VALA_EXPRESSION (vala_invocation_expression_new ($1, src));
g_object_unref ($1);
g_object_unref (src);
if ($3 != NULL) {
GList *l;
for (l = $3; l != NULL; l = l->next) {
vala_invocation_expression_add_argument (VALA_INVOCATION_EXPRESSION ($$), l->data);
g_object_unref (l->data);
}
g_list_free ($3);
}
g_object_unref (src);
}
;
......@@ -1080,21 +1086,28 @@ local_variable_declaration
{
GList *l;
ValaSourceReference *src = src(@2);
$$ = vala_local_variable_declaration_new ($1, $2, src);
$$ = vala_local_variable_declaration_new ($1, src);
g_object_unref ($1);
g_object_unref (src);
for (l = $2; l != NULL; l = l->next) {
ValaVariableDeclarator *decl = l->data;
decl->type_reference = g_object_ref ($1);
vala_local_variable_declaration_add_declarator ($$, decl);
g_object_unref (decl);
}
g_list_free ($2);
g_object_unref ($1);
}
| VAR variable_declarators SEMICOLON
{
GList *l;
ValaSourceReference *src = src(@2);
$$ = vala_local_variable_declaration_new_var ($2, src);
g_list_free ($2);
$$ = vala_local_variable_declaration_new_var (src);
g_object_unref (src);
for (l = $2; l != NULL; l = l->next) {
vala_local_variable_declaration_add_declarator ($$, l->data);
g_object_unref (l->data);
}
g_list_free ($2);
}
;
......@@ -1805,8 +1818,16 @@ initializer
| OPEN_BRACE initializer_list CLOSE_BRACE
{
ValaSourceReference *src = src(@1);
$$ = VALA_EXPRESSION (vala_initializer_list_new ($2, src));
$$ = VALA_EXPRESSION (vala_initializer_list_new (src));
g_object_unref (src);
if ($2 != NULL) {
GList *l;
for (l = $2; l != NULL; l = l->next) {
vala_initializer_list_append (VALA_INITIALIZER_LIST ($$), l->data);
g_object_unref (l->data);
}
}
}
;
......
......@@ -128,7 +128,7 @@ public class Vala.Class : DataType {
*/
public void add_field (Field! f) {
fields.append (f);
if (f.access == MemberAccessibility.PRIVATE) {
if (f.access == MemberAccessibility.PRIVATE && f.instance) {
_has_private_fields = true;
}
}
......@@ -332,7 +332,7 @@ public class Vala.Class : DataType {
}
public override string get_marshaller_type_name () {
return "G_TYPE_OBJECT";
return "OBJECT";
}
public override bool is_reference_counting () {
......
......@@ -424,6 +424,10 @@ public class Vala.CodeGenerator : CodeVisitor {
csignew.add_argument (new CCodeConstant (name = param.type_reference.type.get_type_id ()));
}
if (params_len == 0) {
marshaller = "%s_VOID".printf (marshaller);
}
marshal_arg.name = marshaller;
init_block.add_statement (new CCodeExpressionStatement (expression = csignew));
......@@ -1162,7 +1166,7 @@ public class Vala.CodeGenerator : CodeVisitor {
var cfrag = new CCodeFragment ();
foreach (VariableDeclarator decl in stmt.declaration.variable_declarators) {
foreach (VariableDeclarator decl in stmt.declaration.get_variable_declarators ()) {
var cdecl = new CCodeDeclaration (type_name = decl.type_reference.get_cname ());
cdecl.add_declarator ((CCodeVariableDeclarator) decl.ccodenode);
......@@ -1172,7 +1176,7 @@ public class Vala.CodeGenerator : CodeVisitor {
stmt.ccodenode = cfrag;
foreach (VariableDeclarator decl in stmt.declaration.variable_declarators) {
foreach (VariableDeclarator decl in stmt.declaration.get_variable_declarators ()) {
if (decl.initializer != null) {
create_temp_decl (stmt, decl.initializer.temp_vars);
}
......@@ -1201,7 +1205,7 @@ public class Vala.CodeGenerator : CodeVisitor {
public override void visit_initializer_list (InitializerList! list) {
var clist = new CCodeInitializerList ();
foreach (Expression expr in list.initializers) {
foreach (Expression expr in list.get_initializers ()) {
clist.append ((CCodeExpression) expr.ccodenode);
}
list.ccodenode = clist;
......@@ -1612,7 +1616,7 @@ public class Vala.CodeGenerator : CodeVisitor {
} else {
inst = typed_inst;
}
expr.ccodenode = new CCodeMemberAccess (inner = inst, member_name = f.get_cname (), is_pointer = true);
expr.ccodenode = new CCodeMemberAccess (inner = inst, member_name = f.get_cname (), is_pointer = ((DataType) f.symbol.parent_symbol.node).is_reference_type ());
} else {
if (f.symbol.parent_symbol.node is DataType) {
var t = (DataType) f.symbol.parent_symbol.node;
......@@ -1775,7 +1779,7 @@ public class Vala.CodeGenerator : CodeVisitor {
}
var i = 1;
foreach (Expression arg in expr.argument_list) {
foreach (Expression arg in expr.get_argument_list ()) {
/* explicitly use strong reference as ccall gets
* unrefed at end of inner block
*/
......
......@@ -22,27 +22,47 @@
using GLib;
namespace Vala {
public class IfStatement : Statement {
public Expression condition { get; construct; }
public Statement true_statement { get; construct; }
public Statement false_statement { get; construct; }
/**
* Represents an if selection statement in the source code.
*/
public class Vala.IfStatement : Statement {
/**
* The boolean condition to evaluate.
*/
public Expression! condition { get; set construct; }
/**
* The statement to be evaluated if the condition holds.
*/
public Statement! true_statement { get; set construct; }
/**
* The optional statement to be evaluated if the condition doesn't hold.
*/
public Statement false_statement { get; set construct; }
public static ref IfStatement new (Expression cond, Statement true_stmt, Statement false_stmt, SourceReference source) {
return (new IfStatement (condition = cond, true_statement = true_stmt, false_statement = false_stmt, source_reference = source));
}
/**
* Creates a new if statement.
*
* @param cond a boolean condition
* @param true_stmt statement to be evaluated if condition is true
* @param false_stmt statement to be evaluated if condition is false
* @return newly created if statement
*/
public static ref IfStatement! new (Expression! cond, Statement! true_stmt, Statement false_stmt, SourceReference source) {
return (new IfStatement (condition = cond, true_statement = true_stmt, false_statement = false_stmt, source_reference = source));
}
public override void accept (CodeVisitor! visitor) {
condition.accept (visitor);
public override void accept (CodeVisitor! visitor) {
condition.accept (visitor);
visitor.visit_end_full_expression (condition);
true_statement.accept (visitor);
if (false_statement != null) {
false_statement.accept (visitor);
}
visitor.visit_if_statement (this);
visitor.visit_end_full_expression (condition);
true_statement.accept (visitor);
if (false_statement != null) {
false_statement.accept (visitor);
}
visitor.visit_if_statement (this);
}
}
......@@ -22,20 +22,45 @@
using GLib;
namespace Vala {
public class InitializerList : Expression {
public List<Expression> initializers { get; construct; }
public static ref InitializerList new (List<Expression> initializers, SourceReference source) {
return (new InitializerList (initializers = initializers, source_reference = source));
/**
* Represents an array or struct initializer list in the source code.
*/
public class Vala.InitializerList : Expression {
private List<Expression> initializers;
/**
* Appends the specified expression to this initializer list.
*
* @param expr an expression
*/
public void append (Expression! expr) {
initializers.append (expr);
}
/**
* Returns a copy of the expression list.
*
* @return expression list
*/
public ref List<Expression> get_initializers () {
return initializers.copy ();
}
/**
* Creates a new initializer list.
*
* @param source reference to source code
* @return newly created initializer list
*/
public static ref InitializerList! new (SourceReference source) {
return (new InitializerList (source_reference = source));
}
public override void accept (CodeVisitor! visitor) {
foreach (Expression expr in initializers) {
expr.accept (visitor);
}
public override void accept (CodeVisitor! visitor) {
foreach (Expression expr in initializers) {
expr.accept (visitor);
}
visitor.visit_initializer_list (this);
}
visitor.visit_initializer_list (this);
}
}
......@@ -22,15 +22,23 @@
using GLib;
namespace Vala {
public class InstanceCast : CCodeFunctionCall {
public DataType type_reference { get; construct; }
public CCodeExpression inner { get; construct; }
InstanceCast () {
call = new CCodeIdentifier (name = type_reference.get_upper_case_cname (null));
add_argument ((CCodeExpression) inner);
}
/**
* Represents a runtime checked object instance cast expression in the C code.
*/
public class Vala.InstanceCast : CCodeFunctionCall {
/**
* The target type.
*/
public DataType! type_reference { get; set construct; }
/**
* The expression to be casted.
*/
public CCodeExpression! inner { get; set construct; }
InstanceCast () {
call = new CCodeIdentifier (name = type_reference.get_upper_case_cname (null));
add_argument ((CCodeExpression) inner);
}
}
......
......@@ -22,16 +22,27 @@
using GLib;
namespace Vala {
public class IntegerLiteral : Literal {
public string value { get; set; }
/**
* Represents an integer literal in the source code.
*/
public class Vala.IntegerLiteral : Literal {
/**
* The literal value.
*/
public string! value { get; set; }
public static ref IntegerLiteral! new (string i, SourceReference source) {
return (new IntegerLiteral (value = i, source_reference = source));
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_integer_literal (this);
}
/**
* Creates a new integer literal.
*
* @param i literal value
* @param source reference to source code
* @return newly created integer literal
*/
public static ref IntegerLiteral! new (string! i, SourceReference source) {
return (new IntegerLiteral (value = i, source_reference = source));
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_integer_literal (this);
}
}
......@@ -22,29 +22,55 @@
using GLib;
namespace Vala {
public class InvocationExpression : Expression {
public Expression call { get; construct; }
public List<Expression> argument_list { get; construct; }
public static ref InvocationExpression new (Expression call, List<Expression> argument_list, SourceReference source) {
return (new InvocationExpression (call = call, argument_list = argument_list, source_reference = source));
}
public void add_argument (Expression! arg) {
_argument_list.append (arg);
}
public override void accept (CodeVisitor! visitor) {
call.accept (visitor);
/**
* Represents an invocation expression in the source code.
*/
public class Vala.InvocationExpression : Expression {
/**
* The method to call.
*/
public Expression! call { get; set construct; }
private List<Expression> argument_list;
visitor.visit_begin_invocation_expression (this);
/**
* Creates a new invocation expression.
*
* @param call method to call
* @param source reference to source code
* @return newly created invocation expression
*/
public static ref InvocationExpression! new (Expression! call, SourceReference source) {
return (new InvocationExpression (call = call, source_reference = source));
}
/**
* Appends the specified expression to the list of arguments.
*
* @param arg an argument
*/
public void add_argument (Expression! arg) {
argument_list.append (arg);
}
/**
* Returns a copy of the argument list.
*
* @return argument list
*/
public ref List<Expression> get_argument_list () {
return argument_list.copy ();
}
public override void accept (CodeVisitor! visitor) {
call.accept (visitor);
foreach (Expression expr in argument_list) {
expr.accept (visitor);
}
visitor.visit_begin_invocation_expression (this);
visitor.visit_end_invocation_expression (this);
foreach (Expression expr in argument_list) {
expr.accept (visitor);
}
visitor.visit_end_invocation_expression (this);
}
}
......@@ -22,18 +22,29 @@
using GLib;
namespace Vala {
public class LiteralExpression : Expression {
public Literal literal { get; construct; }
/**
* Represents a literal expression in the source code.
*/
public class Vala.LiteralExpression : Expression {
/**
* The literal.
*/
public Literal literal { get; construct; }
public static ref LiteralExpression new (Literal literal, SourceReference source) {
return (new LiteralExpression (literal = literal, source_reference = source));
}
public override void accept (CodeVisitor! visitor) {
literal.accept (visitor);
visitor.visit_literal_expression (this);
}
/**
* Creates a new literal expression.
*
* @param literal a literal
* @param source reference to source code
* @return newly created literal expression
*/
public static ref LiteralExpression! new (Literal! literal, SourceReference source) {
return (new LiteralExpression (literal = literal, source_reference = source));
}
public override void accept (CodeVisitor! visitor) {
literal.accept (visitor);
visitor.visit_literal_expression (this);
}
}
......@@ -22,29 +22,68 @@
using GLib;
namespace Vala {
public class LocalVariableDeclaration : CodeNode {
public TypeReference type_reference { get; construct; }
public List<VariableDeclarator> variable_declarators { get; construct; }
public static ref LocalVariableDeclaration new (TypeReference type, List<VariableDeclarator> declarators, SourceReference source) {
return (new LocalVariableDeclaration (type_reference = type, variable_declarators = declarators, source_reference = source));
}
public static ref LocalVariableDeclaration new_var (List<VariableDeclarator> declarators, SourceReference source) {
return (new LocalVariableDeclaration (variable_declarators = declarators, source_reference = source));
/**
* Represents a local variable declaration in the source code.
*/
public class Vala.LocalVariableDeclaration : CodeNode {
/**
* The type of the local variable.
*/
public TypeReference type_reference { get; set; }
private List<VariableDeclarator> variable_declarators;
/**
* Creates a new local variable declaration.
*
* @param type type of the variable
* @param source reference to source code
* @return newly created local variable declaration
*/
public static ref LocalVariableDeclaration! new (TypeReference type, SourceReference source) {
return (new LocalVariableDeclaration (type_reference = type, source_reference = source));
}
/**
* Creates a new implicitly typed local variable declaration. The type
* of the variable is inferred from the expression used to initialize
* the variable.
*
* @param source reference to source code
* @return newly created local variable declaration
*/
public static ref LocalVariableDeclaration! new_var (SourceReference source) {
return (new LocalVariableDeclaration (source_reference = source));
}
/**
* Add the specified variable declarator to this local variable
* declaration.
*
* @param declarator a variable declarator
*/
public void add_declarator (VariableDeclarator! declarator) {
variable_declarators.append (declarator);
}
/**
* Returns a copy of the list of variable declarators.
*
* @return variable declarator list
*/
public ref List<VariableDeclarator> get_variable_declarators () {
return variable_declarators.copy ();
}
public override void accept (CodeVisitor! visitor) {
if (type_reference != null) {
type_reference.accept (visitor);
}
public override void accept (CodeVisitor! visitor) {
if (type_reference != null) {
type_reference.accept (visitor);
}
foreach (VariableDeclarator decl in variable_declarators) {
decl.accept (visitor);
}
visitor.visit_local_variable_declaration (this);
foreach (VariableDeclarator decl in variable_declarators) {
decl.accept (visitor);
}
visitor.visit_local_variable_declaration (this);
}
}
......@@ -124,7 +124,7 @@ public class Vala.MemoryManager : CodeVisitor {
var sig = (Signal) msym.node;
params = sig.get_parameters ();
}
foreach (Expression arg in expr.argument_list) {
foreach (Expression arg in expr.get_argument_list ()) {
if (params != null) {
var param = (FormalParameter) params.data;
if (!param.ellipsis
......
......@@ -40,6 +40,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
TypeReference bool_type;
TypeReference string_type;
DataType pointer_type;
DataType initially_unowned_type;
private int next_lambda_id = 0;
......@@ -57,6 +58,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
string_type = new TypeReference ();
string_type.type = (DataType) root_symbol.lookup ("string").node;
pointer_type = (DataType) root_symbol.lookup ("pointer").node;
var glib_ns = root_symbol.lookup ("GLib");
......@@ -562,7 +565,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
(expected_type.type_parameter != null ||
expected_type.type.is_reference_type () ||
expected_type.is_ref ||
expected_type.array)) {
expected_type.array ||
expected_type.type is Callback ||
expected_type.type == pointer_type)) {
return true;
}
......@@ -659,7 +664,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
return;
}
List arg_it = expr.argument_list;
var args = expr.get_argument_list ();
List arg_it = args;
foreach (FormalParameter param in params) {
if (param.ellipsis) {
break;
......@@ -708,7 +714,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
expr.static_type = ret_type;
List arg_it = expr.argument_list;
var args = expr.get_argument_list ();
List arg_it = args;
bool ellipsis = false;
int i = 0;
......@@ -725,7 +732,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (arg_it == null) {
if (param.default_expression == null) {
Report.error (expr.source_reference, "Too few arguments, method `%s' does not take %d arguments".printf (msym.get_full_name (), expr.argument_list.length ()));
Report.error (expr.source_reference, "Too few arguments, method `%s' does not take %d arguments".printf (msym.get_full_name (), args.length ()));
return;
}
} else {
......@@ -744,7 +751,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
if (!ellipsis && arg_it != null) {
Report.error (expr.source_reference, "Too many arguments, method `%s' does not take %d arguments".printf (msym.get_full_name (), expr.argument_list.length ()));
Report.error (expr.source_reference, "Too many arguments, method `%s' does not take %d arguments".printf (msym.get_full_name (), args.length ()));
return;
}
}
......@@ -1105,6 +1112,28 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
Report.error (a.source_reference, "Assignment: Invalid callback assignment attempt");
return;
}
} else if (ma.symbol_reference.node is Field && a.right.static_type == null) {
var f = (Field) ma.symbol_reference.node;
var right_ma = (MemberAccess) a.right;
if (right_ma.symbol_reference.node is Method &&
f.type_reference.type is Callback) {
var m = (Method) right_ma.symbol_reference.node;
var cb = (Callback) f.type_reference.type;
/* check whether method matches callback type */
if (!cb.matches_method (m)) {
f.error = true;
Report.error (a.source_reference, "declaration of method `%s' doesn't match declaration of callback `%s'".printf (m.symbol.get_full_name (), cb.symbol.get_full_name ()));
return;
}
a.right.static_type = f.type_reference;
} else {
a.error = true;
Report.error (a.source_reference, "Assignment: Invalid callback assignment attempt");
return;
}
} else if (a.left.static_type != null && a.right.static_type != null) {
if (!is_type_compatible (a.right.static_type, a.left.static_type)) {
/* if there was an error on either side,
......
......@@ -153,12 +153,6 @@ public struct string {
[Import ()]
[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h")]
namespace GLib {
public struct Path {
public static ref string get_basename (string file_name);
[CCode (cname = "g_build_filename")]
public static ref string build_filename (string first_element, ...);
}
public struct Type {
[CCode (cname = "G_TYPE_IS_OBJECT")]
public bool is_object ();
......@@ -190,6 +184,67 @@ namespace GLib {
public abstract class InitiallyUnowned : Object {
}
[ReferenceType (dup_function = "g_main_loop_ref", free_function = "g_main_loop_unref")]
public struct MainLoop {
public static ref MainLoop new (MainContext context, bool is_running);
public void run ();
public void quit ();
public bool is_running ();
public MainContext get_context ();
}
[ReferenceType (dup_function = "g_main_context_ref", free_function = "g_main_context_unref")]
public struct MainContext {
public static ref MainContext new ();
public static MainContext default ();
public bool iteration (bool may_block);
public bool pending ();
public void wakeup ();
public bool acquire ();
public void release ();
public bool is_owner ();
}
[ReferenceType ()]
public struct IdleSource {
public static Source new ();