+2006-05-18 Jürg Billeter <j@bitron.ch>
+
+ * vala/parser.y: support member and access modifiers, static methods
+ * vala/valaattributeprocessor.vala: process method attributes
+ * vala/valaclass.vala: don't set parent_type member of children
+ * vala/valaconstant.vala: remove unnecessary parent_type member
+ * vala/valafield.vala: remove unnecessary parent_type member
+ * vala/valamethod.vala: support cname attribute
+ * vala/valanamespace.vala: add methods
+ * vala/valaproperty.vala: remove unnecessary parent_type member
+ * vala/valastruct.vala: don't set parent_type member of children
+
2006-05-18 Jürg Billeter <j@bitron.ch>
* vala/parser.y: adapt to BinaryOperator enum changes
static ValaNamespace *current_namespace;
static ValaStruct *current_struct;
+typedef enum {
+ VALA_MODIFIER_NONE,
+ VALA_MODIFIER_ABSTRACT = 1 << 0,
+ VALA_MODIFIER_OVERRIDE = 1 << 1,
+ VALA_MODIFIER_STATIC = 1 << 2,
+ VALA_MODIFIER_VIRTUAL = 1 << 3,
+} ValaModifier;
+
int yylex (YYSTYPE *yylval_param, YYLTYPE *yylloc_param, ValaParser *parser);
static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
%}
%type <statement> return_statement
%type <namespace> namespace_declaration
%type <class> class_declaration
+%type <num> opt_access_modifier
+%type <num> access_modifier
+%type <num> opt_modifiers
+%type <num> modifiers
+%type <num> modifier
%type <list> opt_class_base
%type <list> class_base
%type <list> type_list
vala_namespace_add_field (current_namespace, $1);
}
| method_declaration
+ {
+ vala_namespace_add_method (current_namespace, $1);
+ }
;
class_declaration
opt_access_modifier
: /* empty */
+ {
+ $$ = 0;
+ }
| access_modifier
;
access_modifier
: PUBLIC
+ {
+ $$ = VALA_MEMBER_ACCESSIBILITY_PUBLIC;
+ }
| PRIVATE
+ {
+ $$ = VALA_MEMBER_ACCESSIBILITY_PRIVATE;
+ }
;
opt_modifiers
: /* empty */
+ {
+ $$ = VALA_MODIFIER_NONE;
+ }
| modifiers
;
modifiers
: modifier
| modifiers modifier
+ {
+ if (($1 & $2) == $2) {
+ /* modifier specified twice, signal error */
+ }
+ $$ = $1 | $2;
+ }
;
modifier
: ABSTRACT
+ {
+ $$ = VALA_MODIFIER_ABSTRACT;
+ }
| OVERRIDE
+ {
+ $$ = VALA_MODIFIER_OVERRIDE;
+ }
| STATIC
+ {
+ $$ = VALA_MODIFIER_STATIC;
+ }
| VIRTUAL
+ {
+ $$ = VALA_MODIFIER_VIRTUAL;
+ }
;
opt_class_base
GList *l;
$$ = vala_method_new ($7, $6, src_com (@7, $1));
+ if ($3 != 0) {
+ $$->access = $3;
+ }
+ if (($4 & VALA_MODIFIER_STATIC) == VALA_MODIFIER_STATIC) {
+ $$->instance = FALSE;
+ }
VALA_CODE_NODE($$)->attributes = $2;
for (l = $9; l != NULL; l = l->next) {
public override void visit_begin_class (Class cl) {
cl.process_attributes ();
}
+
+ public override void visit_begin_method (Method m) {
+ m.process_attributes ();
+ }
}
}
public void add_property (Property prop) {
properties.append (prop);
- prop.parent_type = this;
if (prop.set_accessor != null && prop.set_accessor.body == null) {
/* automatic property accessor body generation */
public TypeReference type_reference { get; construct; }
public Expression initializer { get; construct; }
public SourceReference source_reference { get; construct; }
- public weak CodeNode parent_type;
public static ref Constant new (string name, TypeReference type, Expression init, SourceReference source) {
return (new Constant (name = name, type_reference = type, initializer = init, source_reference = source));
public TypeReference type_reference { get; construct; }
public Expression initializer { get; construct; }
public SourceReference source_reference { get; construct; }
- public weak CodeNode parent_type;
public static ref Field new (string name, TypeReference type, Expression init, SourceReference source) {
return (new Field (name = name, type_reference = type, initializer = init, source_reference = source));
public string name { get; construct; }
public TypeReference return_type { get; construct; }
public SourceReference source_reference { get; construct; }
- public weak CodeNode parent_type;
Statement _body;
public Statement body {
get {
public void set_cname (string cname) {
this.cname = cname;
}
+
+ void process_ccode_attribute (Attribute a) {
+ foreach (NamedArgument arg in a.args) {
+ if (arg.name.collate ("cname") == 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_cname (((StringLiteral) lit).eval ());
+ }
+ }
+ }
+ }
+ }
+
+ public void process_attributes () {
+ foreach (Attribute a in attributes) {
+ if (a.name.collate ("CCode") == 0) {
+ process_ccode_attribute (a);
+ }
+ }
+ }
}
}
List<Struct> structs;
List<Enum> enums;
List<Field> fields;
+ List<Method> methods;
public string cprefix;
public string lower_case_cprefix;
fields.append (f);
}
+ public void add_method (Method m) {
+ methods.append (m);
+ }
+
public override void accept (CodeVisitor visitor) {
visitor.visit_begin_namespace (this);
f.accept (visitor);
}
+ foreach (Method m in methods) {
+ m.accept (visitor);
+ }
+
visitor.visit_end_namespace (this);
}
public PropertyAccessor get_accessor { get; construct; }
public PropertyAccessor set_accessor { get; construct; }
public SourceReference source_reference { get; construct; }
- public weak CodeNode parent_type;
public MemberAccessibility access;
public static ref Property new (string name, TypeReference type, PropertyAccessor get_accessor, PropertyAccessor set_accessor, SourceReference source) {
public void add_field (Field f) {
fields.append (f);
- f.parent_type = this;
}
public void add_method (Method m) {
methods.append (m);
- m.parent_type = this;
}
public override void accept (CodeVisitor visitor) {