mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
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:
parent
c8a2bec12b
commit
57ef79692a
@ -20,6 +20,11 @@ namespace std
|
|||||||
typedef long long int64_t;
|
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 types do not need to be processed.
|
||||||
// DirectX 9 Types
|
// DirectX 9 Types
|
||||||
typedef void IDirect3DVertexDeclaration9;
|
typedef void IDirect3DVertexDeclaration9;
|
||||||
@ -39,3 +44,5 @@ typedef void ID3D11Buffer;
|
|||||||
#define __unaligned
|
#define __unaligned
|
||||||
#define volatile
|
#define volatile
|
||||||
#define __cppobj
|
#define __cppobj
|
||||||
|
|
||||||
|
// EOF
|
@ -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 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 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 defineRegex = new Regex(@"^\s*#define\s+(\w+)(?:\s+(.*))?$");
|
||||||
private static readonly Regex undefRegex = new Regex(@"^\s*#undef\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 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 IIncludingParsingStream streamFileSystem;
|
||||||
private readonly IHeaderParserState state;
|
private readonly IHeaderParserState state;
|
||||||
private readonly ICommentProcessor commentProcessor;
|
private readonly ICommentProcessor commentProcessor;
|
||||||
|
|
||||||
private readonly Dictionary<string, string> defines;
|
private readonly Dictionary<string, string> defines;
|
||||||
|
private readonly Stack<bool> conditions;
|
||||||
|
|
||||||
public bool EndOfStream => streamFileSystem.EndOfStream;
|
public bool EndOfStream => streamFileSystem.EndOfStream;
|
||||||
public string Filename => streamFileSystem.Filename;
|
public string Filename => streamFileSystem.Filename;
|
||||||
@ -27,8 +32,14 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl
|
|||||||
{
|
{
|
||||||
streamFileSystem = includingParsingStream;
|
streamFileSystem = includingParsingStream;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
defines = new Dictionary<string, string>();
|
|
||||||
commentProcessor = new CommentProcessor();
|
commentProcessor = new CommentProcessor();
|
||||||
|
|
||||||
|
defines = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{"__zonecodegenerator", "1"}
|
||||||
|
};
|
||||||
|
|
||||||
|
conditions = new Stack<bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseCompilerExpression(string line)
|
private void ParseCompilerExpression(string line)
|
||||||
@ -78,6 +89,44 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl
|
|||||||
streamFileSystem.IncludeFile(filename);
|
streamFileSystem.IncludeFile(filename);
|
||||||
return;
|
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)
|
private string Preprocess(string line)
|
||||||
@ -91,6 +140,11 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (conditions.Count > 0 && !conditions.Peek())
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
defineMatched = false;
|
defineMatched = false;
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
|
|
||||||
namespace T6
|
|
||||||
{
|
|
||||||
#include "T6_Assets.h"
|
#include "T6_Assets.h"
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
struct ScriptStringList
|
struct ScriptStringList
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
@ -27,5 +27,4 @@ namespace T6
|
|||||||
int assetCount;
|
int assetCount;
|
||||||
XAsset *assets;
|
XAsset *assets;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user