Make cpp.py less braindead.

The old code ignored operator precedence (!), despite having two tables
of operator precedence. The code's still pretty awful, but I've cleaned
it up enough to fix this, the most important bug.

This patch lets us correctly clean the uapi unistd.h, stat.h, and swab.h files,
and also fixes the mess we were already making of various old kernel
header files. I've added a bunch more tests, fixed the existing tests that
the existing script was already failing (!), and changed the script so that
the tests are run every time the script is run.

We can probably remove some of the old kernel header files that we were
parsing incorrectly, but we can worry about that later.

Bug: 11253477
Change-Id: Ie66c65b3a7ae13b4e98ed8038a6a534f06eae0e5
diff --git a/libc/kernel/common/asm-generic/swab.h b/libc/kernel/common/asm-generic/swab.h
index 8279332..bcbc94f 100644
--- a/libc/kernel/common/asm-generic/swab.h
+++ b/libc/kernel/common/asm-generic/swab.h
@@ -21,7 +21,7 @@
 #include <asm/bitsperlong.h>
 #if __BITS_PER_LONG == 32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#if defined(__GNUC__) && (!defined(__STRICT_ANSI__) || defined(__KERNEL__))
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
 #define __SWAB_64_THRU_32__
 #endif
 #endif
diff --git a/libc/kernel/common/linux/backing-dev.h b/libc/kernel/common/linux/backing-dev.h
index 2024bdc..d3335f9 100644
--- a/libc/kernel/common/linux/backing-dev.h
+++ b/libc/kernel/common/linux/backing-dev.h
@@ -49,7 +49,7 @@
 #define BDI_CAP_WRITE_MAP 0x00000020
 #define BDI_CAP_EXEC_MAP 0x00000040
 #define BDI_CAP_VMFLAGS   (BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP)
-#if defined(VM_MAYREAD) && BDI_CAP_READ_MAP != (VM_MAYREAD || BDI_CAP_WRITE_MAP != (VM_MAYWRITE || BDI_CAP_EXEC_MAP != VM_MAYEXEC))
+#if defined(VM_MAYREAD) && (BDI_CAP_READ_MAP != VM_MAYREAD || BDI_CAP_WRITE_MAP != VM_MAYWRITE || BDI_CAP_EXEC_MAP != VM_MAYEXEC)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #error please change backing_dev_info::capabilities flags
 #endif
diff --git a/libc/kernel/common/linux/jiffies.h b/libc/kernel/common/linux/jiffies.h
index c221bf4..b2452a2 100644
--- a/libc/kernel/common/linux/jiffies.h
+++ b/libc/kernel/common/linux/jiffies.h
@@ -26,7 +26,7 @@
 #include <linux/timex.h>
 #include <asm/param.h>
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#if HZ >= (12 && HZ < 24)
+#if HZ >= 12 && HZ < 24
 #define SHIFT_HZ 4
 #elif HZ >= 24 && HZ < 48
 #define SHIFT_HZ 5
@@ -91,22 +91,22 @@
 #define MAX_SEC_IN_JIFFIES   (SH_DIV((MAX_JIFFY_OFFSET >> SEC_JIFFIE_SC) * TICK_NSEC, NSEC_PER_SEC, 1) - 1)
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#if HZ <= (MSEC_PER_SEC && !(MSEC_PER_SEC % HZ))
+#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
 #else
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#if HZ <= (USEC_PER_SEC && !(USEC_PER_SEC % HZ))
+#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
 #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
 #else
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#if HZ <= (MSEC_PER_SEC && !(MSEC_PER_SEC % HZ))
+#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
 #else
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
-#if HZ <= (USEC_PER_SEC && !(USEC_PER_SEC % HZ))
+#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
 #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
 #else
 #endif
diff --git a/libc/kernel/common/linux/ktime.h b/libc/kernel/common/linux/ktime.h
index d3f167f..4afae7a 100644
--- a/libc/kernel/common/linux/ktime.h
+++ b/libc/kernel/common/linux/ktime.h
@@ -23,7 +23,7 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef union {
  s64 tv64;
-#if BITS_PER_LONG != (64 && !defined(CONFIG_KTIME_SCALAR))
+#if BITS_PER_LONG != 64
  struct {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __BIG_ENDIAN
diff --git a/libc/kernel/common/linux/soundcard.h b/libc/kernel/common/linux/soundcard.h
index 7159f62..8689924 100644
--- a/libc/kernel/common/linux/soundcard.h
+++ b/libc/kernel/common/linux/soundcard.h
@@ -784,7 +784,7 @@
 #define TMR_SPP 10
 #define TMR_TIMESIG 11
 #define LOCL_STARTAUDIO 1
-#if !defined(__KERNEL__) && !defined(KERNEL) && !defined(INKERNEL) && !defined(_KERNEL) || defined(USE_SEQ_MACROS)
+#if !defined(KERNEL) && !defined(INKERNEL) && !defined(_KERNEL) || defined(USE_SEQ_MACROS)
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SEQ_DECLAREBUF() SEQ_USE_EXTBUF()
 #define SEQ_PM_DEFINES int __foo_bar___