Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
Changed all references to GCC Xml outside of the CastXml class to ref…
Browse files Browse the repository at this point in the history
…er to CastXml. References in CastXml.cs stay because we are using the GCC-XML compatible output format.
  • Loading branch information
jkoritzinsky committed Mar 18, 2017
1 parent bc7b9e6 commit 18affc7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 51 deletions.
12 changes: 6 additions & 6 deletions Source/Tools/SharpGen/CodeGenApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public CodeGenApp()
public string DocProviderAssemblyPath { get; set; }

/// <summary>
/// Gets or sets the GCC XML executable path.
/// Gets or sets the CastXML executable path.
/// </summary>
/// <value>The GCC XML executable path.</value>
public string GccXmlExecutablePath { get; set; }
/// <value>The CastXML executable path.</value>
public string CastXmlExecutablePath { get; set; }

/// <summary>
/// Gets or sets the path to the Visual C++ toolset
Expand Down Expand Up @@ -114,10 +114,10 @@ public void ParseArguments(string[] args)
"Usage: SharpGen [options] config_file.xml",
"Code generator from C++ to C# for .Net languages",
"",
{"g|gccxml=", "Specify the path to gccxml.exe", opt => GccXmlExecutablePath = opt},
{"c|castxml=", "Specify the path to castxml.exe", opt => CastXmlExecutablePath = opt},
{"d|doc", "Specify to generate the documentation [default: false]", opt => IsGeneratingDoc = true},
{"p|docpath=", "Specify the path to the assembly doc provider [default: null]", opt => DocProviderAssemblyPath = opt},
{"c|vctools=", "Specify the path to the Visual C++ Toolset", opt => VcToolsPath = opt },
{"v|vctools=", "Specify the path to the Visual C++ Toolset", opt => VcToolsPath = opt },
"",
{"h|help", "Show this message and exit", opt => showHelp = opt != null},
// default
Expand Down Expand Up @@ -199,7 +199,7 @@ public void Run()
DocProviderAssembly = DocProviderAssemblyPath,
// @"..\..\..\DocProviderFromMsdn\bin\debug\DocProviderFromMsdn.exe",
ForceParsing = _isAssemblyNew,
GccXmlExecutablePath = GccXmlExecutablePath
CastXmlExecutablePath = CastXmlExecutablePath
};

