jit refactoring branch

--HG--
branch : refac-jit
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/refac-jit%402369
This commit is contained in:
David Anderson
2008-07-06 04:49:55 +00:00
commit 2e7b6b5ba5
879 changed files with 297155 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+174
View File
@@ -0,0 +1,174 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace incparser
{
class ParseWriter
{
private int level;
private StringBuilder data;
public ArrayList enumList = new ArrayList();
public ArrayList defineList = new ArrayList();
public ArrayList enumTypeList = new ArrayList();
public ArrayList forwardList = new ArrayList();
public ArrayList nativeList = new ArrayList();
public ArrayList stockList = new ArrayList();
public ArrayList funcenumList = new ArrayList();
public ArrayList functagList = new ArrayList();
public ArrayList structList = new ArrayList();
public int Level
{
get
{
return level;
}
}
public string Contents
{
get
{
return data.ToString();
}
}
public void Reset()
{
level = 0;
data = new StringBuilder();
}
public ParseWriter()
{
level = 0;
data = new StringBuilder();
}
public void BeginSection(string name)
{
WriteLine("\"" + PrepString(name) + "\"");
WriteLine("{");
level++;
}
public void WritePair(string key, string value)
{
WriteLine("\"" + PrepString(key) + "\"\t\t\"" + PrepString(value) + "\"");
}
public void EndSection()
{
if (--level < 0)
{
throw new System.Exception("Writer nesting level went out of bounds");
}
WriteLine("}");
}
public void WriteFiles(string template, string outputfile)
{
StreamReader sr = null;
try
{
sr = File.OpenText(template);
}
catch (Exception e)
{
Console.WriteLine("Failed to open template file: " + e.Message);
return;
}
string contents = sr.ReadToEnd();
string replace = ToOutputString(defineList);
contents = contents.Replace("$defines", replace);
replace = ToOutputString(enumList);
contents = contents.Replace("$enums", replace);
replace = ToOutputString(enumTypeList);
contents = contents.Replace("$enumtypes", replace);
replace = ToOutputString(forwardList);
contents = contents.Replace("$forwards", replace);
replace = ToOutputString(nativeList);
contents = contents.Replace("$natives", replace);
replace = ToOutputString(stockList);
contents = contents.Replace("$stocks", replace);
replace = ToOutputString(funcenumList);
contents = contents.Replace("$funcenums", replace);
replace = ToOutputString(functagList);
contents = contents.Replace("$functags", replace);
replace = ToOutputString(structList);
contents = contents.Replace("$structs", replace);
StreamWriter sw;
sw = File.CreateText(outputfile);
sw.Write(contents);
sr.Close();
sw.Close();
}
private string ToOutputString(ArrayList a)
{
string defines = "";
int count = 0;
foreach (object o in a)
{
defines += o;
defines += " ";
count += o.ToString().Length;
if (count > 180)
{
defines += "\r\n";
count = 0;
}
}
return defines;
}
private void WriteLine(string line)
{
Tabinate();
data.Append(line + "\n");
}
private void Tabinate()
{
for (int i = 0; i < level; i++)
{
data.Append("\t");
}
}
private string PrepString(string text)
{
/* Escape all escaped newlines (so they can be unescaped later) */
text = text.Replace("\\n", "\\\\n");
/* Escape all literal newlines */
text = text.Replace("\n", "\\n");
text = text.Replace("\r", "");
/* Remove escaped quotations */
text = text.Replace("\\\"", "\"");
/* Replace all quotations with escaped ones now */
text = text.Replace("\"", "\\\"");
return text;
}
}
}
+183
View File
@@ -0,0 +1,183 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace incparser
{
class Program
{
static void Main(string[] args)
{
Environment.Exit(SubMain(args));
}
static int SubMain(string[] args)
{
string directory = ".";
string template = "template.txt";
string outputfile = "output.txt";
string file = null;
if (args.Length == 0 || (args.Length == 1 && args[0] == "-h"))
{
PrintHelp();
return 0;
}
for (int i=0; i<args.Length-1; i++)
{
if (args[i] == "-d")
{
directory = args[i + 1];
}
if (args[i] == "-t")
{
template = args[i + 1];
}
if (args[i] == "-o")
{
outputfile = args[i + 1];
}
if (args[i] == "-f")
{
file = args[i + 1];
}
if (args[i] == "-h")
{
if (args[i + 1] == "template")
{
PrintTemplateHelp();
return 0;
}
PrintHelp();
return 0;
}
}
IncParser inc = null;
if (file == null)
{
DirectoryInfo di = new DirectoryInfo(directory);
FileInfo[] rgFiles = di.GetFiles("*.inc");
ParseWriter pwr = new ParseWriter();
foreach (FileInfo fi in rgFiles)
{
pwr.Reset();
Console.Write("Parsing file: " + fi.ToString() + "... ");
try
{
inc = new IncParser(fi.FullName);
}
catch (ParseException e)
{
Console.WriteLine("Initial browsing failed: " + e.Message);
continue;
}
catch (System.Exception e)
{
Console.WriteLine("Failed to read file: " + e.Message);
continue;
}
try
{
inc.Parse(pwr);
}
catch (System.Exception e)
{
Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
continue;
}
if (pwr.Level != 0)
{
Console.WriteLine("Fatal parse error detected; unable to complete output.");
continue;
}
Console.WriteLine("Complete!");
}
pwr.WriteFiles(template, outputfile);
Console.WriteLine("Parsing Complete!");
return 0;
}
try
{
inc = new IncParser(file);
}
catch (ParseException e)
{
Console.WriteLine("Initial browsing failed: " + e.Message);
return 1;
}
catch (System.Exception e)
{
Console.WriteLine("Failed to read file: " + e.Message);
return 1;
}
ParseWriter pw = new ParseWriter();
try
{
inc.Parse(pw);
}
catch (System.Exception e)
{
Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
return 1;
}
if (pw.Level != 0)
{
Console.WriteLine("Fatal parse error detected; unable to complete output.");
return 1;
}
Console.Write(pw.Contents);
Console.Write("\n");
return 0;
}
static void PrintHelp()
{
Console.WriteLine("SourcePawn include file parser by BAILOPAN (edited by pRED*)");
Console.Write("\n");
Console.WriteLine("This can parse a single file into SMC configuration format or an entire directory into a template file if -f is not specified (current directory is used if -d is not specified)");
Console.Write("\n");
Console.WriteLine("Parameters:");
Console.Write("\n");
Console.WriteLine("-f <filename> - Specify an input file to be used");
Console.WriteLine("-d <path> - Specify a directory to parse (only *.inc files are used)");
Console.WriteLine("-t <filename> - Specify a template file to be used");
Console.WriteLine("-o <filename> - Specify an output file to be used");
Console.WriteLine("-h - Display this help");
Console.WriteLine("-h template - Displays help about templates");
}
static void PrintTemplateHelp()
{
Console.WriteLine("Template File Help:");
Console.WriteLine("The inc parser can read a template file and replace variables with the outputs of it's parse and write into the output file");
Console.Write("\n");
Console.WriteLine("Variables:");
Console.Write("\n");
Console.WriteLine("$defines $enums $enumtypes $forwards $natives $stocks $funcenums $functags $structs");
}
}
}
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("incparser")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("AlliedModders")]
[assembly: AssemblyProduct("incparser")]
[assembly: AssemblyCopyright("Copyright © AlliedModders 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("81138f67-d686-415d-b9e2-0fca86c29a22")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+55
View File
@@ -0,0 +1,55 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{064EA9DC-51DC-4EE5-843B-0E3F7069635E}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>incparser</RootNamespace>
<AssemblyName>incparser</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IncParser.cs" />
<Compile Include="ParseWriter.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+20
View File
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C# Express 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "incparser", "incparser.csproj", "{064EA9DC-51DC-4EE5-843B-0E3F7069635E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{064EA9DC-51DC-4EE5-843B-0E3F7069635E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{064EA9DC-51DC-4EE5-843B-0E3F7069635E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{064EA9DC-51DC-4EE5-843B-0E3F7069635E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{064EA9DC-51DC-4EE5-843B-0E3F7069635E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal