Skip to content

Commit

Permalink
misc: Mark ASTProcessor declaration parse methods as nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jan 16, 2025
1 parent 1f1424f commit 9aaf953
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import me.darknet.assembler.util.Location;
import me.darknet.assembler.visitor.Modifiers;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
Expand Down Expand Up @@ -113,6 +114,7 @@ public ASTProcessor(BytecodeFormat format) {
this.format = format;
}

@Nullable
private static ASTElement parseDeclaration(ParserContext ctx, ASTDeclaration declaration) {
String keyword = declaration.keyword().content().substring(1);
return ParserRegistry.get(keyword).parse(ctx, declaration);
Expand Down Expand Up @@ -307,6 +309,10 @@ static ASTElement validateElementValue(ParserContext ctx, ASTElement value) {
ASTDeclaration decl = (ASTDeclaration) value;
if (decl.keyword() != null) {
value = parseDeclaration(ctx, decl);
if (value == null) {
ctx.throwError("declaration parse failure", decl.location());
return null;
}
switch (value.type()) {
case ENUM -> {
}
Expand Down Expand Up @@ -397,7 +403,9 @@ public Result<List<ASTElement>> processAST(List<ASTElement> ast) {
ParserContext ctx = new ParserContext(format);
for (ASTElement astElement : ast) {
if (astElement instanceof ASTDeclaration) {
ctx.add(parseDeclaration(ctx, (ASTDeclaration) astElement));
ASTElement parsed = parseDeclaration(ctx, (ASTDeclaration) astElement);
if (parsed != null)
ctx.add(parsed);
} else {
ctx.throwUnexpectedElementError("declaration", astElement);
}
Expand All @@ -407,6 +415,7 @@ public Result<List<ASTElement>> processAST(List<ASTElement> ast) {

@FunctionalInterface
private interface DeclarationParser<T extends ASTElement> {
@Nullable
T parse(ParserContext ctx, ASTDeclaration declaration);
}

Expand All @@ -426,7 +435,7 @@ public ParserContext(BytecodeFormat format) {
this.instructions = format.getInstructions();
}

public void add(ASTElement element) {
public void add(@NotNull ASTElement element) {
result.add(element);
}

Expand Down Expand Up @@ -654,7 +663,8 @@ List<ASTElement> parseDeclarations(List<@Nullable ASTElement> elements, String e
continue;
}
ASTElement resultDeclaration = parseDeclaration(this, declaration);
result.add(resultDeclaration);
if (resultDeclaration != null)
result.add(resultDeclaration);
}
this.result = old;
return result.getResult();
Expand Down

0 comments on commit 9aaf953

Please sign in to comment.