Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
99b365e260 | |||
68e2be1a26 | |||
68a3479d13 | |||
0de3aba2ec | |||
3e3cbc5e93 |
File diff suppressed because it is too large
Load Diff
85
forEach.js
85
forEach.js
@ -33,12 +33,12 @@ var textBuffer = ""
|
|||||||
|
|
||||||
textBuffer +=
|
textBuffer +=
|
||||||
`/**
|
`/**
|
||||||
* X-Macro alternative. Defines AU_FOR_EACH_N(expandable, ...args*N)
|
* X-Macro alternative. Defines AU_FOR_EACH[_THAT/_FIRST][_N](expandable, ...args*N)
|
||||||
* Autogenerated by forEach.js; do not modify"
|
* Autogenerated by forEach.js; do not modify"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define AU_FE_EXPAND(exp) exp
|
#define _ZAUFE_FE_EXPAND(exp) exp
|
||||||
#define AU_FE_ERROR(exp) ERROR. CHECK PARAMETER COUNT. DID YOU FORGET A COMMA?
|
#define _ZAUFE_FE_ERROR(exp) ERROR. CHECK PARAMETER COUNT. DID YOU FORGET A COMMA?
|
||||||
`
|
`
|
||||||
|
|
||||||
forN(kMaxPairedElements, function(nElements) {
|
forN(kMaxPairedElements, function(nElements) {
|
||||||
@ -52,9 +52,9 @@ forN(kMaxPairedElements, function(nElements) {
|
|||||||
|
|
||||||
forN(nElementsMulNCapped, function(i) {
|
forN(nElementsMulNCapped, function(i) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
textBuffer += `#define AU_FE_0${suffix}(expandable) \n`
|
textBuffer += `#define _ZAUFE_FE_0${suffix}(expandable) \n`
|
||||||
ignoreList[`AU_FE_0_FIRST${suffix}`] = true
|
ignoreList[`_ZAUFE_FE_0_FIRST${suffix}`] = true
|
||||||
ignoreList[`AU_FE_0_THAT${suffix}`] = true
|
ignoreList[`_ZAUFE_FE_0_THAT${suffix}`] = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,81 +65,84 @@ forN(kMaxPairedElements, function(nElements) {
|
|||||||
if (i == nElements - 1) {
|
if (i == nElements - 1) {
|
||||||
// Edge case: the trailing macro does not do anything
|
// Edge case: the trailing macro does not do anything
|
||||||
// We could hack in an _LAST callback here, should a need for it arise
|
// We could hack in an _LAST callback here, should a need for it arise
|
||||||
textBuffer += `#define AU_FE_${i}${suffix}(expandable)\n`
|
textBuffer += `#define _ZAUFE_FE_${i}${suffix}(expandable)\n`
|
||||||
} else if ((i == 1) && (nElements != 1)) {
|
} 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
|
// Edge case: FOR_EACH_N(EXPANDABLE, ), where N has to be defined/has an element count of > 1, this is technically illegal
|
||||||
// However, we just ignore empty element expansions
|
// However, we can just ignore empty element expansions in those instances
|
||||||
textBuffer += `#define AU_FE_${i}${suffix}(expandable, empty)\n`
|
// We can simply use the first 'macro has 2 arguments' slot to hook these (EXPANDABLE, ) conditions
|
||||||
|
// AU_FOR_EACH CANNOT INTRINSICALLY TELL THE DIFFERENCE BETWEEN AN EMTPY VALUE AND ARG 0
|
||||||
|
textBuffer += `#define _ZAUFE_FE_${i}${suffix}(expandable, empty)\n`
|
||||||
} else if (i % nElements == 0) {
|
} else if (i % nElements == 0) {
|
||||||
if (i == nElements) {
|
if (i == nElements) {
|
||||||
// Edge case: the last element does not accept any parameters
|
// Edge case: the last element does not accept any parameters
|
||||||
textBuffer += `#define AU_FE_${i}${suffix}(expandable, ${X}) expandable(${X})\n`
|
textBuffer += `#define _ZAUFE_FE_${i}${suffix}(expandable, ${X}) expandable(${X})\n`
|
||||||
} else {
|
} else {
|
||||||
textBuffer += `#define AU_FE_${i}${suffix}(expandable, ${X}, ...) expandable(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(expandable, __VA_ARGS__))\n`
|
textBuffer += `#define _ZAUFE_FE_${i}${suffix}(expandable, ${X}, ...) expandable(${X}) _ZAUFE_FE_EXPAND(_ZAUFE_FE_${iM1Translated}${suffix}(expandable, __VA_ARGS__))\n`
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ignoreList[`AU_FE_${i}${suffix}`] = true
|
ignoreList[`_ZAUFE_FE_${i}${suffix}`] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var I2 = i + 1
|
var I2 = i + 1
|
||||||
|
|
||||||
// Similar to above
|
// Similar to above
|
||||||
if (i < nElements) {
|
if (i < nElements) {
|
||||||
ignoreList[`AU_FE_${i}_THAT${suffix}`] = true
|
ignoreList[`_ZAUFE_FE_${i}_THAT${suffix}`] = true
|
||||||
ignoreList[`AU_FE_${I2}_THAT${suffix}`] = true
|
ignoreList[`_ZAUFE_FE_${I2}_THAT${suffix}`] = true
|
||||||
} else if (i == nElements) {
|
} else if (i == nElements) {
|
||||||
ignoreList[`AU_FE_${i}_THAT${suffix}`] = true
|
ignoreList[`_ZAUFE_FE_${i}_THAT${suffix}`] = true
|
||||||
textBuffer += `#define AU_FE_${I2}_THAT${suffix}(expandable, ctx, ${X}) expandable(ctx, ${X})\n`
|
textBuffer += `#define _ZAUFE_FE_${I2}_THAT${suffix}(expandable, ctx, ${X}) expandable(ctx, ${X})\n`
|
||||||
} else if ((i % nElements) == 0) {
|
} else if ((i % nElements) == 0) {
|
||||||
var offByOne = iM1Translated + 1
|
var offByOne = iM1Translated + 1
|
||||||
if (i == nElements) {
|
if (i == nElements) {
|
||||||
// Edge case: the last element does not accept any parameters
|
// Edge case: the last element does not accept any parameters
|
||||||
ignoreList[`AU_FE_${I2}_THAT${suffix}`] = true // ? dont question it
|
ignoreList[`_ZAUFE_FE_${I2}_THAT${suffix}`] = true // ? dont question it
|
||||||
textBuffer += `#define AU_FE_${I2}_THAT${suffix}(expandable, ctx, ${X}) expandable(ctx, ${X})\n`
|
textBuffer += `#define _ZAUFE_FE_${I2}_THAT${suffix}(expandable, ctx, ${X}) expandable(ctx, ${X})\n`
|
||||||
} else {
|
} else {
|
||||||
textBuffer += `#define AU_FE_${I2}_THAT${suffix}(expandable, ctx, ${X}, ...) expandable(ctx, ${X}) AU_FE_EXPAND(AU_FE_${offByOne}_THAT${suffix}(expandable, ctx, __VA_ARGS__))\n`
|
textBuffer += `#define _ZAUFE_FE_${I2}_THAT${suffix}(expandable, ctx, ${X}, ...) expandable(ctx, ${X}) _ZAUFE_FE_EXPAND(_ZAUFE_FE_${offByOne}_THAT${suffix}(expandable, ctx, __VA_ARGS__))\n`
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ignoreList[`AU_FE_${I2}_THAT${suffix}`] = true
|
ignoreList[`_ZAUFE_FE_${I2}_THAT${suffix}`] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
ignoreList[`AU_FE_${suffix}_THAT${suffix}`] = true
|
ignoreList[`_ZAUFE_FE_${suffix}_THAT${suffix}`] = true
|
||||||
|
|
||||||
if (i == 1) {
|
if (I2 == nElements) {
|
||||||
textBuffer += `#define AU_FE_${i}_FIRST${suffix}(first, second) \n`
|
textBuffer += `#define _ZAUFE_FE_${I2}_FIRST${suffix}(first, second, ...) \n`
|
||||||
|
textBuffer += `#define _ZAUFE_FE_${i}_FIRST${suffix}(first, second) \n`
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (i == nElements) {
|
if (i == nElements) {
|
||||||
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, second, ${X}) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(second))\n`
|
textBuffer += `#define _ZAUFE_FE_${I2}_FIRST${suffix}(first, second, ${X}) first(${X}) _ZAUFE_FE_EXPAND(_ZAUFE_FE_${iM1Translated}${suffix}(second))\n`
|
||||||
} else if ((i % (nElements) == 0)) {
|
} else if ((i % (nElements) == 0)) {
|
||||||
if (i == nElements) {
|
if (i == nElements) {
|
||||||
ignoreList[`AU_FE_${I2}_FIRST${suffix}`] = true // ? dont question it
|
ignoreList[`_ZAUFE_FE_${I2}_FIRST${suffix}`] = true // ? dont question it
|
||||||
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, second, ${X}) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(second))\n`
|
textBuffer += `#define _ZAUFE_FE_${I2}_FIRST${suffix}(first, second, ${X}) first(${X}) _ZAUFE_FE_EXPAND(_ZAUFE_FE_${iM1Translated}${suffix}(second))\n`
|
||||||
} else {
|
} else {
|
||||||
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, second, ${X}, ...) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(second, __VA_ARGS__))\n`
|
textBuffer += `#define _ZAUFE_FE_${I2}_FIRST${suffix}(first, second, ${X}, ...) first(${X}) _ZAUFE_FE_EXPAND(_ZAUFE_FE_${iM1Translated}${suffix}(second, __VA_ARGS__))\n`
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ignoreList[`AU_FE_${I2}_FIRST${suffix}`] = true
|
ignoreList[`_ZAUFE_FE_${I2}_FIRST${suffix}`] = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Defines a macro that effectively choses a macro given an array of macros based on the number of input arguments
|
// Defines a macro that effectively choses a macro given an array of macros based on the number of input arguments
|
||||||
var getMacroParams = formatNParamPattern(nElementsMulNCapped, "_")
|
var getMacroParams = formatNParamPattern(nElementsMulNCapped, "_")
|
||||||
textBuffer += `#define AU_GET_MACRO${suffix}(${getMacroParams}, NAME,...) NAME\n`
|
textBuffer += `#define _ZAUFE_GET_MACRO${suffix}(${getMacroParams}, NAME,...) NAME\n`
|
||||||
|
|
||||||
// Stringify the parameter portion of the prototype
|
// Stringify the parameter portion of the prototype
|
||||||
var params = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", suffix)
|
var params = formatNParamPatternReverseSuffix(nElementsMulNCapped, "_ZAUFE_FE_", suffix)
|
||||||
var params2 = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", "_FIRST" + suffix)
|
var params2 = formatNParamPatternReverseSuffix(nElementsMulNCapped, "_ZAUFE_FE_", "_FIRST" + suffix)
|
||||||
var params3 = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", "_THAT" + suffix)
|
var params3 = formatNParamPatternReverseSuffix(nElementsMulNCapped, "_ZAUFE_FE_", "_THAT" + suffix)
|
||||||
|
|
||||||
// Replace missing macro paramaters with the AU_FE_ERROR macro
|
// Replace missing macro paramaters with the _ZAUFE_FE_ERROR macro
|
||||||
params = params .split(", ").map((str) => { return ignoreList[str] ? "AU_FE_ERROR" : str}).join(", ")
|
params = params .split(", ").map((str) => { return ignoreList[str] ? "_ZAUFE_FE_ERROR" : str}).join(", ")
|
||||||
params2 = params2.split(", ").map((str) => { return ignoreList[str] ? "AU_FE_ERROR" : str}).join(", ")
|
params2 = params2.split(", ").map((str) => { return ignoreList[str] ? "_ZAUFE_FE_ERROR" : str}).join(", ")
|
||||||
params3 = params3.split(", ").map((str) => { return ignoreList[str] ? "AU_FE_ERROR" : str}).join(", ")
|
params3 = params3.split(", ").map((str) => { return ignoreList[str] ? "_ZAUFE_FE_ERROR" : str}).join(", ")
|
||||||
|
|
||||||
textBuffer += `#define AU_FOR_EACH${suffix}(action, ...) AU_FE_EXPAND(AU_GET_MACRO${suffix}(_whydoweneedthis, __VA_ARGS__, ${params})(action,__VA_ARGS__))\n`
|
textBuffer += `#define AU_FOR_EACH${suffix}(action, ...) _ZAUFE_FE_EXPAND(_ZAUFE_GET_MACRO${suffix}(_whydoweneedthis, __VA_ARGS__, ${params})(action,__VA_ARGS__))\n`
|
||||||
textBuffer += `#define AU_FOR_EACH_FIRST${suffix}(action, ...) AU_FE_EXPAND(AU_GET_MACRO${suffix}(_whydoweneedthis, __VA_ARGS__, ${params2})(action,__VA_ARGS__))\n`
|
textBuffer += `#define AU_FOR_EACH_FIRST${suffix}(action, ...) _ZAUFE_FE_EXPAND(_ZAUFE_GET_MACRO${suffix}(_whydoweneedthis, __VA_ARGS__, ${params2})(action,__VA_ARGS__))\n`
|
||||||
textBuffer += `#define AU_FOR_EACH_THAT${suffix}(action, ...) AU_FE_EXPAND(AU_GET_MACRO${suffix}(_whydoweneedthis, __VA_ARGS__, ${params3})(action,__VA_ARGS__))\n`
|
textBuffer += `#define AU_FOR_EACH_THAT${suffix}(action, ...) _ZAUFE_FE_EXPAND(_ZAUFE_GET_MACRO${suffix}(_whydoweneedthis, __VA_ARGS__, ${params3})(action,__VA_ARGS__))\n`
|
||||||
|
|
||||||
textBuffer += "\n\n"
|
textBuffer += "\n\n"
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user