Cesium icon indicating copy to clipboard operation
Cesium copied to clipboard

Preprocessor: undefined variables aren't implicitly converted to zero

Open ForNeVeR opened this issue 1 year ago • 0 comments

Consider this valid C program:

#if FOO
int a = 1;
#endif

It is expected to generate an empty C file (an undefined variable evaluates to zero).

Currently, it will fail with a stack trace:

Unhandled exception. Cesium.Core.PreprocessorException: Invalid integer constant expression
   at Cesium.Preprocessor.MacroExtensions.AsBoolean(String macroValue) in G:\Projects\Cesium\Cesium.Preprocessor\MacroExtensions.cs:line 14
   at Cesium.Preprocessor.CPreprocessor.EvaluateExpression(IEnumerable`1 expressionTokens) in G:\Projects\Cesium\Cesium.Preprocessor\CPreprocessor.cs:line 753
   at Cesium.Preprocessor.CPreprocessor.ProcessDirective(IEnumerable`1 directiveTokens) in G:\Projects\Cesium\Cesium.Preprocessor\CPreprocessor.cs:line 616
   at Cesium.Preprocessor.CPreprocessor.GetPreprocessingResults()+MoveNext() in G:\Projects\Cesium\Cesium.Preprocessor\CPreprocessor.cs:line 77
   at Cesium.Preprocessor.CPreprocessor.GetPreprocessingResults()+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Cesium.Preprocessor.CPreprocessor.ProcessSource() in G:\Projects\Cesium\Cesium.Preprocessor\CPreprocessor.cs:line 37
   at Cesium.Preprocessor.CPreprocessor.ProcessSource() in G:\Projects\Cesium\Cesium.Preprocessor\CPreprocessor.cs:line 37
   at Cesium.Compiler.Compilation.Preprocess(String inputFilePath, CompilationOptions compilationOptions) in G:\Projects\Cesium\Cesium.Compiler\Compilation.cs:line 91     
   at Cesium.Compiler.Compilation.GenerateCode(AssemblyContext context, String inputFilePath) in G:\Projects\Cesium\Cesium.Compiler\Compilation.cs:line 97
   at Cesium.Compiler.Compilation.Compile(IEnumerable`1 inputFilePaths, String outputFilePath, CompilationOptions compilationOptions) in G:\Projects\Cesium\Cesium.Compiler\Compilation.cs:line 40
   at Program.<>c.<<<Main>$>b__0_0>d.MoveNext() in G:\Projects\Cesium\Cesium.Compiler\Main.cs:line 39
--- End of stack trace from previous location ---
   at Cesium.Compiler.CommandLineParser.<>c__DisplayClass0_0.<<ParseCommandLineArgs>b__1>d.MoveNext() in G:\Projects\Cesium\Cesium.Compiler\CommandLineParser.cs:line 37   
--- End of stack trace from previous location ---
   at Cesium.Compiler.CommandLineParser.ParseCommandLineArgs(String[] args, ICompilerReporter reporter, Func`2 worker) in G:\Projects\Cesium\Cesium.Compiler\CommandLineParser.cs:line 18
   at Program.<Main>$(String[] args) in G:\Projects\Cesium\Cesium.Compiler\Main.cs:line 6
   at Program.<Main>(String[] args)

ForNeVeR avatar Jan 27 '24 20:01 ForNeVeR