2019-04-12 17:41:40 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-04-17 15:33:38 +03:00
|
|
|
|
using System.Linq;
|
2019-04-12 17:41:40 +03:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace Generator
|
|
|
|
|
{
|
|
|
|
|
partial class CodeParser
|
|
|
|
|
{
|
|
|
|
|
public class Class
|
|
|
|
|
{
|
|
|
|
|
public string Name;
|
2019-04-13 00:52:55 +03:00
|
|
|
|
public string InterfaceString;
|
2019-04-12 17:41:40 +03:00
|
|
|
|
|
|
|
|
|
public class Function
|
|
|
|
|
{
|
|
|
|
|
public string Name;
|
2019-04-17 15:33:38 +03:00
|
|
|
|
public string DuplicateName;
|
2019-04-12 17:41:40 +03:00
|
|
|
|
public Dictionary<string, string> Arguments = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
|
|
public string ReturnType;
|
|
|
|
|
public string CallResult;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-13 00:52:55 +03:00
|
|
|
|
public List<Function> Functions = new List<Function>();
|
2019-04-12 17:41:40 +03:00
|
|
|
|
|
|
|
|
|
internal Function AddFunction( string funcName, string returnType, string args )
|
|
|
|
|
{
|
2019-06-19 13:33:16 +03:00
|
|
|
|
if ( funcName == "Init" ) funcName = "DoInit";
|
|
|
|
|
if ( funcName == "Shutdown" ) funcName = "DoShutdown";
|
|
|
|
|
|
2019-04-12 17:41:40 +03:00
|
|
|
|
var f = new Function
|
|
|
|
|
{
|
|
|
|
|
Name = funcName,
|
|
|
|
|
ReturnType = returnType
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-16 23:13:55 +03:00
|
|
|
|
args = Regex.Replace( args, "", "" );
|
|
|
|
|
|
2019-04-12 17:41:40 +03:00
|
|
|
|
foreach ( var arg in args.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
|
|
|
|
|
{
|
2019-05-02 15:05:38 +03:00
|
|
|
|
var m = Regex.Match( arg.Trim(), @"(.+?[ |\*|\&])?([a-zA-Z0-9_]+?)( = (.+?))?$" );
|
2019-04-12 17:41:40 +03:00
|
|
|
|
|
|
|
|
|
var t = m.Groups[1].Value.Trim();
|
|
|
|
|
var n = m.Groups[2].Value.Trim();
|
|
|
|
|
|
2019-04-16 13:45:44 +03:00
|
|
|
|
t = Cleanup.ConvertType( t );
|
|
|
|
|
|
2019-04-12 17:41:40 +03:00
|
|
|
|
f.Arguments.Add( n, t );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Functions.Add( f );
|
|
|
|
|
|
|
|
|
|
return f;
|
|
|
|
|
}
|
2019-04-16 18:50:05 +03:00
|
|
|
|
|
|
|
|
|
public void PostProcess()
|
|
|
|
|
{
|
2019-04-17 15:33:38 +03:00
|
|
|
|
var duplicateFunctions = Functions
|
|
|
|
|
.GroupBy( x => x.Name )
|
|
|
|
|
.Where( x => x.Count() > 1 );
|
2019-04-16 18:50:05 +03:00
|
|
|
|
|
2019-04-17 15:33:38 +03:00
|
|
|
|
foreach ( var group in duplicateFunctions )
|
2019-04-16 18:50:05 +03:00
|
|
|
|
{
|
2019-04-17 15:33:38 +03:00
|
|
|
|
var g = group.ToArray();
|
|
|
|
|
for ( int i=0; i< g.Count(); i++ )
|
2019-04-16 18:50:05 +03:00
|
|
|
|
{
|
2019-04-17 15:33:38 +03:00
|
|
|
|
g[i].DuplicateName = g[i].Name;
|
|
|
|
|
g[i].Name = $"{g[i].Name}{i+1}";
|
2019-04-16 18:50:05 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-12 17:41:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|