From 4cc72afe4baa6424f0ebf7e91cc2cdcd2ea2c4ae Mon Sep 17 00:00:00 2001 From: Aerilius Date: Fri, 22 Apr 2016 18:26:26 +0200 Subject: [PATCH] Allow defined variables as values This patch allows definitions based on previous definitions: ``` #define NARWHAL 0 #define UNICORN 1 #define RHINOCEROS 2 #define ANIMAL UNICORN ``` Previously, the fourth definition's value would be a string "UNICORN" and a condition like: ``` #if ANIMAL == UNICORN ``` would evaluate as "UNICORN" == 1 which is false. --- lib/preprocess.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/preprocess.py b/lib/preprocess.py index 5ab7ca1..990f7b8 100755 --- a/lib/preprocess.py +++ b/lib/preprocess.py @@ -469,6 +469,8 @@ def preprocess(infile, outfile=sys.stdout, defines={}, var, val = match.group("var", "val") if val is None: val = None + elif val in defines: + val = defines[val] else: try: val = eval(val, {}, {})