Added support for illegally terminated elements when N > 1 such that FOR_EACH_3(expandable, ) is now legal (AU_FOR_EACH(expandable, ) should remain sanz)

This commit is contained in:
Reece Wilson 2021-10-14 02:59:22 +01:00
parent fc94167ae7
commit 069e5ef053
2 changed files with 719 additions and 689 deletions

File diff suppressed because it is too large Load Diff

View File

@ -54,34 +54,38 @@ textBuffer +=
#define AU_FE_ERROR(exp) ERROR. CHECK PARAMETER COUNT. DID YOU FORGET A COMMA?
`
forN(subn, function(subN) {
if (!subN) return
forN(subn, function(nElements) {
if (!nElements) return
var suffix = subN != 1 ? "_" + (subN): ""
var suffix = nElements != 1 ? "_" + (nElements): ""
var subNMulNCapped = Math.min(kMacroParamLimit - 3, n * subN)
var nElementsMulNCapped = Math.min(kMacroParamLimit - 3, n * nElements)
var ignoreList = {}
var ignoreListFirst = {}
forN(subNMulNCapped, function(i) {
forN(nElementsMulNCapped, function(i) {
if (i == 0) {
textBuffer += `#define AU_FE_0${suffix}(prefix) \n`
textBuffer += `#define AU_FE_0${suffix}(expandable) \n`
ignoreListFirst[`AU_FE_0_FIRST${suffix}`] = true
return
}
var X = formatNParamPattern(subN, "X")
var X = formatNParamPattern(nElements, "X")
var iM1 = i - 1
var iM1Translated = i - subN
var iM1Translated = i - nElements
if (subN == 1) {
textBuffer += `#define AU_FE_${i}${suffix}(prefix, ${X}, ...) prefix(${X}) AU_FE_EXPAND(AU_FE_${iM1}${suffix}(prefix, __VA_ARGS__))\n`
} else if (i % subN == 0) {
if (i == subN) {
textBuffer += `#define AU_FE_${i}${suffix}(prefix, ${X}) prefix(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix))\n`
if (i == nElements - 1) {
textBuffer += `#define AU_FE_${i}${suffix}(expandable)\n`
} else if ((i == 1) && (nElements != 1)) {
// Edge case: FOR_EACH_N(EXPANDABLE, ), where N has to be defined/has an element count of > 1, this is always illegal
// However, we just ignore empty element expansions
textBuffer += `#define AU_FE_${i}${suffix}(expandable, empty)\n`
} else if (i % nElements == 0) {
if (i == nElements) {
textBuffer += `#define AU_FE_${i}${suffix}(expandable, ${X}) expandable(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix))\n`
} else {
textBuffer += `#define AU_FE_${i}${suffix}(prefix, ${X}, ...) prefix(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix, __VA_ARGS__))\n`
textBuffer += `#define AU_FE_${i}${suffix}(expandable, ${X}, ...) expandable(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix, __VA_ARGS__))\n`
}
} else {
@ -89,24 +93,27 @@ forN(subn, function(subN) {
}
var I2 = i + 1
if (i < subN) {
if (i == 1) {
textBuffer += `#define AU_FE_${i}_FIRST${suffix}(first, second) \n`
} else if (i < nElements) {
ignoreListFirst[`AU_FE_${i}_FIRST${suffix}`] = true
} else if ((i % (subN) == 0)) {
if (i == subN) {
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, prefix, ${X}) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix))\n`
} else if ((i % (nElements) == 0)) {
if (i == nElements) {
ignoreListFirst[`AU_FE_${i}_FIRST${suffix}`] = true
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, second, ${X}) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(second))\n`
} else {
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, prefix, ${X}, ...) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix, __VA_ARGS__))\n`
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, second, ${X}, ...) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(second, __VA_ARGS__))\n`
}
} else {
} else {
ignoreListFirst[`AU_FE_${I2}_FIRST${suffix}`] = true
}
})
var getMacroParams = formatNParamPattern(subNMulNCapped, "_")
var getMacroParams = formatNParamPattern(nElementsMulNCapped, "_")
textBuffer += `#define AU_GET_MACRO${suffix}(${getMacroParams}, NAME,...) NAME\n`
var params = formatNParamPatternReverseSuffix(subNMulNCapped, "AU_FE_", suffix)
var params2 = formatNParamPatternReverseSuffix(subNMulNCapped, "AU_FE_", "_FIRST" + suffix)
var params = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", suffix)
var params2 = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", "_FIRST" + suffix)
params = params.split(", ").map((str) => { return ignoreList[str] ? "AU_FE_ERROR" : str}).join(", ")
params2 = params2.split(", ").map((str) => { return ignoreListFirst[str] ? "AU_FE_ERROR" : str}).join(", ")