// Init the parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@
namespace SharpGen.Parser
{
/// <summary>
/// GccXml front end for command line.
/// see http://www.gccxml.org/HTML/Index.html
/// CastXML front end for command line.
/// see https://github.com/CastXML/CastXML
/// </summary>
public class GccXml
public class CastXml
{
private const string GccXmlGccOptionsFile = "gccxml_preprocess_sharpdx_options.txt";
private static readonly Regex MatchError = new Regex("error:");

/// <summary>
Expand Down Expand Up @@ -129,9 +128,9 @@ public class GccXml
private readonly List<Regex> _filterErrors;

/// <summary>
/// Initializes a new instance of the <see cref="GccXml"/> class.
/// Initializes a new instance of the <see cref="CastXml"/> class.
/// </summary>
public GccXml()
public CastXml()
{
IncludeDirectoryList = new List<IncludeDirRule>();
_filterErrors = new List<Regex>();
Expand All @@ -155,10 +154,10 @@ public void AddFilterError(string file, string regexpError)
/// <param name="handler">The handler.</param>
public void Preprocess(string headerFile, DataReceivedEventHandler handler)
{
Logger.RunInContext("gccxml", () =>
Logger.RunInContext("castxml", () =>
{
if (!File.Exists(ExecutablePath))
Logger.Fatal("gccxml.exe not found from path: [{0}]", ExecutablePath);
Logger.Fatal("castxml.exe not found from path: [{0}]", ExecutablePath);
if (!File.Exists(headerFile))
Logger.Fatal("C++ Header file [{0}] not found", headerFile);
Expand Down Expand Up @@ -264,7 +263,7 @@ private List<string> GetIncludePaths()

foreach (var path in paths)
{
Logger.Message("Path used for gccxml [{0}]", path);
Logger.Message("Path used for castxml [{0}]", path);
}

return paths;
Expand All @@ -279,11 +278,11 @@ public StreamReader Process(string headerFile)
{
StreamReader result = null;

Logger.RunInContext("gccxml", () =>
Logger.RunInContext("castxml", () =>
{
ExecutablePath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, ExecutablePath));
if (!File.Exists(ExecutablePath)) Logger.Fatal("gccxml.exe not found from path: [{0}]", ExecutablePath);
if (!File.Exists(ExecutablePath)) Logger.Fatal("castxml.exe not found from path: [{0}]", ExecutablePath);
if (!File.Exists(headerFile)) Logger.Fatal("C++ Header file [{0}] not found", headerFile);
Expand Down Expand Up @@ -323,7 +322,7 @@ public StreamReader Process(string headerFile)
if (!File.Exists(xmlFile) || Logger.HasErrors)
{
Logger.Error("Unable to generate XML file with gccxml [{0}]. Check previous errors.", xmlFile);
Logger.Error("Unable to generate XML file with castxml [{0}]. Check previous errors.", xmlFile);
}
else
{
Expand Down
56 changes: 28 additions & 28 deletions Source/Tools/SharpGen/Parser/CppParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static string AttributeValue(this XElement xElement, string name)
}

/// <summary>
/// Full C++ Parser built on top of <see cref="GccXml"/>.
/// Full C++ Parser built on top of <see cref="CastXml"/>.
/// </summary>
public class CppParser
{
Expand All @@ -61,7 +61,7 @@ public class CppParser
private Dictionary<string, bool> _includeIsAttached = new Dictionary<string, bool>();
private Dictionary<string, List<string>> _includeAttachedTypes = new Dictionary<string, List<string>>();
private readonly Dictionary<string, string> _bindings = new Dictionary<string, string>();
private GccXml _gccxml;
private CastXml _gccxml;
private string _configRootHeader;
private ConfigFile _configRoot;
private CppInclude _currentCppInclude;
Expand Down Expand Up @@ -101,10 +101,10 @@ public CppParser()
public bool ForceParsing { get; set; }

/// <summary>
/// Gets or sets the GCC XML executable path.
/// Gets or sets the CastXML executable path.
/// </summary>
/// <value>The GCC XML executable path.</value>
public string GccXmlExecutablePath { get; set; }
/// <value>The CastXML executable path.</value>
public string CastXmlExecutablePath { get; set; }

/// <summary>
/// Initialize this Parser from a root ConfigFile.
Expand All @@ -117,7 +117,7 @@ public void Init(ConfigFile configRoot)

// var configRoot = ConfigFile.Load(@"E:\code\sharpdx-v2\Source\Mapping.xml");
_configRootHeader = _configRoot.Id + ".h";
_gccxml = new GccXml {ExecutablePath = GccXmlExecutablePath};
_gccxml = new CastXml {ExecutablePath = CastXmlExecutablePath};

// Config is updated if ForceParsing is true
_isConfigUpdated = ForceParsing;
Expand Down Expand Up @@ -608,14 +608,14 @@ private void Parse(StreamReader reader)
// Fix all structure names
foreach (var xTypedef in doc.Elements("GCC_XML").Elements())
{
if (xTypedef.Name.LocalName == GccXml.TagTypedef)
if (xTypedef.Name.LocalName == CastXml.TagTypedef)
{
var xStruct = _mapIdToXElement[xTypedef.AttributeValue("type")];
switch (xStruct.Name.LocalName)
{
case GccXml.TagStruct:
case GccXml.TagUnion:
case GccXml.TagEnumeration:
case CastXml.TagStruct:
case CastXml.TagUnion:
case CastXml.TagEnumeration:
string structName = xStruct.AttributeValue("name");
// Rename all structure starting with tagXXXX to XXXX
//if (structName.Length > 4 && structName.StartsWith("tag") && Char.IsUpper(structName[3]))
Expand Down Expand Up @@ -1019,7 +1019,7 @@ private CppStruct ParseStructOrUnion(XElement xElement, CppElement cppParent = n

// Create struct
var cppStruct = new CppStruct { Name = structName };
bool isUnion = (xElement.Name.LocalName == GccXml.TagUnion);
bool isUnion = (xElement.Name.LocalName == CastXml.TagUnion);

// Get align from structure
cppStruct.Align = int.Parse(xElement.AttributeValue("align"))/8;
Expand All @@ -1039,7 +1039,7 @@ private CppStruct ParseStructOrUnion(XElement xElement, CppElement cppParent = n
int innerStructCount = 0;
foreach (var field in xElement.Elements())
{
if (field.Name.LocalName != GccXml.TagField)
if (field.Name.LocalName != CastXml.TagField)
continue;

// Parse the field
Expand Down Expand Up @@ -1245,7 +1245,7 @@ private void ParseAllElements()
{
// If the element is not defined from a root namespace
// than skip it, as it might be an inner type
if (_mapIdToXElement[xElement.AttributeValue("context")].Name.LocalName != GccXml.TagNamespace)
if (_mapIdToXElement[xElement.AttributeValue("context")].Name.LocalName != CastXml.TagNamespace)
continue;

// If incomplete flag, than element cannot be parsed
Expand All @@ -1264,25 +1264,25 @@ private void ParseAllElements()
CppElement cppElement = null;
switch (name)
{
case GccXml.TagEnumeration:
case CastXml.TagEnumeration:
cppElement = ParseEnum(xElement);
break;
case GccXml.TagFunction:
case CastXml.TagFunction:
// TODO: Find btter criteria for exclusion. In CastXML extern="1" only indicates an explicit external storage modifier.
// For now, exlude inline functions instead; may not be sensible since by default all functions have external linkage.
if (xElement.AttributeValue("inline") == null)
cppElement = ParseFunction(xElement);
break;
case GccXml.TagStruct:
case CastXml.TagStruct:
if (xElement.AttributeValue("abstract") != null)
cppElement = ParseInterface(xElement);
else
cppElement = ParseStructOrUnion(xElement);
break;
case GccXml.TagUnion:
case CastXml.TagUnion:
cppElement = ParseStructOrUnion(xElement);
break;
case GccXml.TagVariable:
case CastXml.TagVariable:
if (xElement.AttributeValue("init") != null)
cppElement = ParseVariable(xElement);
break;
Expand Down Expand Up @@ -1347,16 +1347,16 @@ private void ResolveAndFillType(string typeId, CppType type)
string nextType = xType.AttributeValue("type");
switch (xType.Name.LocalName)
{
case GccXml.TagFundamentalType:
case CastXml.TagFundamentalType:
type.TypeName = ConvertFundamentalType(name);
isTypeResolved = true;
break;
case GccXml.TagEnumeration:
case CastXml.TagEnumeration:
type.TypeName = name;
isTypeResolved = true;
break;
case GccXml.TagStruct:
case GccXml.TagUnion:
case CastXml.TagStruct:
case CastXml.TagUnion:
type.TypeName = name;

// If the structure being processed is an external include
Expand All @@ -1366,19 +1366,19 @@ private void ResolveAndFillType(string typeId, CppType type)

isTypeResolved = true;
break;
case GccXml.TagTypedef:
case CastXml.TagTypedef:
if (_bindings.ContainsKey(name))
{
type.TypeName = name;
isTypeResolved = true;
}
xType = _mapIdToXElement[nextType];
break;
case GccXml.TagPointerType:
case CastXml.TagPointerType:
xType = _mapIdToXElement[nextType];
type.Pointer = (type.Pointer ?? "") + "*";
break;
case GccXml.TagArrayType:
case CastXml.TagArrayType:
type.IsArray = true;
var maxArrayIndex = xType.AttributeValue("max");
var arrayDim = int.Parse(maxArrayIndex.TrimEnd('u')) + 1;
Expand All @@ -1388,15 +1388,15 @@ private void ResolveAndFillType(string typeId, CppType type)
type.ArrayDimension += "," + arrayDim;
xType = _mapIdToXElement[nextType];
break;
case GccXml.TagReferenceType:
case CastXml.TagReferenceType:
xType = _mapIdToXElement[nextType];
type.Pointer = (type.Pointer ?? "") + "&";
break;
case GccXml.TagCvQualifiedType:
case CastXml.TagCvQualifiedType:
xType = _mapIdToXElement[nextType];
type.Const = true;
break;
case GccXml.TagFunctionType:
case CastXml.TagFunctionType:
// TODO, handle different calling convention
type.TypeName = "__function__stdcall";
isTypeResolved = true;
Expand Down
4 changes: 2 additions & 2 deletions Source/Tools/SharpGen/Parser/MacroManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public class MacroManager
{
private static readonly Regex MatchIncludeLine = new Regex(@"^\s*#\s+\d+\s+""([^""]+)""", RegexOptions.Compiled);
private static readonly Regex MatchDefine = new Regex(@"^\s*#define\s+([a-zA-Z_][\w_]*)\s+(.*)", RegexOptions.Compiled);
private readonly GccXml _gccxml;
private readonly CastXml _gccxml;
private Dictionary<string, string> _currentMacros = null;
private readonly Dictionary<string, Dictionary<string, string>> _mapIncludeToMacros = new Dictionary<string, Dictionary<string, string>>();

/// <summary>
/// Initializes a new instance of the <see cref="MacroManager"/> class.
/// </summary>
/// <param name="gccxml">The GccXml parser.</param>
public MacroManager(GccXml gccxml)
public MacroManager(CastXml gccxml)
{
_gccxml = gccxml;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Tools/SharpGen/RunGenerator.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set VCToolsInstallDir=
if exist "%InstallDir%\VC\Tools\MSVC\%ToolsVersion%\" (
set "VCToolsInstallDir=%InstallDir%\VC\Tools\MSVC\%ToolsVersion%\"
)
SharpGen.exe --doc --gccxml ..\..\..\..\..\External\castxml\bin\castxml.exe ..\..\..\..\Mapping.xml --vctools "%VCToolsInstallDir%
SharpGen.exe --doc --castxml ..\..\..\..\..\External\castxml\bin\castxml.exe ..\..\..\..\Mapping.xml --vctools "%VCToolsInstallDir%
set LOCALERROR = %ERRORLEVEL%
xcopy /D /Y MSDNDoc.zip %~dp0
exit /B %LOCALERROR%
4 changes: 2 additions & 2 deletions Source/Tools/SharpGen/SharpGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>SharpGen.ico</ApplicationIcon>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup Condition="'$(SharpDXPlatform)' == 'StoreApp'">
<DefineConstants>$(DefineConstants);STORE_APP</DefineConstants>
</PropertyGroup>
Expand Down Expand Up @@ -143,7 +143,7 @@
<Compile Include="Config\ConfigBaseRule.cs" />
<Compile Include="Generator\TransformBase.cs" />
<Compile Include="Generator\NamingRulesManager.cs" />
<Compile Include="Parser\GccXml.cs" />
<Compile Include="Parser\CastXml.cs" />
<Compile Include="Parser\MacroManager.cs" />
<Compile Include="Parser\CppParser.cs" />
<Compile Include="Model\InteropType.cs" />
Expand Down

0 comments on commit 18affc7

Please sign in to comment.