2006-05-18 Jürg Billeter <j@bitron.ch>
+ * vala/parser.y: support namespace attributes
+ * vala/valaattributeprocessor.vala: process namespace and class
+ attributes
+ * vala/valacodegenerator.vala: use correct symbol names
+ * vala/valamethod.vala: add cname
+ * vala/valanamespace.vala: add cprefix, support cprefix attribute
+ * vala/valastruct.vala: prefix cname with namespace cprefix
+ * bindings/GLib.vala: add tolower to unichar
+ * valac/parser.y: rename namespace attribute cname to lower_case_cprefix
+
+2006-05-18 Jürg Billeter <j@bitron.ch>
+
* update reference and property annotations
* switch string struct to utf-8
* valac/context.c: set source file in root namespace
public struct unichar {
[CCode (cname = "g_unichar_isupper")]
public bool isupper ();
+ [CCode (cname = "g_unichar_tolower")]
+ public unichar tolower ();
}
[ReferenceType ()]
}
[Import ()]
-[CCode (cname = "g", cprefix = "G", include_filename = "glib.h")]
+[CCode (cprefix = "G", lower_case_cprefix = "g_", include_filename = "glib.h")]
namespace GLib {
public struct Path {
public static ref string get_basename (string file_name);
: comment opt_attributes NAMESPACE IDENTIFIER
{
current_namespace = vala_namespace_new ($4, src_com (@4, $1));
+ VALA_CODE_NODE(current_namespace)->attributes = $2;
}
namespace_body
{
public void process (CodeContext context) {
context.accept (this);
}
+
+ public override void visit_begin_namespace (Namespace ns) {
+ ns.process_attributes ();
+ }
public override void visit_begin_struct (Struct st) {
st.process_attributes ();
}
+
+ public override void visit_begin_class (Class cl) {
+ cl.process_attributes ();
+ }
}
}
}
public override void visit_end_method (Method m) {
- var cmethod_decl = new CCodeFunction (name = m.name, return_type = "void");
- function = new CCodeFunction (name = m.name, return_type = "void");
+ var cmethod_decl = new CCodeFunction (name = m.get_cname (), return_type = "void");
+ function = new CCodeFunction (name = m.get_cname (), return_type = "void");
if (m.access == MemberAccessibility.PUBLIC) {
header_type_member_declaration.append (cmethod_decl);
public override void visit_literal_expression (LiteralExpression expr) {
expr.ccodenode = expr.literal.ccodenode;
}
-
+
public override void visit_simple_name (SimpleName expr) {
- /* local variable */
- expr.ccodenode = new CCodeIdentifier (name = expr.name);
+ if (expr.symbol_reference.node is Method) {
+ var m = (Method) expr.symbol_reference.node;
+ expr.ccodenode = new CCodeIdentifier (name = m.get_cname ());
+ } else {
+ expr.ccodenode = new CCodeIdentifier (name = expr.name);
+ }
}
public override void visit_parenthesized_expression (ParenthesizedExpression expr) {
}
public override void visit_member_access (MemberAccess expr) {
- expr.ccodenode = new CCodeIdentifier (name = expr.member_name);
+ if (expr.symbol_reference.node is Method) {
+ var m = (Method) expr.symbol_reference.node;
+ expr.ccodenode = new CCodeIdentifier (name = m.get_cname ());
+ } else {
+ expr.ccodenode = new CCodeIdentifier (name = expr.member_name);
+ }
}
public override void visit_invocation_expression (InvocationExpression expr) {
public TypeReference return_type { get; construct; }
public SourceReference source_reference { get; construct; }
public weak CodeNode parent_type;
- ref Statement _body;
+ Statement _body;
public Statement body {
get {
return _body;
}
public MemberAccessibility access;
public bool instance = true;
- ref List<ref FormalParameter> parameters;
+ List<FormalParameter> parameters;
+ public string cname;
+
+ Symbol dummy_symbol; // dummy type reference for broken dependency handling
public static ref Method new (string name, TypeReference return_type, SourceReference source) {
return (new Method (name = name, return_type = return_type, source_reference = source));
}
public string get_cname () {
+ if (cname == null) {
+ var parent = symbol.parent_symbol.node;
+ if (parent is Struct) {
+ cname = "%s_%s".printf (((Struct) parent).get_lower_case_cname (null), name);
+ } else if (parent is Namespace) {
+ cname = "%s%s".printf (((Namespace) parent).get_lower_case_cprefix (), name);
+ } else {
+ stderr.printf ("internal error: method is neither in struct nor in namespace\n");
+ }
+ }
+ return cname;
+ }
+
+ public void set_cname (string cname) {
+ this.cname = cname;
}
}
}
List<Enum> enums;
List<Field> fields;
+ public string cprefix;
public string lower_case_cprefix;
public static ref Namespace new (string name, SourceReference source) {
}
}
- result.append_unichar (c);
+ result.append_unichar (c.tolower ());
first = false;
i = i.next_char ();
return result.str;
}
+ public string get_cprefix () {
+ if (cprefix == null) {
+ if (name == null) {
+ cprefix = "";
+ } else {
+ cprefix = name;
+ }
+ }
+ return cprefix;
+ }
+
+ public void set_cprefix (string cprefix) {
+ this.cprefix = cprefix;
+ }
+
public string get_lower_case_cprefix () {
if (lower_case_cprefix == null) {
if (name == null) {
public void set_lower_case_cprefix (string cprefix) {
this.lower_case_cprefix = cprefix;
}
+
+ void process_ccode_attribute (Attribute a) {
+ foreach (NamedArgument arg in a.args) {
+ if (arg.name.collate ("cprefix") == 0) {
+ /* this will already be checked during semantic analysis */
+ if (arg.argument is LiteralExpression) {
+ var lit = ((LiteralExpression) arg.argument).literal;
+ if (lit is StringLiteral) {
+ set_cprefix (((StringLiteral) lit).eval ());
+ }
+ }
+ } else if (arg.name.collate ("lower_case_cprefix") == 0) {
+ /* this will already be checked during semantic analysis */
+ if (arg.argument is LiteralExpression) {
+ var lit = ((LiteralExpression) arg.argument).literal;
+ if (lit is StringLiteral) {
+ set_lower_case_cprefix (((StringLiteral) lit).eval ());
+ }
+ }
+ }
+ }
+ }
+
+ public void process_attributes () {
+ foreach (Attribute a in attributes) {
+ if (a.name.collate ("CCode") == 0) {
+ process_ccode_attribute (a);
+ }
+ }
+ }
}
}
public override string get_cname () {
if (cname == null) {
- cname = name;
+ cname = "%s%s".printf (@namespace.get_cprefix (), name);
}
return cname;
}
for (al = anno->argument_list; al != NULL; al = al->next) {
ValaNamedArgument *arg = al->data;
- if (strcmp (arg->name, "cname") == 0) {
- current_namespace->lower_case_cname = g_strdup_printf ("%s_", eval_string (arg->expression->str));
+ if (strcmp (arg->name, "lower_case_cprefix") == 0) {
+ current_namespace->lower_case_cname = g_strdup (eval_string (arg->expression->str));
current_namespace->upper_case_cname = g_ascii_strup (current_namespace->lower_case_cname, -1);
} else if (strcmp (arg->name, "cprefix") == 0) {
current_namespace->cprefix = eval_string (arg->expression->str);