From 7cafb62f370c65c729e53de51839d2a74ae9b4f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Sat, 2 Sep 2006 15:49:13 +0000 Subject: [PATCH] prepare to support protected members MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2006-09-02 Jürg Billeter * vala/scanner.l, vala/parser.y, vala/valasemanticanalyzer.vala, vala/valacodegenerator.vala, vala/valainterfacewriter.vala, vala/valamemberaccessibility.vala: prepare to support protected members svn path=/trunk/; revision=120 --- vala/ChangeLog | 7 +++++++ vala/vala/parser.y | 7 ++++++- vala/vala/scanner.l | 3 ++- vala/vala/valacodegenerator.vala | 8 ++++---- vala/vala/valainterfacewriter.vala | 24 ++++++++++++------------ vala/vala/valamemberaccessibility.vala | 1 + vala/vala/valasemanticanalyzer.vala | 6 +++--- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/vala/ChangeLog b/vala/ChangeLog index 9cf9646..8ecc7e7 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,5 +1,12 @@ 2006-09-02 Jürg Billeter + * vala/scanner.l, vala/parser.y, vala/valasemanticanalyzer.vala, + vala/valacodegenerator.vala, vala/valainterfacewriter.vala, + vala/valamemberaccessibility.vala: prepare to support protected + members + +2006-09-02 Jürg Billeter + * vala/parser.y: don't set parent_node in parser * vala/valasemanticanalyzer.vala: support string + operator * vala/valaassignment.vala, vala/valabinaryexpression.vala, diff --git a/vala/vala/parser.y b/vala/vala/parser.y index 93a11b1..86925b2 100644 --- a/vala/vala/parser.y +++ b/vala/vala/parser.y @@ -175,8 +175,9 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %token VALA_NULL "null" %token OUT "out" %token OVERRIDE "override" -%token PUBLIC "public" %token PRIVATE "private" +%token PROTECTED "protected" +%token PUBLIC "public" %token REF "ref" %token RETURN "return" %token SET "set" @@ -1957,6 +1958,10 @@ access_modifier { $$ = VALA_MEMBER_ACCESSIBILITY_PUBLIC; } + | PROTECTED + { + $$ = VALA_MEMBER_ACCESSIBILITY_PROTECTED; + } | PRIVATE { $$ = VALA_MEMBER_ACCESSIBILITY_PRIVATE; diff --git a/vala/vala/scanner.l b/vala/vala/scanner.l index 2c54724..a6b366c 100644 --- a/vala/vala/scanner.l +++ b/vala/vala/scanner.l @@ -153,8 +153,9 @@ literal ({integer_literal}|{real_literal}|{character_literal}|{string_literal "null" { uploc; return VALA_NULL; } "out" { uploc; return OUT; } "override" { uploc; return OVERRIDE; } -"public" { uploc; return PUBLIC; } "private" { uploc; return PRIVATE; } +"protected" { uploc; return PROTECTED; } +"public" { uploc; return PUBLIC; } "ref" { uploc; return REF; } "set" { uploc; return SET; } "signal" { uploc; return SIGNAL; } diff --git a/vala/vala/valacodegenerator.vala b/vala/vala/valacodegenerator.vala index eee2ac4..e5675b5 100644 --- a/vala/vala/valacodegenerator.vala +++ b/vala/vala/valacodegenerator.vala @@ -843,7 +843,7 @@ public class Vala.CodeGenerator : CodeVisitor { var ctypedef = new CCodeTypeDefinition (cb.return_type.get_cname (), cfundecl); - if (cb.access == MemberAccessibility.PUBLIC) { + if (cb.access != MemberAccessibility.PRIVATE) { header_type_declaration.append (ctypedef); } else { source_type_member_declaration.append (ctypedef); @@ -861,7 +861,7 @@ public class Vala.CodeGenerator : CodeVisitor { cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("%s%s".printf (c.get_cname (), arr), (CCodeExpression) c.initializer.ccodenode)); cdecl.modifiers = CCodeModifiers.STATIC; - if (c.access == MemberAccessibility.PUBLIC) { + if (c.access != MemberAccessibility.PRIVATE) { header_type_member_declaration.append (cdecl); } else { source_type_member_declaration.append (cdecl); @@ -870,7 +870,7 @@ public class Vala.CodeGenerator : CodeVisitor { } public override void visit_field (Field! f) { - if (f.access == MemberAccessibility.PUBLIC) { + if (f.access != MemberAccessibility.PRIVATE) { instance_struct.add_field (f.type_reference.get_cname (), f.get_cname ()); } else if (f.access == MemberAccessibility.PRIVATE) { if (f.instance) { @@ -1028,7 +1028,7 @@ public class Vala.CodeGenerator : CodeVisitor { /* real function declaration and definition not needed * for abstract methods */ if (!m.is_abstract) { - if (m.access == MemberAccessibility.PUBLIC && !(m.is_virtual || m.overrides)) { + if (m.access != MemberAccessibility.PRIVATE && !(m.is_virtual || m.overrides)) { /* public methods need function declaration in * header file except virtual/overridden methods */ header_type_member_declaration.append (function.copy ()); diff --git a/vala/vala/valainterfacewriter.vala b/vala/vala/valainterfacewriter.vala index 0d4dff6..ad73040 100644 --- a/vala/vala/valainterfacewriter.vala +++ b/vala/vala/valainterfacewriter.vala @@ -87,7 +87,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_begin_class (Class! cl) { - if (cl.access != MemberAccessibility.PUBLIC) { + if (cl.access == MemberAccessibility.PRIVATE) { internal_scope = true; return; } @@ -118,7 +118,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_end_class (Class! cl) { - if (cl.access != MemberAccessibility.PUBLIC) { + if (cl.access == MemberAccessibility.PRIVATE) { internal_scope = false; return; } @@ -128,7 +128,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_begin_struct (Struct! st) { - if (st.access != MemberAccessibility.PUBLIC) { + if (st.access == MemberAccessibility.PRIVATE) { internal_scope = true; return; } @@ -145,7 +145,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_end_struct (Struct! st) { - if (st.access != MemberAccessibility.PUBLIC) { + if (st.access == MemberAccessibility.PRIVATE) { internal_scope = false; return; } @@ -155,7 +155,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_begin_interface (Interface! iface) { - if (iface.access != MemberAccessibility.PUBLIC) { + if (iface.access == MemberAccessibility.PRIVATE) { internal_scope = true; return; } @@ -169,7 +169,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_end_interface (Interface! iface) { - if (iface.access != MemberAccessibility.PUBLIC) { + if (iface.access == MemberAccessibility.PRIVATE) { internal_scope = false; return; } @@ -179,7 +179,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_begin_enum (Enum! en) { - if (en.access != MemberAccessibility.PUBLIC) { + if (en.access == MemberAccessibility.PRIVATE) { internal_scope = true; return; } @@ -194,7 +194,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_end_enum (Enum! en) { - if (en.access != MemberAccessibility.PUBLIC) { + if (en.access == MemberAccessibility.PRIVATE) { internal_scope = false; return; } @@ -230,7 +230,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_field (Field! f) { - if (internal_scope || f.access != MemberAccessibility.PUBLIC) { + if (internal_scope || f.access == MemberAccessibility.PRIVATE) { return; } @@ -321,7 +321,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_begin_callback (Callback! cb) { - if (internal_scope || cb.access != MemberAccessibility.PUBLIC) { + if (internal_scope || cb.access == MemberAccessibility.PRIVATE) { return; } @@ -351,7 +351,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_begin_method (Method! m) { - if (internal_scope || m.access != MemberAccessibility.PUBLIC || m.overrides) { + if (internal_scope || m.access == MemberAccessibility.PRIVATE || m.overrides) { return; } @@ -458,7 +458,7 @@ public class Vala.InterfaceWriter : CodeVisitor { } public override void visit_begin_signal (Signal! sig) { - if (internal_scope || sig.access != MemberAccessibility.PUBLIC) { + if (internal_scope || sig.access == MemberAccessibility.PRIVATE) { return; } diff --git a/vala/vala/valamemberaccessibility.vala b/vala/vala/valamemberaccessibility.vala index 6e49126..b891219 100644 --- a/vala/vala/valamemberaccessibility.vala +++ b/vala/vala/valamemberaccessibility.vala @@ -25,5 +25,6 @@ using GLib; public enum Vala.MemberAccessibility { PRIVATE, INTERNAL, + PROTECTED, PUBLIC } diff --git a/vala/vala/valasemanticanalyzer.vala b/vala/vala/valasemanticanalyzer.vala index 1125560..af98232 100644 --- a/vala/vala/valasemanticanalyzer.vala +++ b/vala/vala/valasemanticanalyzer.vala @@ -122,7 +122,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } public override void visit_field (Field! f) { - if (f.access == MemberAccessibility.PUBLIC) { + if (f.access != MemberAccessibility.PRIVATE) { if (f.type_reference.data_type != null) { /* is null if it references a type parameter */ current_source_file.add_symbol_dependency (f.type_reference.data_type.symbol, SourceFileDependencyType.HEADER_SHALLOW); @@ -761,7 +761,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { access = ((Method) member).access; } - if (access != MemberAccessibility.PUBLIC) { + if (access == MemberAccessibility.PRIVATE) { var target_type = (DataType) member.symbol.parent_symbol.node; var this_type = find_parent_type (current_symbol); @@ -1433,7 +1433,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { var m = (Method) a.right.symbol_reference.node; - if (m.instance && m.access == MemberAccessibility.PUBLIC) { + if (m.instance && m.access != MemberAccessibility.PRIVATE) { /* TODO: generate wrapper function */ ma.error = true; -- 2.7.4