ZoneCodeGenerator: Add precompiler support for ifdef so a namespace can be defined in the t6_assets header for compiling in ZoneCommon without display errors

This commit is contained in:
Jan 2019-12-21 16:37:57 +01:00
parent c8a2bec12b
commit 57ef79692a
4 changed files with 6287 additions and 5803 deletions

View File

@ -20,6 +20,11 @@ namespace std
typedef long long int64_t;
}
#define __int8 char
#define __int16 short
#define __int32 int
#define __int64 long long
// DirectX types do not need to be processed.
// DirectX 9 Types
typedef void IDirect3DVertexDeclaration9;
@ -39,3 +44,5 @@ typedef void ID3D11Buffer;
#define __unaligned
#define volatile
#define __cppobj
// EOF

View File

@ -9,15 +9,20 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl
{
private static readonly Regex packPushRegex = new Regex(@"^\s*#pragma\s+pack\s*\(\s*push\s*,\s*(\d+)\s*\)\s*$");
private static readonly Regex packPopRegex = new Regex(@"^\s*#pragma\s+pack\s*\(\s*pop\s*\)\s*$");
private static readonly Regex defineRegex = new Regex(@"^\s*#define\s*(\w+)(?:\s*(.*))?$");
private static readonly Regex undefRegex = new Regex(@"^\s*#undef\s*(\w+)\s*$");
private static readonly Regex includeRegex = new Regex(@"^\s*#include\s*(?:\""(.*)\""|\<(.*)\>)\s*$");
private static readonly Regex defineRegex = new Regex(@"^\s*#define\s+(\w+)(?:\s+(.*))?$");
private static readonly Regex undefRegex = new Regex(@"^\s*#undef\s+(\w+)\s*$");
private static readonly Regex includeRegex = new Regex(@"^\s*#include\s+(?:\""(.*)\""|\<(.*)\>)\s*$");
private static readonly Regex ifdefRegex = new Regex(@"^\s*#ifdef\s+(\w+)\s*$");
private static readonly Regex ifndefRegex = new Regex(@"^\s*#ifndef\s+(\w+)\s*$");
private static readonly Regex elseRegex = new Regex(@"^\s*#else\s*$");
private static readonly Regex endifRegex = new Regex(@"^\s*#endif\s*$");
private readonly IIncludingParsingStream streamFileSystem;
private readonly IHeaderParserState state;
private readonly ICommentProcessor commentProcessor;
private readonly Dictionary<string, string> defines;
private readonly Stack<bool> conditions;
public bool EndOfStream => streamFileSystem.EndOfStream;
public string Filename => streamFileSystem.Filename;
@ -27,8 +32,14 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl
{
streamFileSystem = includingParsingStream;
this.state = state;
defines = new Dictionary<string, string>();
commentProcessor = new CommentProcessor();
defines = new Dictionary<string, string>
{
{"__zonecodegenerator", "1"}
};
conditions = new Stack<bool>();
}
private void ParseCompilerExpression(string line)
@ -78,6 +89,44 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl
streamFileSystem.IncludeFile(filename);
return;
}
var ifdef = ifdefRegex.Match(line);
if (ifdef.Success)
{
var key = ifdef.Groups[1].Value;
conditions.Push(defines.ContainsKey(key));
return;
}
var ifndef = ifndefRegex.Match(line);
if (ifndef.Success)
{
var key = ifndef.Groups[1].Value;
conditions.Push(!defines.ContainsKey(key));
return;
}
var _else = elseRegex.Match(line);
if (_else.Success)
{
if (conditions.Count > 0)
{
conditions.Push(!conditions.Pop());
}
return;
}
var endif = endifRegex.Match(line);
if (endif.Success)
{
if (conditions.Count > 0)
{
conditions.Pop();
}
return;
}
}
private string Preprocess(string line)
@ -91,6 +140,11 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl
return "";
}
if (conditions.Count > 0 && !conditions.Peek())
{
return "";
}
do
{
defineMatched = false;

View File

@ -2,10 +2,10 @@
#include <d3d11.h>
namespace T6
{
#include "T6_Assets.h"
namespace T6
{
struct ScriptStringList
{
int count;
@ -27,5 +27,4 @@ namespace T6
int assetCount;
XAsset *assets;
};
}

File diff suppressed because it is too large Load Diff