Added support for partial evaluation of && and || expressions.

git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@957 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2009-07-15 15:55:20 +00:00
parent dd235af55c
commit 29da0878e3

View File

@@ -42,8 +42,10 @@ function version_code(kver) {
# it is the same order as the order of operators in C.
function evaluate(stmnt) {
# Remove C-style comments.
gsub(" *\\/\\*[^*]*\\*\\/ *", "", stmnt)
# Remove the spaces before the #-sign.
gsub("^+ *# *", "+#", stmnt)
if (match(stmnt, "^+#ifdef (.*)$", arg))
@@ -99,7 +101,7 @@ function evaluate(stmnt) {
sub(pattern, op[1] == 0, stmnt)
}
pattern="KERNEL_VERSION\\(([0-9]+) *, *([0-9]+) *, *([0-9]+) *\\)"
pattern="KERNEL_VERSION\\( *([0-9]+) *, *([0-9]+) *, *([0-9]+) *\\)"
while (match(stmnt, pattern, op) != 0)
{
sub(pattern, op[1] * 65536 + op[2] * 256 + op[3], stmnt)
@@ -123,12 +125,24 @@ function evaluate(stmnt) {
sub(pattern, (op[1] != 0) && (op[2] != 0), stmnt)
}
pattern="([0-9]+) *\\&\\& *(!* *defined\\([^)]*\\))"
while (match(stmnt, pattern, op) != 0)
{
sub(pattern, (op[1] != 0) ? op[2] : "0", stmnt)
}
pattern="([0-9]+) *\\|\\| *([0-9]+)"
while (match(stmnt, pattern, op) != 0)
{
sub(pattern, (op[1] != 0) || (op[2] != 0), stmnt)
}
pattern="([0-9]+) *\\|\\| *(!* *defined\\([^)]*\\))"
while (match(stmnt, pattern, op) != 0)
{
sub(pattern, (op[1] != 0) ? "1" : op[2], stmnt)
}
pattern="\\(([0-9]+)\\)"
while (match(stmnt, pattern, op) != 0)
{