Skip to content

Commit

Permalink
added TypePattern
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMOBrien committed Feb 26, 2024
1 parent 4232e26 commit d77698f
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 56 deletions.
121 changes: 65 additions & 56 deletions src/compiled-proto/boa/types/Ast.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions src/java/boa/datagen/util/JavaVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,12 @@ else if (node.expressions().size() > 0 && node.expressions().get(0) instanceof S

@Override
public boolean visit(final SwitchStatement node) {
//print all the kinds of statements in the switch block

for (final Object s : node.statements()) {
System.out.println(s.getClass().getName());
}

final boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder();
final List<boa.types.Ast.Statement> list = statements.peek();
b.setKind(boa.types.Ast.Statement.StatementKind.SWITCH);
Expand Down Expand Up @@ -2437,6 +2443,7 @@ public boolean visit(final ProvidesDirective node) {
// begin Java 14
@Override
public boolean visit(final SwitchExpression node) {
System.out.println("\n\n\nhere switchexp\n\n\n");
setAstLevel(JLS14);

final boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder();
Expand Down Expand Up @@ -2593,6 +2600,7 @@ public boolean visit(final NullPattern node) {

@Override
public boolean visit(final GuardedPattern node) {
System.out.println("\n\n\nhere\n\n\n\n");
setAstLevel(JLS21);

final boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder();
Expand All @@ -2615,6 +2623,44 @@ public boolean visit(final GuardedPattern node) {
return false;
}

@Override
public boolean visit(TypePattern node) {
// Create a builder for the representation of the TypePattern
boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder();

// Set the kind of the expression to TypePattern
b.setKind(boa.types.Ast.Expression.ExpressionKind.TYPE_PATTERN);

// Get the pattern variable of the TypePattern
SingleVariableDeclaration patternVariable = node.getPatternVariable();

// Process the pattern variable if it exists
if (patternVariable != null) {
// Visit the pattern variable
patternVariable.accept(this);
// Add the processed pattern variable to the expression
b.addExpressions(expressions.pop());
}

// Get the list of pattern variables of the TypePattern
List<SingleVariableDeclaration> patternVariables = node.patternVariables();

// Process each pattern variable in the list
for (SingleVariableDeclaration var : patternVariables) {
// Visit the pattern variable
var.accept(this);
// Add the processed pattern variable to the expression
b.addExpressions(expressions.pop());
}

// Add the built TypePattern representation to the stack of expressions
expressions.push(b.build());

// Return false to indicate that the visitation should not continue to child nodes
return false;
}


//////////////////////////////////////////////////////////////
// Utility methods

Expand Down
1 change: 1 addition & 0 deletions src/proto/ast.proto
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ message Expression {
PATTERN = 109;
NULL_PATTERN = 110;
GUARDED_PATTERN = 111;
TYPE_PATTERN = 112;
}
/** The kind of expression */
required ExpressionKind kind = 1;
Expand Down

0 comments on commit d77698f

Please sign in to comment.