Smallville7123
04/08/2019, 11:19 AMfun a(b : Int) {
var c = b
c = 5
}
diesieben07
04/08/2019, 11:19 AMval
Smallville7123
04/08/2019, 11:20 AMneil.armstrong
04/08/2019, 11:20 AMfun a(b: Int) {
var b = b
b = 5
}
diesieben07
04/08/2019, 11:21 AMvar
semantics for a parameter that indicates a code-smell.Smallville7123
04/08/2019, 11:43 AMdiesieben07
04/08/2019, 11:43 AMSmallville7123
04/08/2019, 11:43 AMdiesieben07
04/08/2019, 11:44 AMSmallville7123
04/08/2019, 11:46 AMprocess(a.path, a.extension, globalVariables.kppMacroList)
...
fun process(
src: String,
extension: String,
macroTmp: ArrayList<Macro>
) {
val destinationPreProcessed = File("$src${globalVariables.preprocessedExtension}.$extension")
// macro needs to be a modifiable value thus cannot be declared as a paramater directly
var macro = macroTmp
var index = macro.size - 1
if (macro[index].fileName != null) {
index++
println("reallocating to $index")
macro = macro[0].realloc(macro, index + 1)
}
macro[index].fileName = src.substringAfterLast('/')
println("registered macro definition for ${macro[index].fileName} at index $index")
println("processing ${macro[index].fileName} -> ${destinationPreProcessed.name}")
destinationPreProcessed.createNewFile()
val lex = Lexer(fileToByteBuffer(File(src)), globalVariables.tokensNewLine)
lex.lex()
println("lex.currentLine is ${lex.currentLine}")
while (lex.currentLine != null) {
val out = parse(lex, macro)
var input = lex.currentLine as String
if (input[input.length - 1] == '\n') {
input = input.dropLast(1)
}
println("\ninput = $input")
println("output = $out\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
if (globalVariables.firstLine) {
destinationPreProcessed.writeText(out + "\n")
globalVariables.firstLine = false
} else destinationPreProcessed.appendText(out + "\n")
lex.lex()
}
}
ghedeon
04/08/2019, 11:47 AMmodifying a parameter passed value is undefined behaviourIt's so well defined, to the extent of being forbidden.
Smallville7123
04/08/2019, 11:48 AMfun realloc(m: ArrayList<Macro>, NewSize: Int): ArrayList<Macro> {
m.add(Macro())
m[0].size = NewSize
return m
}
macro = macro[0].realloc(macro, index + 1)
diesieben07
04/08/2019, 11:54 AMrealloc
always returns the same object. There is no need to return it or to re-assign to macro
.Smallville7123
04/08/2019, 11:54 AMJonathan Mew
04/08/2019, 3:07 PM// here you pass in macro as the first argument, and you assign the result back to macro
macro = macro[0].realloc(macro, index + 1)
...
// here m is the original macro list
fun realloc(m: ArrayList<Macro>, NewSize: Int): ArrayList<Macro> {
m.add(Macro())
m[0].size = NewSize
// and it is returned here without having been modified - it still refers to the original macros ArrayList
return m
}
// so it currently reassigns 'macro' to the value it already had
Hope that helpsSmallville7123
04/09/2019, 8:40 AM