diff --git a/src/codeGenerator/astProcessor/binaryAsnProcessor.ts b/src/codeGenerator/astProcessor/binaryAsnProcessor.ts index 566a2d3..0d0d276 100644 --- a/src/codeGenerator/astProcessor/binaryAsnProcessor.ts +++ b/src/codeGenerator/astProcessor/binaryAsnProcessor.ts @@ -144,7 +144,9 @@ export default function binaryAsnProcessor ( function assignmentProc () : GENCODE_SOLVED_OBJECT { assignmentStartErrorTests() - AuxVars.isLeftSideOfAssignment = true + if (CurrentNode.Operation.type === 'Assignment') { + AuxVars.isLeftSideOfAssignment = true + } AuxVars.hasVoidArray = false const LGenObj = genCode(Program, AuxVars, { RemAST: CurrentNode.Left, diff --git a/src/codeGenerator/astProcessor/setupGenCode.ts b/src/codeGenerator/astProcessor/setupGenCode.ts index dcd02c0..5b8b45f 100644 --- a/src/codeGenerator/astProcessor/setupGenCode.ts +++ b/src/codeGenerator/astProcessor/setupGenCode.ts @@ -126,6 +126,9 @@ export default function setupGenCode ( if (MemFound === undefined) { throw new Error(`At line: ${line}. Using variable '${varName}' before declaration.`) } + if (!MemFound.isSet) { + detectAndSetNotInitialized(MemFound, line, varDeclaration !== '') + } if (varDeclaration !== '') { // we are in declarations sentence MemFound.isDeclared = true return deepCopy(MemFound) @@ -144,9 +147,24 @@ export default function setupGenCode ( if (FoundMemory === undefined) { throw new Error(`At line: ${line}. No variable found at address '${addr}'.`) } + if (!FoundMemory.isSet) { + detectAndSetNotInitialized(FoundMemory, line, false) + } return deepCopy(FoundMemory) } + function detectAndSetNotInitialized (Memory: MEMORY_SLOT, line: number, isInitialization: boolean) { + if (AuxVars.isLeftSideOfAssignment || Memory.hexContent) { + Memory.isSet = true + return + } + if (isInitialization) { + return + } + AuxVars.warnings.push(`Warning: at line ${line}. Variable '${Memory.name}' is used but not initialized.`) + Memory.isSet = true // No more warning for same variable + } + function auxvarsGetNewJumpID () : string { // This code shall be equal GlobalCodeVars.getNewJumpID() AuxVars.jumpId++ diff --git a/src/shaper/memoryProcessor.ts b/src/shaper/memoryProcessor.ts index 469fe09..cd4f6f4 100644 --- a/src/shaper/memoryProcessor.ts +++ b/src/shaper/memoryProcessor.ts @@ -106,6 +106,7 @@ export default function memoryProcessor ( } } header.isDeclared = AuxVars.isFunctionArgument + header.isSet = AuxVars.isFunctionArgument // If is not an array, just send the header if (dimensions.length === 0) { return [header] @@ -133,6 +134,7 @@ export default function memoryProcessor ( Mem2.asmName = `${header.asmName}_${i - 1}` Mem2.scope = AuxVars.currentScopeName Mem2.declaration = header.ArrayItem.declaration + Mem2.isSet = true // No way to track array items for using before initialized retArrMem.push(Mem2) } // create array type definition @@ -277,6 +279,7 @@ export default function memoryProcessor ( StructMemHeader.asmName = AuxVars.currentPrefix + phraseCode[startingTokenCounter].value StructMemHeader.scope = AuxVars.currentScopeName StructMemHeader.isDeclared = AuxVars.isFunctionArgument + StructMemHeader.isSet = AuxVars.isFunctionArgument return [StructMemHeader] } // It IS array of structs @@ -293,6 +296,7 @@ export default function memoryProcessor ( StructMemHeader.asmName = AuxVars.currentPrefix + phraseCode[startingTokenCounter].value StructMemHeader.scope = AuxVars.currentScopeName StructMemHeader.isDeclared = AuxVars.isFunctionArgument + StructMemHeader.isSet = AuxVars.isFunctionArgument StructMemHeader.type = 'array' StructMemHeader.typeDefinition = StructMemHeader.asmName StructMemHeader.ArrayItem = { diff --git a/src/shaper/templates.ts b/src/shaper/templates.ts index 7e95e0c..ff50385 100644 --- a/src/shaper/templates.ts +++ b/src/shaper/templates.ts @@ -23,6 +23,7 @@ export function getTypeDefinitionTemplate