use GetStructNames instead of collecting the names in GetStructs
This commit is contained in:
@@ -2,7 +2,6 @@ package de.hsrm.compiler.Klang;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import de.hsrm.compiler.Klang.helper.Helper;
|
import de.hsrm.compiler.Klang.helper.Helper;
|
||||||
import de.hsrm.compiler.Klang.nodes.Node;
|
import de.hsrm.compiler.Klang.nodes.Node;
|
||||||
@@ -16,9 +15,9 @@ public class GetStructs extends KlangBaseVisitor<Node> {
|
|||||||
private Set<String> structNames;
|
private Set<String> structNames;
|
||||||
private Map<String, StructDefinition> structs;
|
private Map<String, StructDefinition> structs;
|
||||||
|
|
||||||
public GetStructs(Map<String, StructDefinition> structs) {
|
public GetStructs(Set<String> structNames, Map<String, StructDefinition> structs) {
|
||||||
this.structs = structs;
|
this.structs = structs;
|
||||||
this.structNames = new HashSet<>();
|
this.structNames = structNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -37,13 +36,6 @@ public class GetStructs extends KlangBaseVisitor<Node> {
|
|||||||
int col = ctx.start.getCharPositionInLine();
|
int col = ctx.start.getCharPositionInLine();
|
||||||
StructField[] fields = new StructField[ctx.structField().size()];
|
StructField[] fields = new StructField[ctx.structField().size()];
|
||||||
|
|
||||||
if (this.structNames.contains(name)) {
|
|
||||||
String error = "Struct " + name + " defined multiple times.";
|
|
||||||
throw new Error(Helper.getErrorPrefix(line, col) + error);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.structNames.add(name);
|
|
||||||
|
|
||||||
for (int i = 0; i < ctx.structField().size(); i++) {
|
for (int i = 0; i < ctx.structField().size(); i++) {
|
||||||
StructField field = (StructField) this.visit(ctx.structField(i));
|
StructField field = (StructField) this.visit(ctx.structField(i));
|
||||||
fields[i] = field;
|
fields[i] = field;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.io.*;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import de.hsrm.compiler.Klang.nodes.Node;
|
import de.hsrm.compiler.Klang.nodes.Node;
|
||||||
import de.hsrm.compiler.Klang.nodes.StructDefinition;
|
import de.hsrm.compiler.Klang.nodes.StructDefinition;
|
||||||
@@ -91,9 +92,13 @@ public class Klang {
|
|||||||
var functionDefinitions = new HashMap<String, FunctionInformation>();
|
var functionDefinitions = new HashMap<String, FunctionInformation>();
|
||||||
new GetFunctions(functionDefinitions).visit(tree);
|
new GetFunctions(functionDefinitions).visit(tree);
|
||||||
|
|
||||||
|
// Extract names of all structs
|
||||||
|
var structNames = new HashSet<String>();
|
||||||
|
new GetStructNames(structNames).visit(tree);
|
||||||
|
|
||||||
// Extract information about all structs
|
// Extract information about all structs
|
||||||
var structs = new HashMap<String, StructDefinition>();
|
var structs = new HashMap<String, StructDefinition>();
|
||||||
new GetStructs(structs).visit(tree);
|
new GetStructs(structNames, structs).visit(tree);
|
||||||
|
|
||||||
// Create the DAST
|
// Create the DAST
|
||||||
ContextAnalysis ctxAnal = new ContextAnalysis(functionDefinitions, structs);
|
ContextAnalysis ctxAnal = new ContextAnalysis(functionDefinitions, structs);
|
||||||
|
|||||||
Reference in New Issue
Block a user