Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Make accept a generic method #21

Merged
merged 2 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/src/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class Node {
Iterable<String> get variables;

/// Calls the appropriate [Visitor] method on [this] and returns the result.
dynamic accept(Visitor visitor);
T accept<T>(Visitor<T> visitor);
}

/// A single variable.
Expand All @@ -38,7 +38,7 @@ class VariableNode implements Node {
VariableNode(this.name, [this.span]);

@override
dynamic accept(Visitor visitor) => visitor.visitVariable(this);
T accept<T>(Visitor<T> visitor) => visitor.visitVariable(this);

@override
String toString() => name;
Expand All @@ -64,7 +64,7 @@ class NotNode implements Node {
NotNode(this.child, [this.span]);

@override
dynamic accept(Visitor visitor) => visitor.visitNot(this);
T accept<T>(Visitor<T> visitor) => visitor.visitNot(this);

@override
String toString() =>
Expand Down Expand Up @@ -97,7 +97,7 @@ class OrNode implements Node {
OrNode(this.left, this.right);

@override
dynamic accept(Visitor visitor) => visitor.visitOr(this);
T accept<T>(Visitor<T> visitor) => visitor.visitOr(this);

@override
String toString() {
Expand Down Expand Up @@ -136,7 +136,7 @@ class AndNode implements Node {
AndNode(this.left, this.right);

@override
dynamic accept(Visitor visitor) => visitor.visitAnd(this);
T accept<T>(Visitor<T> visitor) => visitor.visitAnd(this);

@override
String toString() {
Expand Down Expand Up @@ -179,7 +179,7 @@ class ConditionalNode implements Node {
ConditionalNode(this.condition, this.whenTrue, this.whenFalse);

@override
dynamic accept(Visitor visitor) => visitor.visitConditional(this);
T accept<T>(Visitor<T> visitor) => visitor.visitConditional(this);

@override
String toString() {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class Visitor<T> {
///
/// The default implementations of this visitor's methods just traverse the AST
/// and do nothing with it.
abstract class RecursiveVisitor implements Visitor {
abstract class RecursiveVisitor implements Visitor<void> {
const RecursiveVisitor();

@override
Expand Down