Use LinkedHashMaps and LinkedHashSets to preserve the order of parameters and struct fields.
This commit is contained in:
@@ -5,10 +5,7 @@ import de.hsrm.compiler.Klang.nodes.*;
|
||||
import de.hsrm.compiler.Klang.types.NamedType;
|
||||
import de.hsrm.compiler.Klang.types.Type;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class GetDefinitions extends KlangBaseVisitor<Node> {
|
||||
private final Map<String, FunctionDefinition> functionDefs;
|
||||
@@ -110,7 +107,7 @@ public class GetDefinitions extends KlangBaseVisitor<Node> {
|
||||
}
|
||||
|
||||
// IDENT() includes the enumName as the first entry, which we skip
|
||||
var enumFields = new HashSet<String>();
|
||||
var enumFields = new LinkedHashSet<String>();
|
||||
for (int i = 1; i < ctx.IDENT().size(); i++) {
|
||||
var currentEnumField = ctx.IDENT(i);
|
||||
var currentEnumFieldName = currentEnumField.getText();
|
||||
@@ -136,7 +133,7 @@ public class GetDefinitions extends KlangBaseVisitor<Node> {
|
||||
public Node visitStructDef(KlangParser.StructDefContext ctx) {
|
||||
var structName = ctx.structName.getText();
|
||||
var structFieldCount = ctx.structField().size();
|
||||
var structFields = new HashMap<String, StructField>();
|
||||
var structFields = new LinkedHashMap<String, StructField>();
|
||||
var line = ctx.start.getLine();
|
||||
var col = ctx.start.getCharPositionInLine();
|
||||
|
||||
@@ -178,7 +175,7 @@ public class GetDefinitions extends KlangBaseVisitor<Node> {
|
||||
public Node visitFunctionDef(KlangParser.FunctionDefContext ctx) {
|
||||
var funcName = ctx.funcName.getText();
|
||||
var paramCount = ctx.params.parameter().size();
|
||||
var parameters = new HashMap<String, Parameter>();
|
||||
var parameters = new LinkedHashMap<String, Parameter>();
|
||||
var line = ctx.start.getLine();
|
||||
var col = ctx.start.getCharPositionInLine();
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.hsrm.compiler.Klang.ContextAnalysis;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user