Commit 090b89bb authored by Sebastian Biewer's avatar Sebastian Biewer
Browse files

Visitor pattern part 2

parent 212058bc
......@@ -12,6 +12,10 @@ export class ConditionDeclaration extends Node {
return this.childNodes[0] as BooleanExpression;
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitConditionDeclaration(this);
}
indentedString(indent: string): string {
return `${indent}condition ${this.name} with ${this.expression.toString()};`;
}
......
......@@ -10,6 +10,10 @@ export class MainAgent extends Node {
return this.childNodes[0] as StatementBlock;
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitMainAgent(this);
}
indentedString(indent: string): string {
return `mainAgent ${this.body.indentedString(indent)}`;
}
......
......@@ -12,6 +12,10 @@ export class Monitor extends Node {
return this.childNodes as ClassDeclaration[];
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitMonitor(this);
}
indentedString(_: string): string {
const declarationString = this.declarations.map(function(declaration) {
declaration.indentedString(Node.INDENT);
......
......@@ -18,6 +18,10 @@ export class ProcedureDeclaration extends Node {
return this.childNodes[this.childNodes.length-1] as StatementBlock;
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitProcedureDeclaration(this);
}
indentedString(indent: string): string {
const parameterString = this.parameters.map(function(parameter) {
return parameter.toString();
......
......@@ -10,6 +10,10 @@ export class ProcedureParameter extends Node {
return this.childNodes[0] as TypeNode;
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitProcedureParameter(this);
}
indentedString(_: string): string {
return `${this.typeNode.toString()} ${this.name}`;
}
......
......@@ -12,6 +12,10 @@ export class Program extends Node {
return this.childNodes as ProgramDeclaration[];
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitProgram(this);
}
indentedString(indent: string) : string {
return this.childNodes.map(function(child) {
return child.indentedString(indent);
......
......@@ -10,6 +10,10 @@ export class Struct extends Node {
return this.childNodes as ClassDeclaration[];
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitStruct(this);
}
indentedString(_: string): string {
const declarationString = this.declarations.map(function(declaration) {
declaration.indentedString(Node.INDENT);
......
......@@ -14,6 +14,10 @@ export class VariableDeclarations extends Node {
return this.childNodes.slice(1, this.childNodes.length) as VariableDeclarator[];
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitVariableDeclarations(this);
}
// Backwards compatibility
......
......@@ -25,6 +25,10 @@ export class VariableDeclarator extends Node {
return (this.parent as VariableDeclarations).typeNode;
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitVariableDeclarator(this);
}
indentedString(_: string): string {
let res = this.name;
if (this.initializer != null) {
......
......@@ -29,6 +29,10 @@ export class VariableInitializer extends Node {
return (this.parent as VariableDeclarator).typeNode;
}
accept<T>(visitor: Visitor<T>): T {
return visitor.visitVariableInitializer(this);
}
// Backwards compatibility
......
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class AdditiveExpression extends Expression {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitAdditiveExpression(this);
}
}
\ No newline at end of file
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class AndExpression extends Expression {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitAndExpression(this);
}
}
\ No newline at end of file
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class ArrayExpression extends Expression {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitArrayExpression(this);
}
}
\ No newline at end of file
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class AssignDestination extends Node {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitAssignDestination(this);
}
}
\ No newline at end of file
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class AssignExpression extends Expression {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitAssignExpression(this);
}
}
\ No newline at end of file
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class ClassCall extends Expression {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitClassCall(this);
}
}
\ No newline at end of file
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class ConditionalExpression extends Expression {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitConditionalExpression(this);
}
}
\ No newline at end of file
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class EqualityExpression extends Expression {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitEqualityExpression(this);
}
}
\ No newline at end of file
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class Expression extends Node {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitExpression(this);
}
}
\ No newline at end of file
......@@ -3,4 +3,8 @@ import { Visitor } from "./../Visitor";
export class IdentifierExpression extends Expression {
accept<T>(visitor: Visitor<T>): T {
return visitor.visitIdentifierExpression(this);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment