mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +00:00
allow multi var declarations for floats too
This commit is contained in:
parent
1bdc427d73
commit
ae3b2ddf5f
@ -112,6 +112,10 @@ class AstPreprocessor(val program: Program,
|
||||
if(decl.type != VarDeclType.VAR) {
|
||||
movements.add(IAstModification.InsertFirst(decl, parentscope))
|
||||
replacements.add(IAstModification.Remove(decl, scope))
|
||||
} else {
|
||||
if(decl.names.size>1) {
|
||||
// we need to handle multi-decl here too, the desugarer maybe has not processed it here yet...
|
||||
TODO("handle multi-decl movement")
|
||||
} else {
|
||||
val declToInsert: VarDecl
|
||||
if(decl.value!=null && decl.datatype in NumericDatatypes) {
|
||||
@ -128,6 +132,7 @@ class AstPreprocessor(val program: Program,
|
||||
movements.add(IAstModification.InsertFirst(declToInsert, parentscope))
|
||||
}
|
||||
}
|
||||
}
|
||||
return movements + replacements
|
||||
}
|
||||
return noModifications
|
||||
@ -150,14 +155,15 @@ class AstPreprocessor(val program: Program,
|
||||
if(decl.names.size>1) {
|
||||
// note: the desugaring of a multi-variable vardecl has to be done here
|
||||
// and not in CodeDesugarer, that one is too late (identifiers can't be found otherwise)
|
||||
if(decl.datatype !in IntegerDatatypes)
|
||||
errors.err("can only multi declare integer variables", decl.position)
|
||||
if(errors.noErrors()) {
|
||||
if(decl.datatype !in NumericDatatypes)
|
||||
errors.err("can only multi declare numeric variables", decl.position)
|
||||
return if(errors.noErrors()) {
|
||||
// desugar into individual vardecl per name.
|
||||
return decl.desugarMultiDecl().map {
|
||||
decl.desugarMultiDecl().map {
|
||||
IAstModification.InsertAfter(decl, it, parent as IStatementContainer)
|
||||
} + IAstModification.Remove(decl, parent as IStatementContainer)
|
||||
}
|
||||
} else
|
||||
noModifications
|
||||
}
|
||||
|
||||
val nextAssignment = decl.nextSibling() as? Assignment
|
||||
|
@ -300,7 +300,7 @@ class VarDecl(val type: VarDeclType,
|
||||
override fun copy(): VarDecl {
|
||||
if(names.size>1)
|
||||
throw FatalAstException("should not copy a vardecl that still has multiple names")
|
||||
val copy = VarDecl(type, origin, declaredDatatype, zeropage, arraysize?.copy(), name, emptyList(), value?.copy(),
|
||||
val copy = VarDecl(type, origin, declaredDatatype, zeropage, arraysize?.copy(), name, names, value?.copy(),
|
||||
isArray, sharedWithAsm, splitArray, position)
|
||||
copy.allowInitializeWithZero = this.allowInitializeWithZero
|
||||
return copy
|
||||
|
@ -2,6 +2,8 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- fix multi-decl in for loops, see AstPreprocessor TODO("handle multi-decl movement")
|
||||
|
||||
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
|
||||
|
||||
...
|
||||
|
Loading…
x
Reference in New Issue
Block a user