[vala/wip/issue/370: 18/20] Add support for partial classes
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/370: 18/20] Add support for partial classes
- Date: Sat, 2 Oct 2021 07:18:27 +0000 (UTC)
commit 202a14c42f635c63891291eb3d4fcf23f2dc7255
Author: Simon Werbeck <simon werbeck gmail com>
Date: Sun Mar 31 22:30:07 2013 +0200
Add support for partial classes
vala/valaclass.vala | 2 ++
vala/valanamespace.vala | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
vala/valaparser.vala | 13 +++++++++++-
vala/valascanner.vala | 9 ++++++++-
vala/valatokentype.vala | 2 ++
5 files changed, 77 insertions(+), 2 deletions(-)
---
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index ee4ed624f..a6f5ae633 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -37,6 +37,8 @@ public class Vala.Class : ObjectTypeSymbol {
*/
public bool is_abstract { get; set; }
+ public bool is_partial { get; set; }
+
/**
* Specifies whether this class is sealed. Sealed classes may not be
* sub-classed.
diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala
index d62babb63..8dc8b9069 100644
--- a/vala/valanamespace.vala
+++ b/vala/valanamespace.vala
@@ -160,6 +160,59 @@ public class Vala.Namespace : Symbol {
cl.access = SymbolAccessibility.INTERNAL;
}
+ if (cl.is_partial) {
+ var old_cl = scope.lookup (cl.name) as Class;
+ if (old_cl != null && old_cl.is_partial) {
+ if (cl.access != old_cl.access) {
+ Report.error (cl.source_reference, "partial declarations of `%s' have
conflicting accessiblity modifiers".printf (cl.name));
+ cl.error = true;
+ return;
+ }
+ if (cl.is_abstract != old_cl.is_abstract) {
+ Report.error (cl.source_reference, "partial declarations of `%s' have
conflicting abstract modifiers".printf (cl.name));
+ cl.error = true;
+ return;
+ }
+
+ foreach (Class cls in cl.get_classes ()) {
+ old_cl.add_class (cls);
+ }
+ foreach (Struct st in cl.get_structs ()) {
+ old_cl.add_struct (st);
+ }
+ foreach (Delegate d in cl.get_delegates ()) {
+ old_cl.add_delegate (d);
+ }
+ foreach (Enum en in cl.get_enums ()) {
+ old_cl.add_enum (en);
+ }
+ foreach (Constant c in cl.get_constants ()) {
+ old_cl.add_constant (c);
+ }
+ foreach (Field f in cl.get_fields ()) {
+ old_cl.add_field (f);
+ }
+ foreach (Method m in cl.get_methods ()) {
+ if (m != cl.default_construction_method) {
+ old_cl.add_method (m);
+ }
+ }
+ foreach (Property prop in cl.get_properties ()) {
+ //FIXME old_cl.add_property (prop);
+ }
+ foreach (Signal sig in cl.get_signals ()) {
+ old_cl.add_signal (sig);
+ }
+ foreach (Attribute a in cl.attributes) {
+ if (old_cl.get_attribute (a.name) == null) {
+ old_cl.attributes.append(a);
+ }
+ }
+
+ return;
+ }
+ }
+
if (cl.owner == null) {
cl.source_reference.file.add_node (cl);
}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 4bd0114c9..0aa50e7d7 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -61,7 +61,8 @@ public class Vala.Parser : CodeVisitor {
STATIC,
VIRTUAL,
ASYNC,
- SEALED
+ SEALED,
+ PARTIAL
}
public Parser () {
@@ -253,6 +254,7 @@ public class Vala.Parser : CodeVisitor {
case TokenType.OVERRIDE:
case TokenType.OWNED:
case TokenType.PARAMS:
+ case TokenType.PARTIAL:
case TokenType.PRIVATE:
case TokenType.PROTECTED:
case TokenType.PUBLIC:
@@ -2734,6 +2736,7 @@ public class Vala.Parser : CodeVisitor {
case TokenType.NEW:
case TokenType.OVERRIDE:
case TokenType.PRIVATE:
+ case TokenType.PARTIAL:
case TokenType.PROTECTED:
case TokenType.PUBLIC:
case TokenType.SEALED:
@@ -2842,6 +2845,9 @@ public class Vala.Parser : CodeVisitor {
if (ModifierFlags.SEALED in flags) {
cl.is_sealed = true;
}
+ if (ModifierFlags.PARTIAL in flags) {
+ cl.is_partial = true;
+ }
if (ModifierFlags.EXTERN in flags) {
cl.is_extern = true;
}
@@ -3529,6 +3535,10 @@ public class Vala.Parser : CodeVisitor {
next ();
flags |= ModifierFlags.EXTERN;
break;
+ case TokenType.PARTIAL:
+ next ();
+ flags |= ModifierFlags.PARTIAL;
+ break;
case TokenType.SEALED:
next ();
flags |= ModifierFlags.SEALED;
@@ -3871,6 +3881,7 @@ public class Vala.Parser : CodeVisitor {
case TokenType.NAMESPACE:
case TokenType.NEW:
case TokenType.OVERRIDE:
+ case TokenType.PARTIAL:
case TokenType.PRIVATE:
case TokenType.PROTECTED:
case TokenType.PUBLIC:
diff --git a/vala/valascanner.vala b/vala/valascanner.vala
index 36f274e6f..daeb97feb 100644
--- a/vala/valascanner.vala
+++ b/vala/valascanner.vala
@@ -533,7 +533,14 @@ public class Vala.Scanner {
}
break;
case 'p':
- if (matches (begin, "private")) return TokenType.PRIVATE;
+ switch (begin[1]) {
+ case 'r':
+ if (matches (begin, "private")) return TokenType.PRIVATE;
+ break;
+ case 'a':
+ if (matches (begin, "partial")) return TokenType.PARTIAL;
+ break;
+ }
break;
case 'u':
if (matches (begin, "unowned")) return TokenType.UNOWNED;
diff --git a/vala/valatokentype.vala b/vala/valatokentype.vala
index 9cc6d1c74..2c64ec1b0 100644
--- a/vala/valatokentype.vala
+++ b/vala/valatokentype.vala
@@ -115,6 +115,7 @@ public enum Vala.TokenType {
OVERRIDE,
OWNED,
PARAMS,
+ PARTIAL,
PERCENT,
PLUS,
PRIVATE,
@@ -249,6 +250,7 @@ public enum Vala.TokenType {
case OVERRIDE: return "`override'";
case OWNED: return "`owned'";
case PARAMS: return "`params'";
+ case PARTIAL: return "`partial'";
case PERCENT: return "`%'";
case PLUS: return "`+'";
case PRIVATE: return "`private'";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]