Commit 23e2ba15 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

port to construction methods add interface documentation, use implicit

2006-08-02  Jürg Billeter  <j@bitron.ch>

	* port to construction methods
	* vala/valaparenthesizedexpression.vala, vala/valareport.vala,
	  vala/valareturnstatement.vala, vala/valasourcefilecycle.vala,
	  vala/valasourcereference.vala, vala/valatypecheck.vala,
	  vala/valatypeofexpression.vala, vala/valatypeparameter.vala: add
	  interface documentation, use implicit namespace specification
	* vala/Makefile.am: sort source file list

svn path=/trunk/; revision=89
parent e3311183
2006-08-02 Jürg Billeter <j@bitron.ch>
* port to construction methods
* vala/valaparenthesizedexpression.vala, vala/valareport.vala,
vala/valareturnstatement.vala, vala/valasourcefilecycle.vala,
vala/valasourcereference.vala, vala/valatypecheck.vala,
vala/valatypeofexpression.vala, vala/valatypeparameter.vala: add
interface documentation, use implicit namespace specification
* vala/Makefile.am: sort source file list
2006-08-02 Jürg Billeter <j@bitron.ch>
* vala/parser.y, vala/valacodevisitor.vala, vala/valasymbolbuilder.vala,
......
......@@ -41,6 +41,12 @@ public class Vala.CCodeAssignment : CCodeExpression {
*/
public CCodeExpression right { get; construct; }
public construct (CCodeExpression l, CCodeExpression r, CCodeAssignmentOperator op = CCodeAssignmentOperator.SIMPLE) {
left = l;
operator = op;
right = r;
}
public override void write (CCodeWriter! writer) {
if (left != null) {
left.write (writer);
......
......@@ -41,6 +41,12 @@ public class Vala.CCodeBinaryExpression : CCodeExpression {
*/
public CCodeExpression! right { get; set construct; }
public construct (CCodeBinaryOperator op, CCodeExpression! l, CCodeExpression! r) {
operator = op;
left = l;
right = r;
}
public override void write (CCodeWriter! writer) {
if (left != null) {
left.write (writer);
......
......@@ -33,6 +33,10 @@ public class Vala.CCodeCaseStatement : CCodeStatement {
private List<CCodeStatement> statements;
public construct (CCodeExpression! expr) {
expression = expr;
}
/**
* Append the specified statement to this switch section.
*
......
......@@ -36,6 +36,11 @@ public class Vala.CCodeCastExpression : CCodeExpression {
*/
public string! type_name { get; set construct; }
public construct (CCodeExpression! expr, string! type) {
inner = expr;
type_name = type;
}
public override void write (CCodeWriter! writer) {
writer.write_string ("(");
writer.write_string (type_name);
......
......@@ -31,6 +31,10 @@ public class Vala.CCodeComment : CCodeNode {
*/
public string! text { get; set construct; }
public construct (string! _text) {
text = _text;
}
public override void write (CCodeWriter! writer) {
writer.write_comment (text);
}
......
......@@ -41,6 +41,12 @@ public class Vala.CCodeConditionalExpression : CCodeExpression {
*/
public CCodeExpression! false_expression { get; set construct; }
public construct (CCodeExpression! cond, CCodeExpression! true_expr, CCodeExpression! false_expr) {
condition = cond;
true_expression = true_expr;
false_expression = false_expr;
}
public override void write (CCodeWriter! writer) {
writer.write_string ("(");
condition.write (writer);
......
......@@ -31,6 +31,10 @@ public class Vala.CCodeConstant : CCodeExpression {
*/
public string! name { get; set construct; }
public construct (string! _name) {
name = _name;
}
public override void write (CCodeWriter! writer) {
writer.write_string (name);
}
......
......@@ -38,6 +38,10 @@ public class Vala.CCodeDeclaration : CCodeStatement {
private List<CCodeDeclarator> declarators;
public construct (string! _type_name) {
type_name = _type_name;
}
/**
* Adds the specified declarator to this declaration.
*
......
/* valaccodememberaccess.vala
*
* Copyright (C) 2006 Raffaele Sandrini
* Copyright (C) 2006 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -18,24 +19,31 @@
*
* Author:
* Raffaele Sandrini <rasa@gmx.ch>
* Jürg Billeter <j@bitron.ch>
*/
using GLib;
/**
* Represents an access to a array member in the C code.
* Represents an access to an array member in the C code.
*/
public class Vala.CCodeElementAccess : CCodeExpression {
/**
* Expression representing the container on wich we want to access.
* Expression representing the container on which we want to access.
*/
public CCodeExpression! container { get; set construct; }
/**
* Expression representing the index we want to access inside the container.
* Expression representing the index we want to access inside the
* container.
*/
public CCodeExpression! index { get; set construct; }
public construct (CCodeExpression! cont, CCodeExpression! i) {
container = cont;
index = i;
}
public override void write (CCodeWriter! writer) {
container.write (writer);
writer.write_string ("[");
......
......@@ -29,10 +29,14 @@ public class Vala.CCodeEnum : CCodeNode {
/**
* The name of this enum.
*/
public string! name { get; set construct; }
public string name { get; set; }
private List<string> values;
public construct (string n = null) {
name = n;
}
/**
* Adds the specified value to this enum.
*
......
......@@ -30,6 +30,10 @@ public class Vala.CCodeExpressionStatement : CCodeStatement {
* The expression to evaluate.
*/
public CCodeExpression! expression { get; set construct; }
public construct (CCodeExpression expr) {
expression = expr;
}
public override void write (CCodeWriter! writer) {
writer.write_indent ();
......
......@@ -36,6 +36,11 @@ public class Vala.CCodeFormalParameter : CCodeNode {
*/
public string! type_name { get; set construct; }
public construct (string! n, string! type) {
name = n;
type_name = type;
}
public override void write (CCodeWriter! writer) {
writer.write_string (type_name);
writer.write_string (" ");
......
......@@ -38,6 +38,11 @@ public class Vala.CCodeForStatement : CCodeStatement {
private List<CCodeExpression> initializer;
private List<CCodeExpression> iterator;
public construct (CCodeExpression! cond, CCodeStatement stmt = null) {
condition = cond;
body = stmt;
}
/**
* Appends the specified expression to the list of initializers.
......
......@@ -48,6 +48,11 @@ public class Vala.CCodeFunction : CCodeNode {
private List<CCodeFormalParameter> parameters;
public construct (string! _name, string! _return_type) {
name = _name;
return_type = _return_type;
}
/**
* Appends the specified parameter to the list of function parameters.
*
......@@ -63,7 +68,7 @@ public class Vala.CCodeFunction : CCodeNode {
* @return copied function
*/
public ref CCodeFunction! copy () {
var func = new CCodeFunction (name = name, return_type = return_type);
var func = new CCodeFunction (name, return_type);
func.modifiers = modifiers;
/* no deep copy for lists available yet
......
......@@ -33,6 +33,10 @@ public class Vala.CCodeFunctionCall : CCodeExpression {
private List<CCodeExpression> arguments;
public construct (CCodeExpression _call = null) {
call = _call;
}
/**
* Appends the specified expression to the list of arguments.
*
......
......@@ -33,6 +33,10 @@ public class Vala.CCodeFunctionDeclarator : CCodeDeclarator {
private List<CCodeFormalParameter> parameters;
public construct (string! n) {
name = n;
}
/**
* Appends the specified parameter to the list of function parameters.
*
......
......@@ -31,6 +31,10 @@ public class Vala.CCodeIdentifier : CCodeExpression {
*/
public string! name { get; set construct; }
public construct (string! _name) {
name = _name;
}
public override void write (CCodeWriter! writer) {
writer.write_string (name);
}
......
......@@ -41,6 +41,12 @@ public class Vala.CCodeIfStatement : CCodeStatement {
*/
public CCodeStatement false_statement { get; set construct; }
public construct (CCodeExpression! cond, CCodeStatement! true_stmt, CCodeStatement false_stmt = null) {
condition = cond;
true_statement = true_stmt;
false_statement = false_stmt;
}
/**
* Specifies whether this if statement is part of an else if statement.
* This only affects the output formatting.
......
......@@ -31,6 +31,10 @@ public class Vala.CCodeIncludeDirective : CCodeNode {
*/
public string! filename { get; set construct; }
public construct (string! _filename) {
filename = _filename;
}
public override void write (CCodeWriter! writer) {
writer.write_indent ();
writer.write_string ("#include <");
......
......@@ -35,6 +35,11 @@ public class Vala.CCodeLineDirective : CCodeNode {
* The line number in the source file to be presumed.
*/
public int line { get; set; }
public construct (string! _filename, int _line) {
filename = _filename;
line = _line;
}
public override void write (CCodeWriter! writer) {
if (!writer.bol) {
......
......@@ -36,6 +36,11 @@ public class Vala.CCodeMacroReplacement : CCodeNode {
*/
public string! replacement { get; set construct; }
public construct (string! n, string! replace) {
name = n;
replacement = replace;
}
public override void write (CCodeWriter! writer) {
writer.write_indent ();
writer.write_string ("#define ");
......
......@@ -41,6 +41,17 @@ public class Vala.CCodeMemberAccess : CCodeExpression {
*/
public bool is_pointer { get; set; }
public construct (CCodeExpression! container, string! member) {
inner = container;
member_name = member;
}
public construct pointer (CCodeExpression! container, string! member) {
inner = container;
member_name = member;
is_pointer = true;
}
public override void write (CCodeWriter! writer) {
inner.write (writer);
if (is_pointer) {
......
......@@ -31,6 +31,10 @@ public class Vala.CCodeOnceSection : CCodeFragment {
*/
public string! define { get; set construct; }
public construct (string! def) {
define = def;
}
public override void write (CCodeWriter! writer) {
writer.write_indent ();
writer.write_string ("#ifndef ");
......
......@@ -31,6 +31,10 @@ public class Vala.CCodeParenthesizedExpression : CCodeExpression {
*/
public CCodeExpression! inner { get; set construct; }
public construct (CCodeExpression! expr) {
inner = expr;
}
public override void write (CCodeWriter! writer) {
writer.write_string ("(");
......
......@@ -31,6 +31,10 @@ public class Vala.CCodeReturnStatement : CCodeStatement {
*/
public CCodeExpression return_expression { get; set; }
public construct (CCodeExpression expr = null) {
return_expression = expr;
}
public override void write (CCodeWriter! writer) {
writer.write_indent ();
writer.write_string ("return");
......
......@@ -33,6 +33,10 @@ public class Vala.CCodeStruct : CCodeNode {
private List<CCodeDeclaration> declarations;
public construct (string! n) {
name = n;
}
/**
* Adds the specified declaration as member to this struct.
*
......@@ -49,8 +53,8 @@ public class Vala.CCodeStruct : CCodeNode {
* @param name member name
*/
public void add_field (string! type_name, string! name) {
var decl = new CCodeDeclaration (type_name = type_name);
decl.add_declarator (new CCodeVariableDeclarator (name = name));
var decl = new CCodeDeclaration (type_name);
decl.add_declarator (new CCodeVariableDeclarator (name));
add_declaration (decl);
}
......
......@@ -33,6 +33,10 @@ public class Vala.CCodeSwitchStatement : CCodeStatement {
private List<CCodeCaseStatement> case_statements;
public construct (CCodeExpression! expr) {
expression = expr;
}
/**
* Adds the specified case statement to the list of switch sections.
*
......
......@@ -36,6 +36,11 @@ public class Vala.CCodeTypeDefinition : CCodeNode {
*/
public CCodeDeclarator declarator { get; set; }
public construct (string type, CCodeDeclarator decl) {
type_name = type;
declarator = decl;
}
public override void write (CCodeWriter! writer) {
writer.write_indent ();
writer.write_string ("typedef ");
......
......@@ -36,6 +36,11 @@ public class Vala.CCodeUnaryExpression : CCodeExpression {
*/
public CCodeExpression! inner { get; set construct; }
public construct (CCodeUnaryOperator op, CCodeExpression! expr) {
operator = op;
inner = expr;
}
public override void write (CCodeWriter! writer) {
if (operator == CCodeUnaryOperator.PLUS) {
writer.write_string ("+");
......
......@@ -36,6 +36,15 @@ public class Vala.CCodeVariableDeclarator : CCodeDeclarator {
*/
public CCodeExpression initializer { get; set; }
public construct (string! _name) {
name = _name;
}
public construct with_initializer (string! _name, CCodeExpression init) {
name = _name;
initializer = init;
}
public override void write (CCodeWriter! writer) {
writer.write_string (name);
......
......@@ -36,6 +36,11 @@ public class Vala.CCodeWhileStatement : CCodeStatement {
*/
public CCodeStatement body { get; set; }
public construct (CCodeExpression! cond, CCodeStatement stmt = null) {
condition = cond;
body = stmt;
}
public override void write (CCodeWriter! writer) {
writer.write_indent ();
writer.write_string ("while (");
......
......@@ -65,6 +65,10 @@ public class Vala.CCodeWriter {
/* at begin of line */
private bool _bol = true;
public construct (string! _filename) {
filename = _filename;
}
/**
* Closes the file.
*/
......@@ -74,8 +78,8 @@ public class Vala.CCodeWriter {
if (file_exists) {
var changed = true;
var old_file = MappedFile.new (_filename, false, null);
var new_file = MappedFile.new (temp_filename, false, null);
var old_file = new MappedFile (_filename, false, null);
var new_file = new MappedFile (temp_filename, false, null);
var len = old_file.get_length ();
if (len == new_file.get_length ()) {
if (Memory.cmp (old_file.get_contents (), new_file.get_contents (), len) == 0) {
......
......@@ -85,7 +85,7 @@ class Vala.Compiler {
return false;
}
context.add_source_file (new SourceFile (filename = package_path, pkg = true));
context.add_source_file (new SourceFile (package_path, true));
return true;
}
......@@ -113,7 +113,7 @@ class Vala.Compiler {
foreach (string source in sources) {
if (File.test (source, FileTest.EXISTS)) {
context.add_source_file (new SourceFile (filename = source));
context.add_source_file (new SourceFile (source));
} else {
Report.error (null, "%s not found".printf (source));
}
......@@ -152,7 +152,7 @@ class Vala.Compiler {
return quit ();
}
var analyzer = new SemanticAnalyzer (memory_management = !disable_memory_management);
var analyzer = new SemanticAnalyzer (!disable_memory_management);
analyzer.analyze (context);
if (Report.get_errors () > 0) {
......@@ -168,7 +168,7 @@ class Vala.Compiler {
}
}
var code_generator = new CodeGenerator (memory_management = !disable_memory_management);
var code_generator = new CodeGenerator (!disable_memory_management);
code_generator.emit (context);
if (Report.get_errors () > 0) {
......@@ -188,7 +188,7 @@ class Vala.Compiler {
static int main (int argc, string[] argv) {
Error err = null;
var opt_context = OptionContext.@new ("- Vala Compiler");
var opt_context = new OptionContext ("- Vala Compiler");
opt_context.set_help_enabled (true);
opt_context.add_main_entries (options, null);
opt_context.parse (ref argc, out argv, out err);
......
......@@ -89,6 +89,9 @@ libvala_la_SOURCES = \
valadostatement.c \
valadostatement.h \
valadostatement.vala \
valaelementaccess.c \
valaelementaccess.h \
valaelementaccess.vala \
valaemptystatement.c \
valaemptystatement.h \
valaemptystatement.vala \
......@@ -275,9 +278,6 @@ libvala_la_SOURCES = \
valawhilestatement.c \
valawhilestatement.h \
valawhilestatement.vala \
valaelementaccess.c \
valaelementaccess.h \
valaelementaccess.vala \
valaarray.c \
valaarray.h \
valaarray.vala \
......
......@@ -414,7 +414,7 @@ type_name
{
GList *l;
ValaSourceReference *src = src(@1);
$$ = vala_type_reference_new (NULL, $1, src);
$$ = vala_type_reference_new_from_name (NULL, $1, src);
g_free ($1);
g_object_unref (src);
for (l = $2; l != NULL; l = l->next) {
......@@ -427,7 +427,7 @@ type_name
{
GList *l;
ValaSourceReference *src = src(@1);
$$ = vala_type_reference_new ($1, $3, src);
$$ = vala_type_reference_new_from_name ($1, $3, src);
g_free ($1);
g_free ($3);
g_object_unref (src);
......@@ -1011,7 +1011,7 @@ assignment
: unary_expression assignment_operator expression
{
ValaSourceReference *src = src(@2);
$$ = VALA_EXPRESSION (vala_assignment_new ($1, $2, $3, src));
$$ = VALA_EXPRESSION (vala_assignment_new ($1, $3, $2, src));
g_object_unref (src);
g_object_unref ($1);
g_object_unref ($3);
......@@ -1172,7 +1172,7 @@ local_variable_declaration
{
GList *l;
ValaSourceReference *src = src(@2);
$$ = vala_local_variable_declaration_new_var (src);
$$ = vala_local_variable_declaration_new_var_type (src);
g_object_unref (src);
for (l = $2; l != NULL; l = l->next) {
vala_local_variable_declaration_add_declarator ($$, l->data);
......@@ -1382,7 +1382,7 @@ switch_label
| DEFAULT COLON
{
ValaSourceReference *src = src(@1);
$$ = vala_switch_label_new_default (src);
$$ = vala_switch_label_new_with_default (src);
g_object_unref (src);
}
;
......@@ -1465,7 +1465,7 @@ for_statement
if (init != NULL) {
ValaSourceReference *decl_src = vala_code_node_get_source_reference (VALA_CODE_NODE (decl));
ValaMemberAccess *lhs = vala_member_access_new (NULL, vala_variable_declarator_get_name (decl), decl_src);
ValaAssignment *assign = vala_assignment_new (VALA_EXPRESSION (lhs), VALA_ASSIGNMENT_OPERATOR_SIMPLE, init, decl_src);
ValaAssignment *assign = vala_assignment_new (VALA_EXPRESSION (lhs), init, VALA_ASSIGNMENT_OPERATOR_SIMPLE, decl_src);
g_object_unref (lhs);
vala_for_statement_add_initializer (for_statement, VALA_EXPRESSION (assign));
g_object_unref (assign);
......@@ -2189,13 +2189,13 @@ formal_parameter_list
| fixed_parameters COMMA ELLIPSIS
{
ValaSourceReference *src = src(@3);
$$ = g_list_append ($1, vala_formal_parameter_new_ellipsis (src));
$$ = g_list_append ($1, vala_formal_parameter_new_with_ellipsis (src));
g_object_unref (src);
}
| ELLIPSIS
{
ValaSourceReference *src = src(@1);
$$ = g_list_append (NULL, vala_formal_parameter_new_ellipsis (src));
$$ = g_list_append (NULL, vala_formal_parameter_new_with_ellipsis (src));
g_object_unref (src);
}
;
......
......@@ -32,11 +32,16 @@ public class Vala.Array : DataType {
*/
public DataType! element_type { get; set construct; }
private string cname;
public construct (DataType! type) {
element_type = type;
}
Array () {
name = "%s[]".printf (element_type.name);
}
private string cname;
/**
* Returns the name of this data type as it is used in C code.
*
......
......@@ -52,8 +52,11 @@ public class Vala.Assignment : Expression {
* @param source reference to source code
* @return newly created assignment
*/
public static ref Assignment! new (Expression! left, AssignmentOperator op, Expression! right, SourceReference source) {
return (new Assignment (left = left, operator = op, right = right, source_reference = source));
public construct (Expression! _left, Expression! _right, AssignmentOperator _op = AssignmentOperator.SIMPLE, SourceReference _source = null) {
left = _left;
operator = _op;
right = _right;
source_reference = _source;
}