+2006-08-10 Jürg Billeter <j@bitron.ch>
+
+ * vala/parser.y: support constants in namespaces and constants without
+ initializer
+ * vala/valasemanticanalyzer.vala: depend on implemented interfaces
+ * vala/valacodegenerator.vala: always include glib-object.h for
+ interfaces, append NULL to variable argument list calls
+ * vala/valainterfacewriter.vala: support constants and ellipsis
+ parameters
+ * vala/valaconstant.vala: make initializer optional
+ * vala/valainterface.vala: implement get_lower_case_cprefix ()
+ * vala/valanamespace.vala: support constants
+
2006-08-10 Jürg Billeter <j@bitron.ch>
* vala/scanner.l: accept real literals with trailing dot
%type <flags> flags_declaration
%type <callback> callback_declaration
%type <constant> constant_declaration
-%type <variable_declarator> constant_declarator
%type <field> field_declaration
%type <list> variable_declarators
%type <variable_declarator> variable_declarator
current_namespace_implicit = FALSE;
}
}
+ | constant_declaration
+ {
+ /* skip declarations with errors */
+ if ($1 != NULL) {
+ vala_namespace_add_constant (current_namespace, $1);
+ g_object_unref ($1);
+ }
+ }
| field_declaration
{
/* skip declarations with errors */
;
constant_declaration
- : comment opt_attributes opt_access_modifier CONST type constant_declarator SEMICOLON
+ : comment opt_attributes opt_access_modifier CONST type variable_declarator SEMICOLON
{
ValaSourceReference *src = src_com(@5, $1);
$$ = vala_constant_new (vala_variable_declarator_get_name ($6), $5, vala_variable_declarator_get_initializer ($6), src);
}
;
-constant_declarator
- : IDENTIFIER ASSIGN initializer
- {
- ValaSourceReference *src = src(@1);
- $$ = vala_variable_declarator_new ($1, $3, src);
- g_object_unref (src);
- g_free ($1);
- g_object_unref ($3);
- }
- ;
-
field_declaration
: comment opt_attributes opt_access_modifier opt_modifiers type variable_declarator SEMICOLON
{
g_free (name);
g_object_unref (src);
+ VALA_CODE_NODE(current_interface)->attributes = $2;
+ if ($3 != 0) {
+ VALA_DATA_TYPE(current_interface)->access = $3;
+ }
if ($7 != NULL) {
GList *l;
for (l = $7; l != NULL; l = l->next) {
next_temp_var_id = 0;
header_begin.append (new CCodeIncludeDirective ("glib.h"));
+ header_begin.append (new CCodeIncludeDirective ("glib-object.h"));
source_include_directives.append (new CCodeIncludeDirective (source_file.get_cheader_filename (), true));
ref List<string> used_includes = null;
used_includes.append ("glib.h");
+ used_includes.append ("glib-object.h");
used_includes.append (source_file.get_cheader_filename ());
foreach (string filename1 in source_file.get_header_external_includes ()) {
}
}
+ bool ellipsis = false;
+
var i = 1;
foreach (Expression arg in expr.get_argument_list ()) {
/* explicitly use strong reference as ccall gets
ref CCodeExpression cexpr = (CCodeExpression) arg.ccodenode;
if (params != null) {
var param = (FormalParameter) params.data;
+ ellipsis = param.ellipsis;
if (!param.ellipsis
&& param.type_reference.data_type != null
&& param.type_reference.data_type.is_reference_type ()
var param = (FormalParameter) params.data;
if (param.ellipsis) {
+ ellipsis = true;
break;
}
if (m != null && m.instance && m.instance_last) {
ccall.add_argument (instance);
+ } else if (ellipsis) {
+ // ensure variable argument list ends with NULL
+ ccall.add_argument (new CCodeConstant ("NULL"));
}
if (m != null && m.instance && m.returns_modified_pointer) {
var params = m.get_parameters ();
var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ()));
+
+ bool ellipsis = false;
- var i = 1;
+ int i = 1;
foreach (Expression arg in expr.get_argument_list ()) {
/* explicitly use strong reference as ccall gets
* unrefed at end of inner block
ref CCodeExpression cexpr = (CCodeExpression) arg.ccodenode;
if (params != null) {
var param = (FormalParameter) params.data;
+ ellipsis = param.ellipsis;
if (!param.ellipsis
&& param.type_reference.data_type != null
&& param.type_reference.data_type.is_reference_type ()
var param = (FormalParameter) params.data;
if (param.ellipsis) {
+ ellipsis = true;
break;
}
params = params.next;
}
+
+ if (ellipsis) {
+ // ensure variable argument list ends with NULL
+ ccall.add_argument (new CCodeConstant ("NULL"));
+ }
expr.ccodenode = ccall;
}
/**
* The value of this constant.
*/
- public Expression! initializer { get; set construct; }
+ public Expression initializer { get; set; }
private string cname;
* @param source reference to source code
* @return newly created constant
*/
- public construct (string! _name, TypeReference! type, Expression! init, SourceReference source) {
+ public construct (string! _name, TypeReference! type, Expression init, SourceReference source) {
name = _name;
type_reference = type;
initializer = init;
public override void accept (CodeVisitor! visitor) {
type_reference.accept (visitor);
-
- initializer.accept (visitor);
+
+ if (initializer != null) {
+ initializer.accept (visitor);
+ }
visitor.visit_constant (this);
}
return "%s%s%s".printf (@namespace.get_lower_case_cprefix (), infix, get_lower_case_csuffix ());
}
+ public override ref string get_lower_case_cprefix () {
+ return "%s_".printf (get_lower_case_cname (null));
+ }
+
public override ref string get_upper_case_cname (string infix) {
return get_lower_case_cname (infix).up ();
}
}
public override void visit_constant (Constant! c) {
+ if (internal_scope) {
+ return;
+ }
+
+ write_indent ();
+ write_string ("public const ");
+ write_string (c.type_reference.data_type.symbol.get_full_name ());
+
+ write_string (" ");
+ write_identifier (c.name);
+ write_string (";");
+ write_newline ();
}
public override void visit_field (Field! f) {
first = false;
}
+ if (param.ellipsis) {
+ write_string ("...");
+ continue;
+ }
+
if (param.type_reference.reference_to_value_type ||
param.type_reference.takes_ownership) {
write_string ("ref ");
private List<Enum> enums;
private List<Flags> flags_;
private List<Callback> callbacks;
+ private List<Constant> constants;
private List<Field> fields;
private List<Method> methods;
return classes.copy ();
}
+ /**
+ * Adds the specified constant to this namespace.
+ *
+ * @param constant a constant
+ */
+ public void add_constant (Constant! constant) {
+ constants.append (constant);
+ }
+
/**
* Adds the specified field to this namespace.
*
cb.accept (visitor);
}
+ foreach (Constant c in constants) {
+ c.accept (visitor);
+ }
+
foreach (Field f in fields) {
f.accept (visitor);
}
if (cl.base_class != null) {
current_source_file.add_symbol_dependency (cl.base_class.symbol, SourceFileDependencyType.HEADER_FULL);
}
+
+ foreach (TypeReference base_type_reference in cl.get_base_types ()) {
+ current_source_file.add_symbol_dependency (base_type_reference.data_type.symbol, SourceFileDependencyType.HEADER_FULL);
+ }
}
public override void visit_end_class (Class! cl) {