diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeArray.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeArray.java deleted file mode 100644 index dee6d4978..000000000 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeArray.java +++ /dev/null @@ -1,61 +0,0 @@ -package dk.camelot64.kickc.model.types; - -import dk.camelot64.kickc.model.values.RValue; - -import java.util.Objects; - -/** - * A fixed size array of another type - */ -public class SymbolTypeArray extends SymbolTypePointer { - - /** The fixed size of the array. Can be null, if the size is not bound. - * If it si non-null it must be constant before the compilation is done. */ - private RValue size; - - public SymbolTypeArray(SymbolType elementType, RValue size) { - super(elementType); - this.size = size; - } - - public SymbolTypeArray(SymbolType elementType) { - super(elementType); - this.size = null; - } - - public RValue getSize() { - return size; - } - - public void setSize(RValue size) { - this.size = size; - } - - @Override - public String getTypeName() { - SymbolType elementType = getElementType(); - return elementType.getTypeName() + "[" + (size == null ? "" : size.toString()) + "]"; - } - - @Override - public boolean equals(Object o) { - if(this == o) return true; - if(o == null || getClass() != o.getClass()) return false; - if(!super.equals(o)) return false; - SymbolTypeArray that = (SymbolTypeArray) o; - return Objects.equals(size, that.size); - } - - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (size != null ? size.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return getTypeName(); - } - -} diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index a1307c3f0..39aedba59 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -508,6 +508,10 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor declVarDirectives = null; /** Holds the declared comments when descending into a Variable Declaration. */ @@ -537,6 +541,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor directives = declVarDirectives; SymbolType type = declVarType; List comments = declVarComments; // Find kind - Variable.Kind kind = directiveContext.getKind(type, getCurrentScope(), false, isArray, directives, new StatementSource(ctx)); + Variable.Kind kind = directiveContext.getKind(type, getCurrentScope(), false, declIsArray, directives, new StatementSource(ctx)); // Create variable Variable lValue = getCurrentScope().addVariable(kind, varName, type, defaultMemoryArea, currentDataSegment); - if(isArray) { + if(declIsArray) { lValue.setArray(true); - if(arraySize != null) { - if(!(arraySize instanceof ConstantValue)) - throw new CompileError("Error! Array size not constant " + arraySize.toString(program), new StatementSource(ctx)); - lValue.setArraySize((ConstantValue) arraySize); + if(declArraySize != null) { + if(!(declArraySize instanceof ConstantValue)) + throw new CompileError("Error! Array size not constant " + declArraySize.toString(program), new StatementSource(ctx)); + lValue.setArraySize((ConstantValue) declArraySize); } } // Add directives - directiveContext.applyDirectives(lValue, false, isArray, directives, new StatementSource(ctx)); + directiveContext.applyDirectives(lValue, false, declIsArray, directives, new StatementSource(ctx)); if(lValue.isDeclaredConst()) { // Add comments to constant lValue.setComments(ensureUnusedComments(comments)); @@ -697,14 +696,6 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor comments, StatementSource statementSource) { - PrePostModifierHandler.addPreModifiers(this, initializer, statementSource); - RValue rValue = (RValue) visit(initializer); - Statement stmt = new StatementAssignment((LValue) lValue.getRef(), rValue, statementSource, ensureUnusedComments(comments)); - sequence.addStatement(stmt); - PrePostModifierHandler.addPostModifiers(this, initializer, statementSource); - } - @Override public RValue visitInitList(KickCParser.InitListContext ctx) { List initValues = new ArrayList<>(); @@ -1672,9 +1655,13 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor