Skip to content

Commit c8c7a1f

Browse files
committed
remove the body field from StaticInitializer and relax the valuye type on MemberDefinition
1 parent e3ed6c2 commit c8c7a1f

File tree

6 files changed

+10
-34
lines changed

6 files changed

+10
-34
lines changed

javascript/extractor/src/com/semmle/js/ast/DefaultVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,6 @@ public R visit(GeneratedCodeExpr nd, C c) {
785785

786786
@Override
787787
public R visit(StaticInitializer nd, C c) {
788-
return visit((MemberDefinition<Expression>) nd, c);
788+
return visit((MemberDefinition<BlockStatement>) nd, c);
789789
}
790790
}

javascript/extractor/src/com/semmle/js/ast/MemberDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* <p>A member definition has a name and an optional initial value, whose type is given by the type
1010
* parameter {@code V}.
1111
*/
12-
public abstract class MemberDefinition<V extends Expression> extends Node {
12+
public abstract class MemberDefinition<V extends Node> extends Node {
1313
/** A bitmask of flags defined in {@linkplain DeclarationFlags}. */
1414
private final int flags;
1515

@@ -21,7 +21,7 @@ public abstract class MemberDefinition<V extends Expression> extends Node {
2121
*/
2222
private final Expression key;
2323

24-
/** The initial value of the member. */
24+
/** The initial value / initializer of the member. */
2525
private final V value;
2626

2727
/** The decorators applied to this member, if any. */

javascript/extractor/src/com/semmle/js/ast/NodeCopier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,6 @@ public INode visit(GeneratedCodeExpr nd, Void c) {
902902

903903
@Override
904904
public INode visit(StaticInitializer nd, Void c) {
905-
return new StaticInitializer(visit(nd.getLoc()), copy(nd.getBody()));
905+
return new StaticInitializer(visit(nd.getLoc()), copy(nd.getValue()));
906906
}
907907
}

javascript/extractor/src/com/semmle/js/ast/StaticInitializer.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
11
package com.semmle.js.ast;
22

33
/**
4-
* A static initializer block in a class.
5-
* E.g.
6-
* ```TypeScript
7-
* class Foo {
8-
* static bar : number;
9-
* static {
10-
* Foo.bar = 42;
11-
* }
12-
* }
4+
* A static initializer block in a class. E.g. ```TypeScript class Foo { static
5+
* bar : number; static { Foo.bar = 42; } }
136
*/
14-
public class StaticInitializer extends MemberDefinition<Expression> {
15-
private final BlockStatement body;
16-
7+
public class StaticInitializer extends MemberDefinition<BlockStatement> {
178
public StaticInitializer(SourceLocation loc, BlockStatement body) {
18-
super("StaticInitializer", loc, DeclarationFlags.static_, null, null);
19-
this.body = body;
20-
}
21-
22-
/**
23-
* Gets the body of this static initializer.
24-
* @return The body of this static initializer.
25-
*/
26-
public BlockStatement getBody() {
27-
return body;
9+
super("StaticInitializer", loc, DeclarationFlags.static_, null, body);
2810
}
2911

3012
@Override
3113
public boolean isConcrete() {
3214
return false;
3315
}
3416

35-
3617
@Override
3718
public <C, R> R accept(Visitor<C, R> v, C c) {
3819
return v.visit(this, c);

javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,11 +1646,6 @@ public Label visit(MemberDefinition<?> nd, Context c) {
16461646
}
16471647
}
16481648

1649-
if (nd instanceof StaticInitializer) {
1650-
StaticInitializer si = (StaticInitializer) nd;
1651-
visit(si.getBody(), methkey, 3, IdContext.VAR_BIND);
1652-
}
1653-
16541649
if (nd instanceof FieldDefinition) {
16551650
FieldDefinition field = (FieldDefinition) nd;
16561651
if (field.isParameterField() && constructorKey != null) {

javascript/extractor/src/com/semmle/js/extractor/CFGExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ public Void visit(ClassExpression nd, SuccessorInfo i) {
11651165

11661166
private Void visit(Node nd, AClass ac, SuccessorInfo i) {
11671167
for (MemberDefinition<?> md : ac.getBody().getBody()) {
1168-
if (md.isConstructor() && md.isConcrete()) constructor2Class.put(md.getValue(), ac);
1168+
if (md.isConstructor() && md.isConcrete()) constructor2Class.put((Expression)md.getValue(), ac);
11691169
}
11701170
visitSequence(ac.getId(), ac.getSuperClass(), ac.getBody(), nd);
11711171
writeSuccessors(nd, visitSequence(getStaticInitializers(ac.getBody()), getDecoratorsOfClass(ac), i.getAllSuccessors()));
@@ -1627,7 +1627,7 @@ private List<Node> getStaticInitializers(ClassBody nd) {
16271627
List<Node> nodes = new ArrayList<>();
16281628
for (MemberDefinition<?> node : nd.getBody()) {
16291629
if (node instanceof FieldDefinition && ((FieldDefinition)node).isStatic()) nodes.add(node);
1630-
if (node instanceof StaticInitializer) nodes.add(((StaticInitializer)node).getBody());
1630+
if (node instanceof StaticInitializer) nodes.add(node.getValue());
16311631
}
16321632
return nodes;
16331633
}

0 commit comments

Comments
 (0)