mirror of
https://github.com/github/codeql.git
synced 2025-12-21 19:26:31 +01:00
remove the body field from StaticInitializer and relax the valuye type on MemberDefinition
This commit is contained in:
@@ -785,6 +785,6 @@ public class DefaultVisitor<C, R> implements Visitor<C, R> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R visit(StaticInitializer nd, C c) {
|
public R visit(StaticInitializer nd, C c) {
|
||||||
return visit((MemberDefinition<Expression>) nd, c);
|
return visit((MemberDefinition<BlockStatement>) nd, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.List;
|
|||||||
* <p>A member definition has a name and an optional initial value, whose type is given by the type
|
* <p>A member definition has a name and an optional initial value, whose type is given by the type
|
||||||
* parameter {@code V}.
|
* parameter {@code V}.
|
||||||
*/
|
*/
|
||||||
public abstract class MemberDefinition<V extends Expression> extends Node {
|
public abstract class MemberDefinition<V extends Node> extends Node {
|
||||||
/** A bitmask of flags defined in {@linkplain DeclarationFlags}. */
|
/** A bitmask of flags defined in {@linkplain DeclarationFlags}. */
|
||||||
private final int flags;
|
private final int flags;
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public abstract class MemberDefinition<V extends Expression> extends Node {
|
|||||||
*/
|
*/
|
||||||
private final Expression key;
|
private final Expression key;
|
||||||
|
|
||||||
/** The initial value of the member. */
|
/** The initial value / initializer of the member. */
|
||||||
private final V value;
|
private final V value;
|
||||||
|
|
||||||
/** The decorators applied to this member, if any. */
|
/** The decorators applied to this member, if any. */
|
||||||
|
|||||||
@@ -902,6 +902,6 @@ public class NodeCopier implements Visitor<Void, INode> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public INode visit(StaticInitializer nd, Void c) {
|
public INode visit(StaticInitializer nd, Void c) {
|
||||||
return new StaticInitializer(visit(nd.getLoc()), copy(nd.getBody()));
|
return new StaticInitializer(visit(nd.getLoc()), copy(nd.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,12 @@
|
|||||||
package com.semmle.js.ast;
|
package com.semmle.js.ast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A static initializer block in a class.
|
* A static initializer block in a class. E.g. ```TypeScript class Foo { static
|
||||||
* E.g.
|
* bar : number; static { Foo.bar = 42; } }
|
||||||
* ```TypeScript
|
|
||||||
* class Foo {
|
|
||||||
* static bar : number;
|
|
||||||
* static {
|
|
||||||
* Foo.bar = 42;
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*/
|
*/
|
||||||
public class StaticInitializer extends MemberDefinition<Expression> {
|
public class StaticInitializer extends MemberDefinition<BlockStatement> {
|
||||||
private final BlockStatement body;
|
|
||||||
|
|
||||||
public StaticInitializer(SourceLocation loc, BlockStatement body) {
|
public StaticInitializer(SourceLocation loc, BlockStatement body) {
|
||||||
super("StaticInitializer", loc, DeclarationFlags.static_, null, null);
|
super("StaticInitializer", loc, DeclarationFlags.static_, null, body);
|
||||||
this.body = body;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the body of this static initializer.
|
|
||||||
* @return The body of this static initializer.
|
|
||||||
*/
|
|
||||||
public BlockStatement getBody() {
|
|
||||||
return body;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -32,7 +14,6 @@ public class StaticInitializer extends MemberDefinition<Expression> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <C, R> R accept(Visitor<C, R> v, C c) {
|
public <C, R> R accept(Visitor<C, R> v, C c) {
|
||||||
return v.visit(this, c);
|
return v.visit(this, c);
|
||||||
|
|||||||
@@ -1646,11 +1646,6 @@ public class ASTExtractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nd instanceof StaticInitializer) {
|
|
||||||
StaticInitializer si = (StaticInitializer) nd;
|
|
||||||
visit(si.getBody(), methkey, 3, IdContext.VAR_BIND);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nd instanceof FieldDefinition) {
|
if (nd instanceof FieldDefinition) {
|
||||||
FieldDefinition field = (FieldDefinition) nd;
|
FieldDefinition field = (FieldDefinition) nd;
|
||||||
if (field.isParameterField() && constructorKey != null) {
|
if (field.isParameterField() && constructorKey != null) {
|
||||||
|
|||||||
@@ -1165,7 +1165,7 @@ public class CFGExtractor {
|
|||||||
|
|
||||||
private Void visit(Node nd, AClass ac, SuccessorInfo i) {
|
private Void visit(Node nd, AClass ac, SuccessorInfo i) {
|
||||||
for (MemberDefinition<?> md : ac.getBody().getBody()) {
|
for (MemberDefinition<?> md : ac.getBody().getBody()) {
|
||||||
if (md.isConstructor() && md.isConcrete()) constructor2Class.put(md.getValue(), ac);
|
if (md.isConstructor() && md.isConcrete()) constructor2Class.put((Expression)md.getValue(), ac);
|
||||||
}
|
}
|
||||||
visitSequence(ac.getId(), ac.getSuperClass(), ac.getBody(), nd);
|
visitSequence(ac.getId(), ac.getSuperClass(), ac.getBody(), nd);
|
||||||
writeSuccessors(nd, visitSequence(getStaticInitializers(ac.getBody()), getDecoratorsOfClass(ac), i.getAllSuccessors()));
|
writeSuccessors(nd, visitSequence(getStaticInitializers(ac.getBody()), getDecoratorsOfClass(ac), i.getAllSuccessors()));
|
||||||
@@ -1627,7 +1627,7 @@ public class CFGExtractor {
|
|||||||
List<Node> nodes = new ArrayList<>();
|
List<Node> nodes = new ArrayList<>();
|
||||||
for (MemberDefinition<?> node : nd.getBody()) {
|
for (MemberDefinition<?> node : nd.getBody()) {
|
||||||
if (node instanceof FieldDefinition && ((FieldDefinition)node).isStatic()) nodes.add(node);
|
if (node instanceof FieldDefinition && ((FieldDefinition)node).isStatic()) nodes.add(node);
|
||||||
if (node instanceof StaticInitializer) nodes.add(((StaticInitializer)node).getBody());
|
if (node instanceof StaticInitializer) nodes.add(node.getValue());
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user