Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def generate_sst_node(emitter: java_file.Emitter, c: model.ConcreteClass):
# fields
for f in c.fields:
comment = ' // nullable' if f.is_nullable else ''
emitter.println(f'public final {f.type.java} {f.name.java};{comment}')
final = '' if f.type.python == 'expr' and not f.is_sequence else 'final '
emitter.println(f'public {final}{f.type.java} {f.name.java};{comment}')
# constructor
ctor_args = ', '.join(f'{f.type.java} {f.name.java}' for f in c.fields)
with emitter.define(f'public {c.name.java}({ctor_args}{", " if ctor_args else ""}SourceRange sourceRange)'):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

public final class ArgTy extends SSTNode {
public final String arg;
public final ExprTy annotation; // nullable
public ExprTy annotation; // nullable
public final Object typeComment; // nullable

public ArgTy(String arg, ExprTy annotation, Object typeComment, SourceRange sourceRange) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;

public final class ComprehensionTy extends SSTNode {
public final ExprTy target;
public final ExprTy iter;
public ExprTy target;
public ExprTy iter;
public final ExprTy[] ifs; // nullable
public final boolean isAsync;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -142,56 +142,6 @@ public static ConstantValue ofDouble(double v) {
return new ConstantValue(v, Kind.DOUBLE);
}

public ConstantValue addComplex(ConstantValue right) {
assert right.kind == Kind.COMPLEX;
double ld = toDouble();
double[] rd = right.getComplex();
return ofComplex(ld + rd[0], rd[1]);
}

public ConstantValue subComplex(ConstantValue right) {
assert right.kind == Kind.COMPLEX;
double ld = toDouble();
double[] rd = right.getComplex();
return ofComplex(ld - rd[0], -rd[1]);
}

private double toDouble() {
assert kind == Kind.BIGINTEGER || kind == Kind.DOUBLE || kind == Kind.LONG : kind;
switch (kind) {
case BIGINTEGER:
return getBigInteger().doubleValue();
case DOUBLE:
return getDouble();
case LONG:
return getLong();
default:
throw new IllegalStateException("should not reach here");
}
}

public ConstantValue negate() {
assert kind == Kind.BIGINTEGER || kind == Kind.DOUBLE || kind == Kind.LONG || kind == Kind.COMPLEX : kind;
switch (kind) {
case BIGINTEGER:
return ofBigInteger(getBigInteger().negate());
case DOUBLE:
return ofDouble(-getDouble());
case LONG:
long v = getLong();
if (v != Long.MIN_VALUE) {
return ofLong(-v);
} else {
return ofBigInteger(BigInteger.valueOf(v).negate());
}
case COMPLEX:
double[] complex = getComplex();
return ofComplex(-complex[0], -complex[1]);
default:
throw new IllegalStateException("should not reach here");
}
}

public static ConstantValue ofLong(long v) {
if (v >= CACHED_MIN && v <= CACHED_MAX) {
return CACHED_LONGS[(int) (v - CACHED_MIN)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public abstract class ExceptHandlerTy extends SSTNode {
}

public static final class ExceptHandler extends ExceptHandlerTy {
public final ExprTy type; // nullable
public ExprTy type; // nullable
public final String name; // nullable
public final StmtTy[] body; // nullable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class NamedExpr extends ExprTy {
public final ExprTy target;
public final ExprTy value;
public ExprTy target;
public ExprTy value;

public NamedExpr(ExprTy target, ExprTy value, SourceRange sourceRange) {
super(sourceRange);
Expand All @@ -89,9 +89,9 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class BinOp extends ExprTy {
public final ExprTy left;
public ExprTy left;
public final OperatorTy op;
public final ExprTy right;
public ExprTy right;

public BinOp(ExprTy left, OperatorTy op, ExprTy right, SourceRange sourceRange) {
super(sourceRange);
Expand All @@ -111,7 +111,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {

public static final class UnaryOp extends ExprTy {
public final UnaryOpTy op;
public final ExprTy operand;
public ExprTy operand;

public UnaryOp(UnaryOpTy op, ExprTy operand, SourceRange sourceRange) {
super(sourceRange);
Expand All @@ -129,7 +129,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {

public static final class Lambda extends ExprTy {
public final ArgumentsTy args;
public final ExprTy body;
public ExprTy body;

public Lambda(ArgumentsTy args, ExprTy body, SourceRange sourceRange) {
super(sourceRange);
Expand All @@ -146,9 +146,9 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class IfExp extends ExprTy {
public final ExprTy test;
public final ExprTy body;
public final ExprTy orElse;
public ExprTy test;
public ExprTy body;
public ExprTy orElse;

public IfExp(ExprTy test, ExprTy body, ExprTy orElse, SourceRange sourceRange) {
super(sourceRange);
Expand Down Expand Up @@ -197,7 +197,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class ListComp extends ExprTy {
public final ExprTy element;
public ExprTy element;
public final ComprehensionTy[] generators; // nullable

public ListComp(ExprTy element, ComprehensionTy[] generators, SourceRange sourceRange) {
Expand All @@ -214,7 +214,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class SetComp extends ExprTy {
public final ExprTy element;
public ExprTy element;
public final ComprehensionTy[] generators; // nullable

public SetComp(ExprTy element, ComprehensionTy[] generators, SourceRange sourceRange) {
Expand All @@ -231,8 +231,8 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class DictComp extends ExprTy {
public final ExprTy key;
public final ExprTy value;
public ExprTy key;
public ExprTy value;
public final ComprehensionTy[] generators; // nullable

public DictComp(ExprTy key, ExprTy value, ComprehensionTy[] generators, SourceRange sourceRange) {
Expand All @@ -251,7 +251,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class GeneratorExp extends ExprTy {
public final ExprTy element;
public ExprTy element;
public final ComprehensionTy[] generators; // nullable

public GeneratorExp(ExprTy element, ComprehensionTy[] generators, SourceRange sourceRange) {
Expand All @@ -268,7 +268,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class Await extends ExprTy {
public final ExprTy value;
public ExprTy value;

public Await(ExprTy value, SourceRange sourceRange) {
super(sourceRange);
Expand All @@ -283,7 +283,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class Yield extends ExprTy {
public final ExprTy value; // nullable
public ExprTy value; // nullable

public Yield(ExprTy value, SourceRange sourceRange) {
super(sourceRange);
Expand All @@ -297,7 +297,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class YieldFrom extends ExprTy {
public final ExprTy value;
public ExprTy value;

public YieldFrom(ExprTy value, SourceRange sourceRange) {
super(sourceRange);
Expand All @@ -312,7 +312,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class Compare extends ExprTy {
public final ExprTy left;
public ExprTy left;
public final CmpOpTy[] ops; // nullable
public final ExprTy[] comparators; // nullable

Expand All @@ -331,7 +331,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class Call extends ExprTy {
public final ExprTy func;
public ExprTy func;
public final ExprTy[] args; // nullable
public final KeywordTy[] keywords; // nullable

Expand All @@ -350,9 +350,9 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class FormattedValue extends ExprTy {
public final ExprTy value;
public ExprTy value;
public final int conversion;
public final ExprTy formatSpec; // nullable
public ExprTy formatSpec; // nullable

public FormattedValue(ExprTy value, int conversion, ExprTy formatSpec, SourceRange sourceRange) {
super(sourceRange);
Expand Down Expand Up @@ -400,7 +400,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class Attribute extends ExprTy {
public final ExprTy value;
public ExprTy value;
public final String attr;
public final ExprContextTy context;

Expand All @@ -421,8 +421,8 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class Subscript extends ExprTy {
public final ExprTy value;
public final ExprTy slice;
public ExprTy value;
public ExprTy slice;
public final ExprContextTy context;

public Subscript(ExprTy value, ExprTy slice, ExprContextTy context, SourceRange sourceRange) {
Expand All @@ -442,7 +442,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class Starred extends ExprTy {
public final ExprTy value;
public ExprTy value;
public final ExprContextTy context;

public Starred(ExprTy value, ExprContextTy context, SourceRange sourceRange) {
Expand Down Expand Up @@ -512,9 +512,9 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class Slice extends ExprTy {
public final ExprTy lower; // nullable
public final ExprTy upper; // nullable
public final ExprTy step; // nullable
public ExprTy lower; // nullable
public ExprTy upper; // nullable
public ExprTy step; // nullable

public Slice(ExprTy lower, ExprTy upper, ExprTy step, SourceRange sourceRange) {
super(sourceRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

public final class KeywordTy extends SSTNode {
public final String arg; // nullable
public final ExprTy value;
public ExprTy value;

public KeywordTy(String arg, ExprTy value, SourceRange sourceRange) {
super(sourceRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

public final class MatchCaseTy extends SSTNode {
public final PatternTy pattern;
public final ExprTy guard; // nullable
public ExprTy guard; // nullable
public final StmtTy[] body; // nullable

public MatchCaseTy(PatternTy pattern, ExprTy guard, StmtTy[] body, SourceRange sourceRange) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class Expression extends ModTy {
public final ExprTy body;
public ExprTy body;

public Expression(ExprTy body, SourceRange sourceRange) {
super(sourceRange);
Expand All @@ -100,7 +100,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {

public static final class FunctionType extends ModTy {
public final ExprTy[] argTypes; // nullable
public final ExprTy returns;
public ExprTy returns;

public FunctionType(ExprTy[] argTypes, ExprTy returns, SourceRange sourceRange) {
super(sourceRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public abstract class PatternTy extends SSTNode {
}

public static final class MatchValue extends PatternTy {
public final ExprTy value;
public ExprTy value;

public MatchValue(ExprTy value, SourceRange sourceRange) {
super(sourceRange);
Expand Down Expand Up @@ -116,7 +116,7 @@ public <T> T accept(SSTreeVisitor<T> visitor) {
}

public static final class MatchClass extends PatternTy {
public final ExprTy cls;
public ExprTy cls;
public final PatternTy[] patterns; // nullable
public final String[] kwdAttrs; // nullable
public final PatternTy[] kwdPatterns; // nullable
Expand Down
Loading
Loading