removed some deleted files from repository
This commit is contained in:
parent
99216ca254
commit
b82cfd40ee
@ -1,26 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HLSLParser", "HLSLParser\HLSLParser.csproj", "{9588B0C3-E03A-4C71-89A4-2C8685D426F1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HLSLParserTests", "HLSLParserTests\HLSLParserTests.csproj", "{F9177943-1590-49AE-987D-D6FAE30D96DD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9588B0C3-E03A-4C71-89A4-2C8685D426F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9588B0C3-E03A-4C71-89A4-2C8685D426F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9588B0C3-E03A-4C71-89A4-2C8685D426F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9588B0C3-E03A-4C71-89A4-2C8685D426F1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F9177943-1590-49AE-987D-D6FAE30D96DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F9177943-1590-49AE-987D-D6FAE30D96DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F9177943-1590-49AE-987D-D6FAE30D96DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F9177943-1590-49AE-987D-D6FAE30D96DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Binary file not shown.
@ -1,101 +0,0 @@
|
||||
using System;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public static class CommentRemover
|
||||
{
|
||||
#region Remove
|
||||
public static string Remove(string source)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source = RemoveMultilineComments(source);
|
||||
source = RemoveSingleLineComments(source);
|
||||
|
||||
return source;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region RemoveMultilineComments
|
||||
private static string RemoveMultilineComments(string source)
|
||||
{
|
||||
int currentIndex = 0;
|
||||
int textLength = source.Length;
|
||||
while (currentIndex < textLength)
|
||||
{
|
||||
currentIndex = source.IndexOf("/*", currentIndex);
|
||||
if (currentIndex == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentIndex != 0 &&
|
||||
source[currentIndex - 1] == '/')
|
||||
{
|
||||
currentIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
int endIndex = source.IndexOf("*/", currentIndex);
|
||||
source = source.Remove(currentIndex, endIndex - currentIndex + 2);
|
||||
textLength = source.Length;
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region RemoveSingleLineComments
|
||||
private static string RemoveSingleLineComments(string source)
|
||||
{
|
||||
string[] lines = SplitLines(source);
|
||||
|
||||
for (int index = 0; index < lines.Length; index++)
|
||||
{
|
||||
string line = lines[index];
|
||||
int commentIndex = line.IndexOf("//");
|
||||
if (commentIndex == -1)
|
||||
continue;
|
||||
|
||||
lines[index] = line.Substring(0, commentIndex);
|
||||
}
|
||||
|
||||
return MergeLines(lines);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SplitLines
|
||||
internal static string[] SplitLines(string source)
|
||||
{
|
||||
source = source.Replace('\r', '\n');
|
||||
return source.Split(new char[] { '\n' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region MergeLines
|
||||
internal static string MergeLines(string[] lines)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (line == null)
|
||||
continue;
|
||||
|
||||
if (String.IsNullOrEmpty(line.Trim()) == false)
|
||||
result += line + "\n";
|
||||
}
|
||||
|
||||
return result.TrimEnd('\n');
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
using System;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public class EffectBuffer : IShaderElement
|
||||
{
|
||||
#region Public
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Type
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public EffectBuffer(ParseTextWalker walker)
|
||||
{
|
||||
string text = walker.Text;
|
||||
|
||||
int typeStartIndex = text.IndexOf('<') + 1;
|
||||
int typeEndIndex = text.IndexOf('>');
|
||||
Type = text.Substring(typeStartIndex, typeEndIndex - typeStartIndex);
|
||||
|
||||
typeEndIndex++;
|
||||
|
||||
int semicolonIndex = text.IndexOf(';');
|
||||
Name = text.Substring(typeEndIndex, semicolonIndex - typeEndIndex).Trim();
|
||||
|
||||
walker.Seek(semicolonIndex + 1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TryParse
|
||||
public static EffectBuffer TryParse(ParseTextWalker walker)
|
||||
{
|
||||
return walker.Text.StartsWith("Buffer") ?
|
||||
new EffectBuffer(walker) :
|
||||
null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
return "Buffer<" + Type + "> " + Name + ";";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public class EffectFile
|
||||
{
|
||||
#region Public
|
||||
public string Source
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Variable> Variables
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Structure> Structures
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<TypeDef> TypeDefs
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Technique> Techniques
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<EffectBuffer> Buffers
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Sampler> Samplers
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Method> Methods
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
internal EffectFile(string setSource)
|
||||
{
|
||||
Source = setSource;
|
||||
Variables = new List<Variable>();
|
||||
Structures = new List<Structure>();
|
||||
TypeDefs = new List<TypeDef>();
|
||||
Techniques = new List<Technique>();
|
||||
Buffers = new List<EffectBuffer>();
|
||||
Samplers = new List<Sampler>();
|
||||
Methods = new List<Method>();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9588B0C3-E03A-4C71-89A4-2C8685D426F1}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>HLSLParser</RootNamespace>
|
||||
<AssemblyName>HLSLParser</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</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" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EffectBuffer.cs" />
|
||||
<Compile Include="CommentRemover.cs" />
|
||||
<Compile Include="EffectFile.cs" />
|
||||
<Compile Include="IShaderElement.cs" />
|
||||
<Compile Include="Method.cs" />
|
||||
<Compile Include="Parser.cs" />
|
||||
<Compile Include="ParseTextWalker.cs" />
|
||||
<Compile Include="Pass.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Sampler.cs" />
|
||||
<Compile Include="Structure.cs" />
|
||||
<Compile Include="Technique.cs" />
|
||||
<Compile Include="TypeDef.cs" />
|
||||
<Compile Include="Variable.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\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>
|
@ -1,12 +0,0 @@
|
||||
using System;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public interface IShaderElement
|
||||
{
|
||||
}
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
using System;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public class Method : IShaderElement
|
||||
{
|
||||
#region Public
|
||||
public string StorageClass
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string ReturnType
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Semantic
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Arguments
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Body
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Method(ParseTextWalker walker)
|
||||
{
|
||||
string text = walker.Text;
|
||||
if (text.StartsWith("inline"))
|
||||
{
|
||||
StorageClass = "inline";
|
||||
walker.Seek("inline".Length);
|
||||
text = walker.Text;
|
||||
}
|
||||
|
||||
int indexOfOpenParenthesis = text.IndexOf('(');
|
||||
int indexOfCloseParenthesis = text.IndexOf(')');
|
||||
|
||||
string headerPart = text.Substring(0, indexOfOpenParenthesis).Trim();
|
||||
headerPart = walker.RemoveUnneededChars(headerPart);
|
||||
|
||||
string[] parts = headerPart.Split(new char[] { ' ' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
ReturnType = parts[0].Trim();
|
||||
Name = parts[1].Trim();
|
||||
|
||||
Arguments = text.Substring(indexOfOpenParenthesis + 1,
|
||||
indexOfCloseParenthesis - indexOfOpenParenthesis - 1);
|
||||
|
||||
walker.Seek(indexOfCloseParenthesis + 1);
|
||||
text = walker.Text;
|
||||
|
||||
int indexOfMethodBodyStart = text.IndexOf('{');
|
||||
|
||||
if (text.StartsWith(":"))
|
||||
{
|
||||
Semantic = text.Substring(1, indexOfMethodBodyStart - 1).Trim();
|
||||
Semantic = walker.RemoveUnneededChars(Semantic);
|
||||
}
|
||||
|
||||
walker.Seek(indexOfMethodBodyStart + 1);
|
||||
|
||||
GetMethodBody(walker);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetMethodBody
|
||||
private void GetMethodBody(ParseTextWalker walker)
|
||||
{
|
||||
string text = walker.Text;
|
||||
|
||||
int numberOfOpenBraces = 0;
|
||||
int searchBodyEndIndex = 0;
|
||||
while (searchBodyEndIndex < text.Length)
|
||||
{
|
||||
char currentChar = text[searchBodyEndIndex];
|
||||
if (currentChar == '{')
|
||||
numberOfOpenBraces++;
|
||||
else if (currentChar == '}')
|
||||
numberOfOpenBraces--;
|
||||
|
||||
if (numberOfOpenBraces == -1)
|
||||
break;
|
||||
|
||||
searchBodyEndIndex++;
|
||||
}
|
||||
|
||||
Body = text.Substring(0, searchBodyEndIndex - 1);
|
||||
Body = Body.TrimEnd('\n', '\r', '\t');
|
||||
|
||||
walker.Seek(searchBodyEndIndex + 1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TryParse
|
||||
public static Method TryParse(ParseTextWalker walker)
|
||||
{
|
||||
if(walker.Text.StartsWith("inline ") ||
|
||||
CheckIfMethodHeaderExists(walker))
|
||||
{
|
||||
return new Method(walker);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CheckIfMethodHeaderExists
|
||||
private static bool CheckIfMethodHeaderExists(ParseTextWalker walker)
|
||||
{
|
||||
string text = walker.Text;
|
||||
int indexOfOpenParenthesis = text.IndexOf('(');
|
||||
if (indexOfOpenParenthesis == -1)
|
||||
return false;
|
||||
|
||||
string headerPart = text.Substring(0, indexOfOpenParenthesis).Trim();
|
||||
headerPart = headerPart.Replace("\n", "");
|
||||
headerPart = headerPart.Replace("\r", "");
|
||||
headerPart = headerPart.Replace("\t", "");
|
||||
|
||||
string[] parts = headerPart.Split(new char[] { ' ' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
return parts.Length == 2;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
string result = "";
|
||||
if (String.IsNullOrEmpty(StorageClass) == false)
|
||||
{
|
||||
result += StorageClass + " ";
|
||||
}
|
||||
|
||||
result += ReturnType + " " + Name + "(" + Arguments + ")";
|
||||
|
||||
if (String.IsNullOrEmpty(Semantic) == false)
|
||||
{
|
||||
result += " : " + Semantic;
|
||||
}
|
||||
|
||||
result += "\n{\n\t" + Body + "\n}";
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
using System;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public class ParseTextWalker
|
||||
{
|
||||
public string Text
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public ParseTextWalker(string setText)
|
||||
{
|
||||
Text = setText;
|
||||
Seek(0);
|
||||
}
|
||||
|
||||
public void Seek(int length)
|
||||
{
|
||||
Text = Text.Substring(length);
|
||||
string text = Text;
|
||||
text = text.TrimStart(' ', '\n', '\r', '\t');
|
||||
length = Text.Length - text.Length;
|
||||
Text = Text.Substring(length);
|
||||
}
|
||||
|
||||
public string RemoveUnneededChars(string text)
|
||||
{
|
||||
text = text.Replace("\n", "");
|
||||
text = text.Replace("\r", "");
|
||||
text = text.Replace("\t", "");
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
/// <summary>
|
||||
/// Spec:
|
||||
/// http://msdn.microsoft.com/en-us/library/windows/desktop/bb509615%28v=vs.85%29.aspx
|
||||
/// </summary>
|
||||
public class Parser
|
||||
{
|
||||
#region Public
|
||||
public EffectFile Effect
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
private Parser(string sourceCode)
|
||||
{
|
||||
Effect = new EffectFile(sourceCode);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region LoadFromFile
|
||||
public static Parser LoadFromFile(string filepath)
|
||||
{
|
||||
ValidateFilepath(filepath);
|
||||
return new Parser(File.ReadAllText(filepath));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region LoadFromSource
|
||||
public static Parser LoadFromSource(string sourceCode)
|
||||
{
|
||||
return new Parser(sourceCode);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Parse
|
||||
public void Parse()
|
||||
{
|
||||
string commentFreeSource = CommentRemover.Remove(Effect.Source);
|
||||
var textWalker = new ParseTextWalker(commentFreeSource);
|
||||
|
||||
WalkText(textWalker);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WalkText
|
||||
private void WalkText(ParseTextWalker walker)
|
||||
{
|
||||
while (walker.Text.Length > 0)
|
||||
{
|
||||
int beforeLength = walker.Text.Length;
|
||||
|
||||
if (TryParse(Method.TryParse(walker), Effect.Methods))
|
||||
continue;
|
||||
|
||||
if (TryParse(Structure.TryParse(walker), Effect.Structures))
|
||||
continue;
|
||||
|
||||
if (TryParse(TypeDef.TryParse(walker), Effect.TypeDefs))
|
||||
continue;
|
||||
|
||||
if (TryParse(Sampler.TryParse(walker), Effect.Samplers))
|
||||
continue;
|
||||
|
||||
if (TryParse(Technique.TryParse(walker), Effect.Techniques))
|
||||
continue;
|
||||
|
||||
if (TryParse(EffectBuffer.TryParse(walker), Effect.Buffers))
|
||||
continue;
|
||||
|
||||
if (TryParse(Variable.TryParse(walker), Effect.Variables))
|
||||
continue;
|
||||
|
||||
if (walker.Text.Length == beforeLength)
|
||||
walker.Seek(1);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TryParse
|
||||
private bool TryParse<T>(IShaderElement parsedElement, List<T> addList)
|
||||
where T : IShaderElement
|
||||
{
|
||||
if (parsedElement != null)
|
||||
{
|
||||
addList.Add((T)parsedElement);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ValidateFilepath
|
||||
private static void ValidateFilepath(string filepath)
|
||||
{
|
||||
if (String.IsNullOrEmpty(filepath))
|
||||
{
|
||||
throw new ArgumentException("filepath");
|
||||
}
|
||||
|
||||
if (File.Exists(filepath) == false)
|
||||
{
|
||||
throw new FileNotFoundException(
|
||||
"Unable to load missing file '" + filepath + "'!");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,176 +0,0 @@
|
||||
using System;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public class Pass : IShaderElement
|
||||
{
|
||||
#region Private
|
||||
private string vertexShaderProfile = "";
|
||||
private string pixelShaderProfile = "";
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string VertexShader
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string VertexShaderProfile
|
||||
{
|
||||
get
|
||||
{
|
||||
return vertexShaderProfile;
|
||||
}
|
||||
}
|
||||
|
||||
public string PixelShader
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string PixelShaderProfile
|
||||
{
|
||||
get
|
||||
{
|
||||
return pixelShaderProfile;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Pass(ParseTextWalker walker)
|
||||
{
|
||||
string text = walker.Text;
|
||||
|
||||
int indexOfNameStart = text.IndexOf(' ') + 1;
|
||||
int indexOfNameEnd = text.IndexOf('{');
|
||||
|
||||
Name = text.Substring(indexOfNameStart, indexOfNameEnd - indexOfNameStart);
|
||||
Name = Name.TrimEnd('\n', '\r', '\t', ' ');
|
||||
|
||||
string passContentText = text.Substring(indexOfNameEnd + 1);
|
||||
if (text.Contains("SetVertexShader"))
|
||||
{
|
||||
passContentText = passContentText.Replace("\t", "").Replace(" ", "");
|
||||
passContentText = passContentText.Replace(",", ", ");
|
||||
ParseDx10Pass(passContentText);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParseDx9Pass(passContentText);
|
||||
}
|
||||
|
||||
walker.Seek(text.IndexOf('}') + 1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseDx10Pass
|
||||
private void ParseDx10Pass(string text)
|
||||
{
|
||||
VertexShader = ParseDx10Shader(text, "SetVertexShader(", ref vertexShaderProfile);
|
||||
PixelShader = ParseDx10Shader(text, "SetPixelShader(", ref pixelShaderProfile);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseDx10Shader
|
||||
private string ParseDx10Shader(string text, string key, ref string profile)
|
||||
{
|
||||
int indexOfshaderStart = text.IndexOf(key) + key.Length;
|
||||
int indexOfPixelShaderEnd = text.IndexOf(");", indexOfshaderStart);
|
||||
string shader = text.Substring(indexOfshaderStart,
|
||||
indexOfPixelShaderEnd - indexOfshaderStart);
|
||||
shader = shader.Replace(" ", "").Replace("\t", "");
|
||||
shader = shader.Replace("\r", "").Replace("\n", "");
|
||||
|
||||
int subPartStartIndex = "CompileShader(".Length;
|
||||
shader = shader.Substring(subPartStartIndex,
|
||||
shader.Length - subPartStartIndex - 1);
|
||||
|
||||
int indexOfFirstComma = shader.IndexOf(',');
|
||||
profile = shader.Substring(0, indexOfFirstComma);
|
||||
shader = shader.Substring(indexOfFirstComma + 1);
|
||||
shader = shader.Replace(",", ", ");
|
||||
|
||||
return shader;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseDx9Pass
|
||||
private void ParseDx9Pass(string text)
|
||||
{
|
||||
VertexShader = ParseDx9Shader(text, "VertexShader", ref vertexShaderProfile);
|
||||
PixelShader = ParseDx9Shader(text, "PixelShader", ref pixelShaderProfile);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseDx9Shader
|
||||
private string ParseDx9Shader(string text, string key, ref string profile)
|
||||
{
|
||||
int indexOfShaderStart = text.IndexOf(key);
|
||||
string shader = "";
|
||||
indexOfShaderStart = text.IndexOf("compile ", indexOfShaderStart);
|
||||
int indexOfShaderEnd = text.IndexOf(';', indexOfShaderStart);
|
||||
shader = text.Substring(indexOfShaderStart,
|
||||
indexOfShaderEnd - indexOfShaderStart);
|
||||
shader = shader.Replace("compile", "");
|
||||
shader = shader.Trim();
|
||||
|
||||
int indexOfSpaceAfterProfile = shader.IndexOf(' ');
|
||||
profile = shader.Substring(0, indexOfSpaceAfterProfile);
|
||||
|
||||
shader = shader.Substring(indexOfSpaceAfterProfile).Trim();
|
||||
shader = shader.Replace(" ", "").Replace(",", ", ");
|
||||
return shader;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TryParse
|
||||
public static Pass TryParse(ParseTextWalker walker)
|
||||
{
|
||||
return walker.Text.StartsWith("pass ") ?
|
||||
new Pass(walker) :
|
||||
null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
return ToStringIndented(0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToStringIndented
|
||||
public string ToStringIndented(int tabs)
|
||||
{
|
||||
string idention = "";
|
||||
for (int tabIndex = 0; tabIndex < tabs; tabIndex++)
|
||||
{
|
||||
idention += "\t";
|
||||
}
|
||||
|
||||
string text = idention + "pass " + Name + "\n" + idention + "{\n";
|
||||
|
||||
text += idention + "\tSetVertexShader(CompileShader(" +
|
||||
VertexShaderProfile + ", " + VertexShader + "));\n";
|
||||
text += idention + "\tSetGeometryShader(NULL);\n";
|
||||
text += idention + "\tSetPixelShader(CompileShader(" +
|
||||
PixelShaderProfile + ", " + PixelShader + "));\n";
|
||||
|
||||
return text + idention + "}";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("HLSLParser")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("ANX Developer Team")]
|
||||
[assembly: AssemblyProduct("HLSLParser")]
|
||||
[assembly: AssemblyCopyright("Copyright © ANX Developer Team 2012")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("687e726e-bdc9-4e22-bf3a-b7cc686e95cd")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
[assembly: InternalsVisibleTo("HLSLParserTests")]
|
@ -1,192 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using StringPair = System.Collections.Generic.KeyValuePair<string, string>;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public class Sampler : IShaderElement
|
||||
{
|
||||
#region Public
|
||||
public string Type
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Register
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<StringPair> States
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Sampler(ParseTextWalker walker)
|
||||
{
|
||||
States = new List<StringPair>();
|
||||
|
||||
ParseType(walker);
|
||||
ParseName(walker);
|
||||
ParseRegister(walker);
|
||||
ParseStates(walker);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseType
|
||||
private void ParseType(ParseTextWalker walker)
|
||||
{
|
||||
int indexOfTypeEndSpace = walker.Text.IndexOf(' ');
|
||||
Type = walker.Text.Substring(0, indexOfTypeEndSpace);
|
||||
walker.Seek(indexOfTypeEndSpace + 1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseName
|
||||
private void ParseName(ParseTextWalker walker)
|
||||
{
|
||||
string text = walker.Text;
|
||||
Name = "";
|
||||
int nameParseIndex = 0;
|
||||
while (nameParseIndex < text.Length)
|
||||
{
|
||||
char currentChar = text[nameParseIndex];
|
||||
if (currentChar == ' ' ||
|
||||
currentChar == '{' ||
|
||||
currentChar == ':' ||
|
||||
currentChar == '=')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Name += currentChar;
|
||||
nameParseIndex++;
|
||||
}
|
||||
|
||||
Name = Name.Trim(' ', '\t', '\n', '\r');
|
||||
|
||||
walker.Seek(nameParseIndex);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseRegister
|
||||
private void ParseRegister(ParseTextWalker walker)
|
||||
{
|
||||
string text = walker.Text;
|
||||
if (text.StartsWith(":"))
|
||||
{
|
||||
int lengthBeforeCut = text.Length;
|
||||
text = text.Substring(1).TrimStart(' ', '\t');
|
||||
int cutLength = lengthBeforeCut - text.Length;
|
||||
|
||||
Register = "";
|
||||
int registerParseIndex = 0;
|
||||
while (registerParseIndex < text.Length)
|
||||
{
|
||||
char currentChar = text[registerParseIndex];
|
||||
if (currentChar == ' ' ||
|
||||
currentChar == '{' ||
|
||||
currentChar == ';' ||
|
||||
currentChar == '=')
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Register += currentChar;
|
||||
registerParseIndex++;
|
||||
}
|
||||
|
||||
Register = Register.Trim(' ', '\t', '\n', '\r');
|
||||
|
||||
walker.Seek(registerParseIndex + cutLength);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseStates
|
||||
private void ParseStates(ParseTextWalker walker)
|
||||
{
|
||||
string text = walker.Text;
|
||||
|
||||
if (text[0] == ';')
|
||||
return;
|
||||
|
||||
int indexOfOpenBrace = text.IndexOf('{');
|
||||
|
||||
walker.Seek(indexOfOpenBrace + 1);
|
||||
|
||||
text = walker.Text;
|
||||
|
||||
int indexOfStatesEndBrace = text.IndexOf('}');
|
||||
string statesSubText = text.Substring(0, indexOfStatesEndBrace);
|
||||
statesSubText = statesSubText.Replace("\n", "");
|
||||
statesSubText = statesSubText.Replace("\r", "");
|
||||
statesSubText = statesSubText.Replace("\t", "");
|
||||
|
||||
indexOfStatesEndBrace = text.IndexOf(';', indexOfStatesEndBrace);
|
||||
walker.Seek(indexOfStatesEndBrace + 1);
|
||||
|
||||
string[] parts = statesSubText.Split(new char[] { '=', ';' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
for (int partIndex = 0; partIndex < parts.Length; partIndex += 2)
|
||||
{
|
||||
States.Add(new StringPair(parts[partIndex].Trim(), parts[partIndex + 1].Trim()));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TryParse
|
||||
public static Sampler TryParse(ParseTextWalker walker)
|
||||
{
|
||||
if (walker.Text.StartsWith("sampler") ||
|
||||
walker.Text.StartsWith("SamplerComparisonState") ||
|
||||
walker.Text.StartsWith("SamplerState"))
|
||||
{
|
||||
return new Sampler(walker);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
string result = Type + " " + Name;
|
||||
|
||||
if (String.IsNullOrEmpty(Register) == false)
|
||||
{
|
||||
result += " : " + Register;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += "\n{";
|
||||
|
||||
foreach (StringPair state in States)
|
||||
{
|
||||
result += "\n\t" + state.Key + " = " + state.Value + ";";
|
||||
}
|
||||
|
||||
result += "\n}";
|
||||
}
|
||||
|
||||
return result + ";";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public class Structure : IShaderElement
|
||||
{
|
||||
#region Public
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Variable> Variables
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Structure(ParseTextWalker walker)
|
||||
{
|
||||
Variables = new List<Variable>();
|
||||
|
||||
string currentText = walker.Text;
|
||||
|
||||
int indexOfStructOpenBrace = currentText.IndexOf('{');
|
||||
walker.Seek(indexOfStructOpenBrace + 1);
|
||||
|
||||
Name = currentText.Substring(0, indexOfStructOpenBrace);
|
||||
Name = Name.Replace("struct ", "").Trim();
|
||||
|
||||
Variable newVariable = null;
|
||||
while ((newVariable = Variable.TryParse(walker)) != null)
|
||||
{
|
||||
Variables.Add(newVariable);
|
||||
}
|
||||
|
||||
currentText = walker.Text;
|
||||
int indexOfStructCloseBrace = currentText.IndexOf("};");
|
||||
walker.Seek(indexOfStructCloseBrace + 2);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TryParse
|
||||
public static Structure TryParse(ParseTextWalker walker)
|
||||
{
|
||||
string currentText = walker.Text;
|
||||
if (currentText.StartsWith("struct"))
|
||||
{
|
||||
return new Structure(walker);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
string result = "struct " + Name + "\n{";
|
||||
|
||||
foreach (Variable variable in Variables)
|
||||
{
|
||||
result += "\n\t" + variable.ToString();
|
||||
}
|
||||
|
||||
return result + "\n};";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public class Technique : IShaderElement
|
||||
{
|
||||
#region Public
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<Pass> Passes
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Technique(ParseTextWalker walker)
|
||||
{
|
||||
Passes = new List<Pass>();
|
||||
|
||||
string text = walker.Text;
|
||||
|
||||
int indexOfNameStart = text.IndexOf(' ') + 1;
|
||||
int indexOfNameEnd = text.IndexOf('{');
|
||||
|
||||
Name = text.Substring(indexOfNameStart, indexOfNameEnd - indexOfNameStart);
|
||||
Name = Name.TrimEnd('\n', '\r', '\t', ' ');
|
||||
|
||||
walker.Seek(indexOfNameEnd + 1);
|
||||
|
||||
Pass newPass = null;
|
||||
while ((newPass = Pass.TryParse(walker)) != null)
|
||||
{
|
||||
Passes.Add(newPass);
|
||||
}
|
||||
|
||||
walker.Seek(walker.Text.IndexOf('}') + 1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TryParse
|
||||
public static Technique TryParse(ParseTextWalker walker)
|
||||
{
|
||||
if (walker.Text.StartsWith("technique"))
|
||||
{
|
||||
return new Technique(walker);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
string text = "technique10 " + Name + "\n{";
|
||||
|
||||
foreach (Pass pass in Passes)
|
||||
{
|
||||
text += "\n" + pass.ToStringIndented(1);
|
||||
}
|
||||
|
||||
return text + "\n}";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
using System;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
public class TypeDef : IShaderElement
|
||||
{
|
||||
#region Constants
|
||||
private const string TypedefKeyword = "typedef ";
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
public string Value
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public TypeDef(ParseTextWalker walker)
|
||||
{
|
||||
int indexOfTypedefEnd = walker.Text.IndexOf(';');
|
||||
Value = walker.Text.Substring(0, indexOfTypedefEnd);
|
||||
|
||||
walker.Seek(indexOfTypedefEnd + 1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TryParse
|
||||
public static TypeDef TryParse(ParseTextWalker walker)
|
||||
{
|
||||
if (walker.Text.StartsWith(TypedefKeyword))
|
||||
{
|
||||
walker.Seek(TypedefKeyword.Length);
|
||||
return new TypeDef(walker);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
return TypedefKeyword + Value + ";";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,496 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParser
|
||||
{
|
||||
/// <summary>
|
||||
/// http://msdn.microsoft.com/en-us/library/windows/desktop/bb509706%28v=vs.85%29.aspx
|
||||
/// </summary>
|
||||
public class Variable : IShaderElement
|
||||
{
|
||||
#region Constants
|
||||
private static char[] SemanticEndChars = new char[]
|
||||
{
|
||||
' ', ':', '<', ';', '='
|
||||
};
|
||||
|
||||
private static readonly List<string> AllTypeModifiers = new List<string>(
|
||||
new string[]
|
||||
{
|
||||
"const",
|
||||
"row_major",
|
||||
"column_major",
|
||||
"extern",
|
||||
"nointerpolation",
|
||||
"precise",
|
||||
"shared",
|
||||
"groupshared",
|
||||
"static",
|
||||
"uniform",
|
||||
"volatile",
|
||||
|
||||
// struct additions
|
||||
"linear",
|
||||
"centroid",
|
||||
"noperspective",
|
||||
"sample"
|
||||
});
|
||||
|
||||
private static readonly List<string> AllTypeNames = new List<string>(
|
||||
new string[]
|
||||
{
|
||||
"int",
|
||||
"bool",
|
||||
"uint",
|
||||
"dword",
|
||||
"half",
|
||||
"float",
|
||||
"double",
|
||||
// "min16float",
|
||||
// "min10float",
|
||||
// "min16int",
|
||||
// "min12int",
|
||||
// "min16uint",
|
||||
|
||||
// vector <Type, Number>
|
||||
"vector",
|
||||
// matrix <Type, Rows, Columns>
|
||||
"matrix",
|
||||
|
||||
"texture",
|
||||
"Texture2D",
|
||||
});
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
public string[] TypeModifiers
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string InitialValue
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public int ArraySize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Type
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Annotations
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Semantic
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Packoffset
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string Register
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public int[] Dimensions
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
protected Variable(ParseTextWalker walker)
|
||||
{
|
||||
ParseType(walker);
|
||||
ReadNameAndArraySize(walker);
|
||||
ParseExtraParameters(walker);
|
||||
ParseAnnotations(walker);
|
||||
ReadInitialValue(walker);
|
||||
|
||||
if (walker.Text.StartsWith(";"))
|
||||
{
|
||||
walker.Seek(1);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseType
|
||||
private void ParseType(ParseTextWalker walker)
|
||||
{
|
||||
string currentText = walker.Text;
|
||||
|
||||
int nextSpaceIndex = FindInitialTypeEndSpace(currentText);
|
||||
string variableType = currentText.Substring(0, nextSpaceIndex);
|
||||
variableType = variableType.Replace(" ", "");
|
||||
walker.Seek(nextSpaceIndex + 1);
|
||||
|
||||
variableType = ResolveMatrixAndArraySyntax(variableType);
|
||||
ParseDimensions(variableType);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region FindInitialTypeEndSpace
|
||||
private int FindInitialTypeEndSpace(string text)
|
||||
{
|
||||
int searchScope = 0;
|
||||
if (text.StartsWith("vector") ||
|
||||
text.StartsWith("matrix"))
|
||||
{
|
||||
searchScope = text.IndexOf('>');
|
||||
}
|
||||
else if (text.StartsWith("Texture") ||
|
||||
text.StartsWith("texture"))
|
||||
{
|
||||
string textureGeneric = text;
|
||||
textureGeneric = textureGeneric.Substring(textureGeneric.IndexOf(' '));
|
||||
textureGeneric = textureGeneric.Trim();
|
||||
if (textureGeneric.StartsWith("<"))
|
||||
{
|
||||
searchScope = text.IndexOf('>');
|
||||
}
|
||||
}
|
||||
|
||||
return text.IndexOf(' ', searchScope);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ResolveMatrixAndArraySyntax
|
||||
private string ResolveMatrixAndArraySyntax(string text)
|
||||
{
|
||||
if (text.Contains("<") &&
|
||||
text.StartsWith("matrix") ||
|
||||
text.StartsWith("vector"))
|
||||
{
|
||||
text = text.Substring(text.IndexOf('<') + 1);
|
||||
text = text.Trim().TrimEnd('>');
|
||||
string[] parts = text.Split(',');
|
||||
text = parts[0].Trim();
|
||||
for (int index = 1; index < parts.Length; index++)
|
||||
{
|
||||
text += (index > 1 ? "x" : "") + parts[index].Trim();
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseDimensions
|
||||
private void ParseDimensions(string typeText)
|
||||
{
|
||||
List<int> dimensions = new List<int>();
|
||||
Type = typeText;
|
||||
int numeralRemoverIndex = typeText.Length - 1;
|
||||
while (numeralRemoverIndex >= 1)
|
||||
{
|
||||
if (Char.IsDigit(Type[numeralRemoverIndex]))
|
||||
{
|
||||
dimensions.Insert(0, int.Parse(Type[numeralRemoverIndex].ToString()));
|
||||
Type = Type.Substring(0, numeralRemoverIndex);
|
||||
}
|
||||
else if (Type[numeralRemoverIndex] == 'x' &&
|
||||
Char.IsDigit(Type[numeralRemoverIndex - 1]))
|
||||
{
|
||||
Type = Type.Substring(0, numeralRemoverIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
numeralRemoverIndex--;
|
||||
}
|
||||
|
||||
Dimensions = dimensions.ToArray();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadNameAndArraySize
|
||||
private void ReadNameAndArraySize(ParseTextWalker walker)
|
||||
{
|
||||
string currentText = walker.Text;
|
||||
|
||||
int nameIndex = 0;
|
||||
while (nameIndex < currentText.Length)
|
||||
{
|
||||
char currentChar = currentText[nameIndex];
|
||||
if (currentChar == ' ' ||
|
||||
currentChar == ':' ||
|
||||
currentChar == '<' ||
|
||||
currentChar == ';' ||
|
||||
currentChar == '=')
|
||||
{
|
||||
break;
|
||||
}
|
||||
Name += currentChar;
|
||||
nameIndex++;
|
||||
}
|
||||
|
||||
if (Name.Contains("["))
|
||||
{
|
||||
Name = Name.TrimEnd(']');
|
||||
int openBraceIndex = Name.IndexOf('[');
|
||||
ArraySize = int.Parse(Name.Substring(openBraceIndex + 1));
|
||||
Name = Name.Substring(0, openBraceIndex);
|
||||
}
|
||||
|
||||
walker.Seek(nameIndex);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseExtraParameters
|
||||
private void ParseExtraParameters(ParseTextWalker walker)
|
||||
{
|
||||
string currentText = walker.Text;
|
||||
|
||||
char currentChar = currentText[0];
|
||||
if (currentChar == '<' ||
|
||||
currentChar == ';' ||
|
||||
currentChar == '=')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int afterColonIndex = 1;
|
||||
string extraText = currentText.Substring(afterColonIndex);
|
||||
|
||||
if (extraText.Trim().StartsWith("packoffset"))
|
||||
{
|
||||
int endIndex = extraText.IndexOf(')') + 1;
|
||||
Packoffset = extraText.Substring(0, endIndex).Trim();
|
||||
walker.Seek(endIndex + afterColonIndex);
|
||||
}
|
||||
else if (extraText.Trim().StartsWith("register"))
|
||||
{
|
||||
int endIndex = extraText.IndexOf(')') + 1;
|
||||
Register = extraText.Substring(0, endIndex).Trim();
|
||||
walker.Seek(endIndex + afterColonIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
int beforeLength = extraText.Length;
|
||||
extraText = extraText.TrimStart(' ');
|
||||
int lowestEndIndex = -1;
|
||||
foreach (char semanticEndChar in SemanticEndChars)
|
||||
{
|
||||
int indexOfEndChar = extraText.IndexOf(semanticEndChar);
|
||||
if (indexOfEndChar != -1 &&
|
||||
(lowestEndIndex == -1 ||
|
||||
indexOfEndChar < lowestEndIndex))
|
||||
{
|
||||
lowestEndIndex = indexOfEndChar;
|
||||
}
|
||||
}
|
||||
|
||||
Semantic = extraText.Substring(0, lowestEndIndex).Trim();
|
||||
walker.Seek(lowestEndIndex + afterColonIndex + (beforeLength - extraText.Length));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseAnnotations
|
||||
private void ParseAnnotations(ParseTextWalker walker)
|
||||
{
|
||||
string currentText = walker.Text;
|
||||
if (currentText[0] != '<')
|
||||
return;
|
||||
|
||||
int endIndex = currentText.IndexOf('>');
|
||||
Annotations = currentText.Substring(1, endIndex - 1);
|
||||
|
||||
walker.Seek(endIndex + 1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ReadInitialValue
|
||||
private void ReadInitialValue(ParseTextWalker walker)
|
||||
{
|
||||
string text = walker.Text;
|
||||
|
||||
if (text[0] == '<' ||
|
||||
text[0] == ';' ||
|
||||
text[0] == ':')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int valueEndIndex = text.IndexOf(';', 1);
|
||||
InitialValue = text.Substring(1, valueEndIndex - 1);
|
||||
InitialValue = InitialValue.Trim();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetTypeModifiers
|
||||
public static string[] GetTypeModifiers(ParseTextWalker walker)
|
||||
{
|
||||
if (walker == null)
|
||||
return new string[0];
|
||||
|
||||
if (String.IsNullOrEmpty(walker.Text))
|
||||
return new string[0];
|
||||
|
||||
string currentText = walker.Text;
|
||||
|
||||
int firstSpaceIndex = currentText.IndexOf(' ');
|
||||
if (firstSpaceIndex == -1)
|
||||
{
|
||||
return AllTypeModifiers.Contains(currentText) ?
|
||||
new string[] { currentText } :
|
||||
new string[0];
|
||||
}
|
||||
|
||||
var result = new List<string>();
|
||||
while (firstSpaceIndex != -1)
|
||||
{
|
||||
string currentElement = currentText.Substring(0, firstSpaceIndex);
|
||||
|
||||
if (AllTypeModifiers.Contains(currentElement))
|
||||
{
|
||||
result.Add(currentElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
walker.Seek(firstSpaceIndex + 1);
|
||||
currentText = walker.Text;
|
||||
firstSpaceIndex = currentText.IndexOf(' ');
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IsVariableFollowing
|
||||
public static bool IsVariableFollowing(ParseTextWalker walker)
|
||||
{
|
||||
string currentText = walker.Text;
|
||||
|
||||
foreach (string typeName in AllTypeNames)
|
||||
{
|
||||
if (currentText.StartsWith(typeName))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TryParse
|
||||
public static Variable TryParse(ParseTextWalker walker)
|
||||
{
|
||||
string[] typeModifiersFound = GetTypeModifiers(walker);
|
||||
|
||||
if (IsVariableFollowing(walker))
|
||||
{
|
||||
return new Variable(walker)
|
||||
{
|
||||
TypeModifiers = typeModifiersFound,
|
||||
};
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
string result = "";
|
||||
result = AddTypeModifiersToString(result);
|
||||
result += Type;
|
||||
result = AddDimensionsToString(result);
|
||||
result += " " + Name;
|
||||
|
||||
if (ArraySize > 0)
|
||||
{
|
||||
result += "[" + ArraySize + "]";
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(Semantic) == false)
|
||||
{
|
||||
result += " : " + Semantic;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(Packoffset) == false)
|
||||
{
|
||||
result += " : " + Packoffset;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(Register) == false)
|
||||
{
|
||||
result += " : " + Register;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(Annotations) == false)
|
||||
{
|
||||
result += " <" + Annotations + ">";
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(InitialValue) == false)
|
||||
{
|
||||
result += " = " + InitialValue;
|
||||
}
|
||||
|
||||
result += ";";
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddTypeModifiersToString
|
||||
private string AddTypeModifiersToString(string text)
|
||||
{
|
||||
foreach (string modifier in TypeModifiers)
|
||||
{
|
||||
text += modifier + " ";
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddDimensionsToString
|
||||
private string AddDimensionsToString(string text)
|
||||
{
|
||||
for (int index = 0; index < Dimensions.Length; index++)
|
||||
{
|
||||
text += (index > 0 ? "x" : "") + Dimensions[index];
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class BufferTests
|
||||
{
|
||||
#region TestParseIfBuffer
|
||||
[Test]
|
||||
public static void TestParseIfBuffer()
|
||||
{
|
||||
var text = new ParseTextWalker("Buffer<float4> g_Buffer;");
|
||||
var result = EffectBuffer.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("g_Buffer", result.Name);
|
||||
Assert.AreEqual("float4", result.Type);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfBufferWithoutCode
|
||||
[Test]
|
||||
public static void TestParseIfBufferWithoutCode()
|
||||
{
|
||||
var text = new ParseTextWalker("testtest");
|
||||
var result = EffectBuffer.TryParse(text);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToString
|
||||
[Test]
|
||||
public static void TestToString()
|
||||
{
|
||||
string text = "Buffer<float4> g_Buffer;";
|
||||
var walker = new ParseTextWalker(text);
|
||||
var result = EffectBuffer.TryParse(walker);
|
||||
|
||||
Assert.AreEqual(text, result.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class CommentRemoverTests
|
||||
{
|
||||
#region TestEmptySource
|
||||
[Test]
|
||||
public static void TestEmptySource()
|
||||
{
|
||||
Assert.AreEqual(CommentRemover.Remove(null), null);
|
||||
Assert.AreEqual(CommentRemover.Remove(""), "");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestMultilineComment
|
||||
[Test]
|
||||
public static void TestMultilineComment()
|
||||
{
|
||||
string source = "/* comment line */";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "");
|
||||
source = "/* comment line\nline two*/";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestCascadedMultilineComments
|
||||
[Test]
|
||||
public static void TestCascadedMultilineComments()
|
||||
{
|
||||
string source = "/* /*comment line */";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "");
|
||||
source = "/* comment /* //line\nline two*/";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestMultilineCommentWithCodeInFront
|
||||
[Test]
|
||||
public static void TestMultilineCommentWithCodeInFront()
|
||||
{
|
||||
string source = "aaa/*comment*/";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "aaa");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestCommentedOutMultilineComment
|
||||
[Test]
|
||||
public static void TestCommentedOutMultilineComment()
|
||||
{
|
||||
string source = "//*comment\n*/";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "*/");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestMultipleMultilineComments
|
||||
[Test]
|
||||
public static void TestMultipleMultilineComments()
|
||||
{
|
||||
string source = "/*blub*/aaa/*comment*/";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "aaa");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestMultilineCommentWithCodeAfter
|
||||
[Test]
|
||||
public static void TestMultilineCommentWithCodeAfter()
|
||||
{
|
||||
string source = "/*comment*/bbb";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "bbb");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestSingleLineComment
|
||||
[Test]
|
||||
public static void TestSingleLineComment()
|
||||
{
|
||||
string source = "// comment line";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "");
|
||||
source = "// comment line\n//test";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestSingleLineCommentWithCode
|
||||
[Test]
|
||||
public static void TestSingleLineCommentWithCode()
|
||||
{
|
||||
string source =
|
||||
@"// comment line
|
||||
float4x4 matrix;";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "float4x4 matrix;");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestSingleLineCommentWithCodeInFront
|
||||
[Test]
|
||||
public static void TestSingleLineCommentWithCodeInFront()
|
||||
{
|
||||
string source = "float value;// comment line";
|
||||
Assert.AreEqual(CommentRemover.Remove(source), "float value;");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestSplitLines
|
||||
[Test]
|
||||
public static void TestSplitLines()
|
||||
{
|
||||
string source = "aa\nbbb";
|
||||
Assert.AreEqual(CommentRemover.SplitLines(source), new string[] { "aa", "bbb" });
|
||||
source = @"aa
|
||||
bbb";
|
||||
Assert.AreEqual(CommentRemover.SplitLines(source), new string[] { "aa", "bbb" });
|
||||
source = "aa\n\rbbb";
|
||||
Assert.AreEqual(CommentRemover.SplitLines(source), new string[] { "aa", "bbb" });
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestMergeLines
|
||||
[Test]
|
||||
public static void TestMergeLines()
|
||||
{
|
||||
string[] lines = new string[] { "aa", "bbb" };
|
||||
Assert.AreEqual(CommentRemover.MergeLines(lines), "aa\nbbb");
|
||||
lines = new string[] { "aa", "", null, "bbb" };
|
||||
Assert.AreEqual(CommentRemover.MergeLines(lines), "aa\nbbb");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F9177943-1590-49AE-987D-D6FAE30D96DD}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>HLSLParserTests</RootNamespace>
|
||||
<AssemblyName>HLSLParserTests</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</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="nunit.framework">
|
||||
<HintPath>..\..\..\lib\NUnit-2.6.1\bin\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CommentRemoverTests.cs" />
|
||||
<Compile Include="HlslTestFile.cs" />
|
||||
<Compile Include="BufferTests.cs" />
|
||||
<Compile Include="MethodTests.cs" />
|
||||
<Compile Include="SamplerTests.cs" />
|
||||
<Compile Include="PassTests.cs" />
|
||||
<Compile Include="ParserTests.cs" />
|
||||
<Compile Include="ParseTextWalkerTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="StructureTests.cs" />
|
||||
<Compile Include="TechniqueTests.cs" />
|
||||
<Compile Include="TypeDefTests.cs" />
|
||||
<Compile Include="VariableTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HLSLParser\HLSLParser.csproj">
|
||||
<Project>{9588B0C3-E03A-4C71-89A4-2C8685D426F1}</Project>
|
||||
<Name>HLSLParser</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\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>
|
@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class HlslTestFile
|
||||
{
|
||||
public const string Source =
|
||||
@"// This file is part of the ANX.Framework created by the
|
||||
// ""ANX.Framework developer group"" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
uniform extern float4x4 MatrixTransform;
|
||||
|
||||
Texture2D<float4> Texture : register(t0);
|
||||
sampler TextureSampler : register(s0);
|
||||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float4 col : COLOR;
|
||||
float2 tex : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float4 col : COLOR;
|
||||
float2 tex : TEXCOORD0;
|
||||
};
|
||||
|
||||
PixelShaderInput SpriteVertexShader( VertexShaderInput input )
|
||||
{
|
||||
PixelShaderInput output = (PixelShaderInput)0;
|
||||
|
||||
output.pos = mul(input.pos, MatrixTransform);
|
||||
output.col = input.col;
|
||||
output.tex = input.tex;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 SpritePixelShader( PixelShaderInput input ) : SV_Target
|
||||
{
|
||||
return Texture.Sample(TextureSampler, input.tex) * input.col;
|
||||
}
|
||||
|
||||
technique10 SpriteTechnique
|
||||
{
|
||||
pass SpriteColorPass
|
||||
{
|
||||
SetGeometryShader( 0 );
|
||||
SetVertexShader( CompileShader( vs_4_0, SpriteVertexShader() ) );
|
||||
SetPixelShader( CompileShader( ps_4_0, SpritePixelShader() ) );
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
public static string WriteTestFile()
|
||||
{
|
||||
string testFilepath = Path.GetTempFileName() + ".fx";
|
||||
File.WriteAllText(testFilepath, HlslTestFile.Source);
|
||||
return testFilepath;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class MethodTests
|
||||
{
|
||||
#region Constants
|
||||
private const string TestMethod =
|
||||
@"float4 PSPointSprite(PSSceneIn input) : SV_Target
|
||||
{
|
||||
return g_txDiffuse.Sample(g_samLinear, input.tex) * input.color;
|
||||
}";
|
||||
|
||||
private const string TestMethodWithBodyBraces =
|
||||
@"float4 PSPointSprite(PSSceneIn input) : SV_Target
|
||||
{
|
||||
if(true)
|
||||
{
|
||||
return g_txDiffuse.Sample(g_samLinear, input.tex) * input.color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return g_txDiffuse.Sample(g_samLinear, input.tex);
|
||||
}
|
||||
}";
|
||||
|
||||
private const string TestMethodInline =
|
||||
@"inline float4 PSPointSprite(PSSceneIn input) : SV_Target
|
||||
{
|
||||
return g_txDiffuse.Sample(g_samLinear, input.tex) * input.color;
|
||||
}";
|
||||
#endregion
|
||||
|
||||
#region TestParseIfMethod
|
||||
[Test]
|
||||
public static void TestParseIfMethod()
|
||||
{
|
||||
var text = new ParseTextWalker(TestMethod);
|
||||
var result = Method.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("PSPointSprite", result.Name);
|
||||
Assert.AreEqual("float4", result.ReturnType);
|
||||
Assert.AreEqual("PSSceneIn input", result.Arguments);
|
||||
Assert.AreEqual("SV_Target", result.Semantic);
|
||||
Assert.AreEqual(
|
||||
"return g_txDiffuse.Sample(g_samLinear, input.tex) * input.color;",
|
||||
result.Body);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfMethodWithBodyBraces
|
||||
[Test]
|
||||
public static void TestParseIfMethodWithBodyBraces()
|
||||
{
|
||||
var text = new ParseTextWalker(TestMethodWithBodyBraces);
|
||||
var result = Method.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("PSPointSprite", result.Name);
|
||||
Assert.AreEqual("float4", result.ReturnType);
|
||||
|
||||
string expected =
|
||||
@"if(true)
|
||||
{
|
||||
return g_txDiffuse.Sample(g_samLinear, input.tex) * input.color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return g_txDiffuse.Sample(g_samLinear, input.tex);
|
||||
}";
|
||||
|
||||
Assert.AreEqual(expected, result.Body);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfMethodInline
|
||||
[Test]
|
||||
public static void TestParseIfMethodInline()
|
||||
{
|
||||
var text = new ParseTextWalker(TestMethodInline);
|
||||
var result = Method.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("PSPointSprite", result.Name);
|
||||
Assert.AreEqual("float4", result.ReturnType);
|
||||
Assert.AreEqual("inline", result.StorageClass);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfMethodWithVariable
|
||||
[Test]
|
||||
public static void TestParseIfMethodWithVariable()
|
||||
{
|
||||
var text = new ParseTextWalker("float4 value;");
|
||||
var result = Method.TryParse(text);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfMethodWithoutCode
|
||||
[Test]
|
||||
public static void TestParseIfMethodWithoutCode()
|
||||
{
|
||||
var text = new ParseTextWalker("testtest");
|
||||
var result = Method.TryParse(text);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToString
|
||||
[Test]
|
||||
public static void TestToString()
|
||||
{
|
||||
var text = new ParseTextWalker(TestMethod);
|
||||
var result = Method.TryParse(text);
|
||||
|
||||
Assert.AreEqual(TestMethod.Replace("\r", ""), result.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToStringWithInline
|
||||
[Test]
|
||||
public static void TestToStringWithInline()
|
||||
{
|
||||
var text = new ParseTextWalker("inline " + TestMethod);
|
||||
var result = Method.TryParse(text);
|
||||
|
||||
Assert.AreEqual("inline " + TestMethod.Replace("\r", ""), result.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class ParseTextWalkerTests
|
||||
{
|
||||
[Test]
|
||||
public static void TestCreateTextWalker()
|
||||
{
|
||||
string text = "Testtext";
|
||||
ParseTextWalker walker = new ParseTextWalker(text);
|
||||
|
||||
Assert.AreEqual(walker.Text, text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestSeeking()
|
||||
{
|
||||
string text = "Testtext";
|
||||
ParseTextWalker walker = new ParseTextWalker(text);
|
||||
|
||||
walker.Seek(4);
|
||||
Assert.AreEqual(walker.Text, "text");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using HLSLParser;
|
||||
using NUnit.Framework;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class ParserTests
|
||||
{
|
||||
#region TestLoadThrowsOnEmptyFilepath
|
||||
[Test]
|
||||
public static void TestLoadThrowsOnEmptyFilepath()
|
||||
{
|
||||
Assert.Throws(typeof(ArgumentException), delegate
|
||||
{
|
||||
Parser.LoadFromFile("");
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestLoadThrowsOnMissingFile
|
||||
[Test]
|
||||
public static void TestLoadThrowsOnMissingFile()
|
||||
{
|
||||
Assert.Throws(typeof(FileNotFoundException), delegate
|
||||
{
|
||||
Parser.LoadFromFile("testfile.fx");
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestWriteTestFile
|
||||
[Test]
|
||||
public static void TestWriteTestFile()
|
||||
{
|
||||
string testFilepath = HlslTestFile.WriteTestFile();
|
||||
Assert.True(File.Exists(testFilepath));
|
||||
File.Delete(testFilepath);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestLoadFile
|
||||
[Test]
|
||||
public static void TestLoadFile()
|
||||
{
|
||||
string testFilepath = HlslTestFile.WriteTestFile();
|
||||
Parser parser = Parser.LoadFromFile(testFilepath);
|
||||
|
||||
Assert.NotNull(parser.Effect);
|
||||
Assert.NotNull(parser.Effect.Source);
|
||||
Assert.AreNotEqual(parser.Effect.Source, "");
|
||||
|
||||
File.Delete(testFilepath);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseFile
|
||||
[Test]
|
||||
public static void TestParseFile()
|
||||
{
|
||||
string testFilepath = HlslTestFile.WriteTestFile();
|
||||
Parser parser = Parser.LoadFromFile(testFilepath);
|
||||
|
||||
parser.Parse();
|
||||
|
||||
Assert.AreEqual(2, parser.Effect.Variables.Count);
|
||||
Assert.AreEqual(1, parser.Effect.Techniques.Count);
|
||||
Assert.AreEqual(2, parser.Effect.Methods.Count);
|
||||
Assert.AreEqual(2, parser.Effect.Structures.Count);
|
||||
Assert.AreEqual(1, parser.Effect.Samplers.Count);
|
||||
Assert.AreEqual(0, parser.Effect.TypeDefs.Count);
|
||||
Assert.AreEqual(0, parser.Effect.Buffers.Count);
|
||||
|
||||
File.Delete(testFilepath);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseFromSource
|
||||
[Test]
|
||||
public static void TestParseFromSource()
|
||||
{
|
||||
Parser parser = Parser.LoadFromSource(HlslTestFile.Source);
|
||||
|
||||
parser.Parse();
|
||||
|
||||
Assert.AreEqual(2, parser.Effect.Variables.Count);
|
||||
Assert.AreEqual(1, parser.Effect.Techniques.Count);
|
||||
Assert.AreEqual(2, parser.Effect.Methods.Count);
|
||||
Assert.AreEqual(2, parser.Effect.Structures.Count);
|
||||
Assert.AreEqual(1, parser.Effect.Samplers.Count);
|
||||
Assert.AreEqual(0, parser.Effect.TypeDefs.Count);
|
||||
Assert.AreEqual(0, parser.Effect.Buffers.Count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseWithTypeDef
|
||||
[Test]
|
||||
public static void TestParseWithTypeDef()
|
||||
{
|
||||
Parser parser = Parser.LoadFromSource("typedef matrix <bool, 1, 1> bool1x1;");
|
||||
|
||||
parser.Parse();
|
||||
|
||||
Assert.AreEqual(1, parser.Effect.TypeDefs.Count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseWithBuffer
|
||||
[Test]
|
||||
public static void TestParseWithBuffer()
|
||||
{
|
||||
Parser parser = Parser.LoadFromSource("Buffer<float4> g_Buffer;");
|
||||
|
||||
parser.Parse();
|
||||
|
||||
Assert.AreEqual(1, parser.Effect.Buffers.Count);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class PassTests
|
||||
{
|
||||
#region Constants
|
||||
private const string TestPass =
|
||||
@"pass P0
|
||||
{
|
||||
SetVertexShader( CompileShader( vs_4_0, VS() ) );
|
||||
SetGeometryShader( NULL );
|
||||
SetPixelShader( CompileShader( ps_4_0, PS() ) );
|
||||
}";
|
||||
|
||||
private const string TestPassDx9 =
|
||||
@"pass P0
|
||||
{
|
||||
VertexShader = compile vs_2_0 RenderSceneVS( 1, true, true );
|
||||
PixelShader = compile ps_2_0 RenderScenePS( true );
|
||||
}";
|
||||
#endregion
|
||||
|
||||
#region ParseIfPass
|
||||
[Test]
|
||||
public static void ParseIfPass()
|
||||
{
|
||||
var text = new ParseTextWalker(TestPass);
|
||||
var result = Pass.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("P0", result.Name);
|
||||
Assert.AreEqual("VS()", result.VertexShader);
|
||||
Assert.AreEqual("vs_4_0", result.VertexShaderProfile);
|
||||
Assert.AreEqual("PS()", result.PixelShader);
|
||||
Assert.AreEqual("ps_4_0", result.PixelShaderProfile);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseIfPassDx9
|
||||
[Test]
|
||||
public static void ParseIfPassDx9()
|
||||
{
|
||||
var text = new ParseTextWalker(TestPassDx9);
|
||||
var result = Pass.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("P0", result.Name);
|
||||
Assert.AreEqual("RenderSceneVS(1, true, true)", result.VertexShader);
|
||||
Assert.AreEqual("vs_2_0", result.VertexShaderProfile);
|
||||
Assert.AreEqual("RenderScenePS(true)", result.PixelShader);
|
||||
Assert.AreEqual("ps_2_0", result.PixelShaderProfile);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfTypeDefWithoutCode
|
||||
[Test]
|
||||
public static void TestParseIfTypeDefWithoutCode()
|
||||
{
|
||||
var text = new ParseTextWalker("testtest");
|
||||
var result = Pass.TryParse(text);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToString
|
||||
[Test]
|
||||
public static void TestToString()
|
||||
{
|
||||
var text = new ParseTextWalker(TestPass);
|
||||
var result = Pass.TryParse(text);
|
||||
|
||||
string expected =
|
||||
@"pass P0
|
||||
{
|
||||
SetVertexShader(CompileShader(vs_4_0, VS()));
|
||||
SetGeometryShader(NULL);
|
||||
SetPixelShader(CompileShader(ps_4_0, PS()));
|
||||
}";
|
||||
|
||||
Assert.AreEqual(expected.Replace("\r", ""), result.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("HLSLParserTests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("ANX Developer Team")]
|
||||
[assembly: AssemblyProduct("HLSLParserTests")]
|
||||
[assembly: AssemblyCopyright("Copyright © ANX Developer Team 2012")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("4222de4b-ae10-4ae3-8e2e-8adce5ed6ac8")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
@ -1,126 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class SamplerTests
|
||||
{
|
||||
#region Constants
|
||||
private const string TestSampler =
|
||||
@"SamplerState MeshTextureSampler
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = Wrap;
|
||||
AddressV = Wrap;
|
||||
};";
|
||||
|
||||
private const string TestSamplerDx9 =
|
||||
@"sampler MeshTextureSampler =
|
||||
sampler_state
|
||||
{
|
||||
Texture = <g_MeshTexture>;
|
||||
MipFilter = LINEAR;
|
||||
MinFilter = LINEAR;
|
||||
MagFilter = LINEAR;
|
||||
};";
|
||||
#endregion
|
||||
|
||||
#region ParseIfPass
|
||||
[Test]
|
||||
public static void ParseIfPass()
|
||||
{
|
||||
var text = new ParseTextWalker(TestSampler);
|
||||
var result = Sampler.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("MeshTextureSampler", result.Name);
|
||||
Assert.AreEqual("SamplerState", result.Type);
|
||||
|
||||
Assert.AreEqual("Filter", result.States[0].Key);
|
||||
Assert.AreEqual("MIN_MAG_MIP_LINEAR", result.States[0].Value);
|
||||
Assert.AreEqual("AddressU", result.States[1].Key);
|
||||
Assert.AreEqual("Wrap", result.States[1].Value);
|
||||
Assert.AreEqual("AddressV", result.States[2].Key);
|
||||
Assert.AreEqual("Wrap", result.States[2].Value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseIfPassDx9
|
||||
[Test]
|
||||
public static void ParseIfPassDx9()
|
||||
{
|
||||
var text = new ParseTextWalker(TestSamplerDx9);
|
||||
var result = Sampler.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("MeshTextureSampler", result.Name);
|
||||
Assert.AreEqual("sampler", result.Type);
|
||||
|
||||
Assert.AreEqual("Texture", result.States[0].Key);
|
||||
Assert.AreEqual("<g_MeshTexture>", result.States[0].Value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseIfPassHasRegister
|
||||
[Test]
|
||||
public static void ParseIfPassHasRegister()
|
||||
{
|
||||
var text = new ParseTextWalker("sampler TextureSampler : register(s0);");
|
||||
var result = Sampler.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("TextureSampler", result.Name);
|
||||
Assert.AreEqual("sampler", result.Type);
|
||||
Assert.AreEqual("register(s0)", result.Register);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfTypeDefWithoutCode
|
||||
[Test]
|
||||
public static void TestParseIfTypeDefWithoutCode()
|
||||
{
|
||||
var text = new ParseTextWalker("testtest");
|
||||
var result = Sampler.TryParse(text);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToString
|
||||
[Test]
|
||||
public static void TestToString()
|
||||
{
|
||||
var text = new ParseTextWalker(TestSampler);
|
||||
var result = Sampler.TryParse(text);
|
||||
|
||||
string expected =
|
||||
@"SamplerState MeshTextureSampler
|
||||
{
|
||||
Filter = MIN_MAG_MIP_LINEAR;
|
||||
AddressU = Wrap;
|
||||
AddressV = Wrap;
|
||||
};";
|
||||
|
||||
Assert.AreEqual(expected.Replace("\r", ""), result.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToStringWithRegister
|
||||
[Test]
|
||||
public static void TestToStringWithRegister()
|
||||
{
|
||||
var text = new ParseTextWalker("sampler TextureSampler : register(s0);");
|
||||
var result = Sampler.TryParse(text);
|
||||
|
||||
string expected = "sampler TextureSampler : register(s0);";
|
||||
|
||||
Assert.AreEqual(expected, result.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class StructureTests
|
||||
{
|
||||
#region Constants
|
||||
private const string TestStructure =
|
||||
@"struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float4 col : COLOR;
|
||||
float2 tex : TEXCOORD0;
|
||||
};";
|
||||
#endregion
|
||||
|
||||
#region TestParseIfStructure
|
||||
[Test]
|
||||
public static void TestParseIfStructure()
|
||||
{
|
||||
var text = new ParseTextWalker(TestStructure);
|
||||
var result = Structure.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("PixelShaderInput", result.Name);
|
||||
Assert.AreEqual(3, result.Variables.Count);
|
||||
Assert.AreEqual("", text.Text);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfStructureWithoutCode
|
||||
[Test]
|
||||
public static void TestParseIfStructureWithoutCode()
|
||||
{
|
||||
var text = new ParseTextWalker("testtest");
|
||||
var result = Structure.TryParse(text);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToString
|
||||
[Test]
|
||||
public static void TestToString()
|
||||
{
|
||||
var text = new ParseTextWalker(TestStructure);
|
||||
var result = Structure.TryParse(text);
|
||||
|
||||
Assert.AreEqual(TestStructure.Replace("\r", ""), result.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class TechniqueTests
|
||||
{
|
||||
#region Constants
|
||||
private const string TestTechnique =
|
||||
@"technique10 Render
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
SetVertexShader( CompileShader( vs_4_0, VS() ) );
|
||||
SetGeometryShader( NULL );
|
||||
SetPixelShader( CompileShader( ps_4_0, PS() ) );
|
||||
}
|
||||
}";
|
||||
|
||||
private const string TestTechniqueMultipass =
|
||||
@"technique Render
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
SetVertexShader( CompileShader( vs_4_0, VS() ) );
|
||||
SetGeometryShader( NULL );
|
||||
SetPixelShader( CompileShader( ps_4_0, PS() ) );
|
||||
}
|
||||
|
||||
pass P1
|
||||
{
|
||||
SetVertexShader( CompileShader( vs_4_0, VS() ) );
|
||||
SetGeometryShader( NULL );
|
||||
SetPixelShader( CompileShader( ps_4_0, PS() ) );
|
||||
}
|
||||
}";
|
||||
#endregion
|
||||
|
||||
#region ParseIfTechnique
|
||||
[Test]
|
||||
public static void ParseIfTechnique()
|
||||
{
|
||||
var text = new ParseTextWalker(TestTechnique);
|
||||
var result = Technique.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("Render", result.Name);
|
||||
Assert.AreEqual(1, result.Passes.Count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfTypeDefWithoutCode
|
||||
[Test]
|
||||
public static void TestParseIfTypeDefWithoutCode()
|
||||
{
|
||||
var text = new ParseTextWalker("testtest");
|
||||
var result = Technique.TryParse(text);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseTechniqueWithMultiplePasses
|
||||
[Test]
|
||||
public static void ParseTechniqueWithMultiplePasses()
|
||||
{
|
||||
var text = new ParseTextWalker(TestTechniqueMultipass);
|
||||
var result = Technique.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("Render", result.Name);
|
||||
Assert.AreEqual(2, result.Passes.Count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToString
|
||||
[Test]
|
||||
public static void TestToString()
|
||||
{
|
||||
var text = new ParseTextWalker(TestTechnique);
|
||||
var result = Technique.TryParse(text);
|
||||
|
||||
string expected =
|
||||
@"technique10 Render
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
SetVertexShader(CompileShader(vs_4_0, VS()));
|
||||
SetGeometryShader(NULL);
|
||||
SetPixelShader(CompileShader(ps_4_0, PS()));
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.AreEqual(expected.Replace("\r", ""), result.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class TypeDefTests
|
||||
{
|
||||
#region TestParseIfTypeDef
|
||||
[Test]
|
||||
public static void TestParseIfTypeDef()
|
||||
{
|
||||
var text = new ParseTextWalker("typedef matrix <bool, 1, 1> bool1x1;");
|
||||
var result = TypeDef.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("matrix <bool, 1, 1> bool1x1", result.Value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfTypeDefWithoutCode
|
||||
[Test]
|
||||
public static void TestParseIfTypeDefWithoutCode()
|
||||
{
|
||||
var text = new ParseTextWalker("testtest");
|
||||
var result = TypeDef.TryParse(text);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToString
|
||||
[Test]
|
||||
public static void TestToString()
|
||||
{
|
||||
string text = "typedef matrix <bool, 1, 1> bool1x1;";
|
||||
var walker = new ParseTextWalker(text);
|
||||
var result = TypeDef.TryParse(walker);
|
||||
|
||||
Assert.AreEqual(text, result.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,402 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using HLSLParser;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace HLSLParserTests
|
||||
{
|
||||
public static class VariableTests
|
||||
{
|
||||
#region TestGetTypeModifiersFromEmptyString
|
||||
[Test]
|
||||
public static void TestGetTypeModifiersFromEmptyString()
|
||||
{
|
||||
Assert.AreEqual(Variable.GetTypeModifiers(null), new string[0]);
|
||||
Assert.AreEqual(Variable.GetTypeModifiers(new ParseTextWalker("")),
|
||||
new string[0]);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestGetTypeModifiersStringWithoutElement
|
||||
[Test]
|
||||
public static void TestGetTypeModifiersStringWithoutElement()
|
||||
{
|
||||
var text = new ParseTextWalker("aaa");
|
||||
string[] result = Variable.GetTypeModifiers(text);
|
||||
Assert.AreEqual(0, result.Length);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestGetTypeModifiersFromStringWithoutSpace
|
||||
[Test]
|
||||
public static void TestGetTypeModifiersFromStringWithoutSpace()
|
||||
{
|
||||
var text = new ParseTextWalker("uniform");
|
||||
string[] result = Variable.GetTypeModifiers(text);
|
||||
Assert.AreEqual(1, result.Length);
|
||||
Assert.AreEqual("uniform", result[0]);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestGetStorageClassesFrom
|
||||
[Test]
|
||||
public static void TestGetStorageClassesFrom()
|
||||
{
|
||||
var text = new ParseTextWalker("uniform extern float4x4 MatrixTransform;");
|
||||
string[] result = Variable.GetTypeModifiers(text);
|
||||
Assert.AreEqual(2, result.Length);
|
||||
Assert.AreEqual("uniform", result[0]);
|
||||
Assert.AreEqual("extern", result[1]);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestIsVariableFollowing
|
||||
[Test]
|
||||
public static void TestIsVariableFollowing()
|
||||
{
|
||||
var text = new ParseTextWalker("int value;");
|
||||
bool result = Variable.IsVariableFollowing(text);
|
||||
Assert.True(result);
|
||||
|
||||
text = new ParseTextWalker("int4x4 value;");
|
||||
result = Variable.IsVariableFollowing(text);
|
||||
Assert.True(result);
|
||||
|
||||
text = new ParseTextWalker("const int value;");
|
||||
result = Variable.IsVariableFollowing(text);
|
||||
Assert.False(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfVariable
|
||||
[Test]
|
||||
public static void TestParseIfVariable()
|
||||
{
|
||||
var text = new ParseTextWalker("int value;");
|
||||
var result = Variable.TryParse(text);
|
||||
Assert.NotNull(result);
|
||||
|
||||
text = new ParseTextWalker("uniform const int value;");
|
||||
result = Variable.TryParse(text);
|
||||
Assert.NotNull(result);
|
||||
|
||||
text = new ParseTextWalker("uniform extern float4x4 MatrixTransform;");
|
||||
result = Variable.TryParse(text);
|
||||
Assert.NotNull(result);
|
||||
|
||||
text = new ParseTextWalker("PS_IN VS(VS_IN in) { }");
|
||||
result = Variable.TryParse(text);
|
||||
Assert.Null(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseTwoVariables
|
||||
[Test]
|
||||
public static void TestParseTwoVariables()
|
||||
{
|
||||
string source =
|
||||
@"uniform extern float4x4 MatrixTransform;
|
||||
|
||||
Texture2D<float4> Texture : register(t0);";
|
||||
|
||||
var text = new ParseTextWalker(source);
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("uniform extern float4x4 MatrixTransform;", result.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseIfVariableWithGenericTexture2D
|
||||
[Test]
|
||||
public static void TestParseIfVariableWithGenericTexture2D()
|
||||
{
|
||||
string variableSource = "Texture2D <float4> Texture : register(t0);";
|
||||
var text = new ParseTextWalker(variableSource);
|
||||
var result = Variable.TryParse(text);
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("Texture2D<float4>", result.Type);
|
||||
Assert.AreEqual("Texture", result.Name);
|
||||
Assert.AreEqual("register(t0)", result.Register);
|
||||
Assert.AreEqual("Texture2D<float4> Texture : register(t0);", result.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestfloatVariableParsing
|
||||
[Test]
|
||||
public static void TestfloatVariableParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("uniform const float value;");
|
||||
var result = Variable.TryParse(text);
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(2, result.TypeModifiers.Length);
|
||||
Assert.AreEqual("float", result.Type);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestVectorVariableParsing
|
||||
[Test]
|
||||
public static void TestVectorVariableParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("vector<float, 1> value;");
|
||||
var result = Variable.TryParse(text);
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("float", result.Type);
|
||||
Assert.AreEqual(1, result.Dimensions.Length);
|
||||
Assert.AreEqual(1, result.Dimensions[0]);
|
||||
|
||||
text = new ParseTextWalker("float4 value;");
|
||||
result = Variable.TryParse(text);
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("float", result.Type);
|
||||
Assert.AreEqual(1, result.Dimensions.Length);
|
||||
Assert.AreEqual(4, result.Dimensions[0]);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestMatrixVariableParsing
|
||||
[Test]
|
||||
public static void TestMatrixVariableParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("matrix<float, 1, 3> value;");
|
||||
var result = Variable.TryParse(text);
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("float", result.Type);
|
||||
Assert.AreEqual(2, result.Dimensions.Length);
|
||||
Assert.AreEqual(1, result.Dimensions[0]);
|
||||
Assert.AreEqual(3, result.Dimensions[1]);
|
||||
|
||||
text = new ParseTextWalker("int4x4 value;");
|
||||
result = Variable.TryParse(text);
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("int", result.Type);
|
||||
Assert.AreEqual(2, result.Dimensions.Length);
|
||||
Assert.AreEqual(4, result.Dimensions[0]);
|
||||
Assert.AreEqual(4, result.Dimensions[1]);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestNameParsing
|
||||
[Test]
|
||||
public static void TestNameParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("matrix<float, 1, 3> value;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestArrayParsing
|
||||
[Test]
|
||||
public static void TestArrayParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("int value[15];");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual(15, result.ArraySize);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestInitialValueParsing
|
||||
[Test]
|
||||
public static void TestInitialValueParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("int value = 4;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("4", result.InitialValue);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestInitialValueParsingWithoutValueText
|
||||
[Test]
|
||||
public static void TestInitialValueParsingWithoutValueText()
|
||||
{
|
||||
var text = new ParseTextWalker("int value;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual(null, result.InitialValue);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestAnnotationsParsing
|
||||
[Test]
|
||||
public static void TestAnnotationsParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("int value<float y=1.3;>;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("float y=1.3;", result.Annotations);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestAnnotationsParsingWithInitialValue
|
||||
[Test]
|
||||
public static void TestAnnotationsParsingWithInitialValue()
|
||||
{
|
||||
var text = new ParseTextWalker("int value<float y=1.3;> = 4;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("float y=1.3;", result.Annotations);
|
||||
Assert.AreEqual("4", result.InitialValue);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestSemanticParsing
|
||||
[Test]
|
||||
public static void TestSemanticParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("int value : COLOR;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("COLOR", result.Semantic);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestSemanticParsingWithAnnotations
|
||||
[Test]
|
||||
public static void TestSemanticParsingWithAnnotations()
|
||||
{
|
||||
var text = new ParseTextWalker("int value : COLOR<float y=1.3;>;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("COLOR", result.Semantic);
|
||||
Assert.AreEqual("float y=1.3;", result.Annotations);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestSemanticParsingWithInitialValue
|
||||
[Test]
|
||||
public static void TestSemanticParsingWithInitialValue()
|
||||
{
|
||||
var text = new ParseTextWalker("int value : COLOR = 5;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("COLOR", result.Semantic);
|
||||
Assert.AreEqual("5", result.InitialValue);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestSemanticParsingWithoutSpaces
|
||||
[Test]
|
||||
public static void TestSemanticParsingWithoutSpaces()
|
||||
{
|
||||
var text = new ParseTextWalker("int value:COLOR;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("COLOR", result.Semantic);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestPackoffsetParsing
|
||||
[Test]
|
||||
public static void TestPackoffsetParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("int value : packoffset(c0);");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("packoffset(c0)", result.Packoffset);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestRegisterParsing
|
||||
[Test]
|
||||
public static void TestRegisterParsing()
|
||||
{
|
||||
var text = new ParseTextWalker("int value : register( ps_5_0, s );");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("register( ps_5_0, s )", result.Register);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestRegisterAndAnnotationParsing
|
||||
[Test]
|
||||
public static void TestRegisterAndAnnotationParsing()
|
||||
{
|
||||
var text = new ParseTextWalker(
|
||||
"int value : register( ps_5_0, s ) <float y=1.3;>;");
|
||||
var result = Variable.TryParse(text);
|
||||
|
||||
Assert.AreEqual("value", result.Name);
|
||||
Assert.AreEqual("register( ps_5_0, s )", result.Register);
|
||||
Assert.AreEqual("float y=1.3;", result.Annotations);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToString
|
||||
[Test]
|
||||
public static void TestToString()
|
||||
{
|
||||
string variableText = "uniform const int value : COLOR <float y=1.3;> = 5;";
|
||||
var walker = new ParseTextWalker(variableText);
|
||||
var result = Variable.TryParse(walker);
|
||||
|
||||
Assert.AreEqual(variableText, result.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToStringWithArraySize
|
||||
[Test]
|
||||
public static void TestToStringWithArraySize()
|
||||
{
|
||||
string variableText = "uniform const int value[7];";
|
||||
var walker = new ParseTextWalker(variableText);
|
||||
var result = Variable.TryParse(walker);
|
||||
|
||||
Assert.AreEqual(variableText, result.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToStringWithPackoffset
|
||||
[Test]
|
||||
public static void TestToStringWithPackoffset()
|
||||
{
|
||||
string variableText = "uniform const int value : packoffset(c0) = 5;";
|
||||
var walker = new ParseTextWalker(variableText);
|
||||
var result = Variable.TryParse(walker);
|
||||
|
||||
Assert.AreEqual(variableText, result.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToStringWithRegister
|
||||
[Test]
|
||||
public static void TestToStringWithRegister()
|
||||
{
|
||||
string variableText = "uniform const int value : register( vs, s[8] ) = 5;";
|
||||
var walker = new ParseTextWalker(variableText);
|
||||
var result = Variable.TryParse(walker);
|
||||
|
||||
Assert.AreEqual(variableText, result.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestToStringWithDimensions
|
||||
[Test]
|
||||
public static void TestToStringWithDimensions()
|
||||
{
|
||||
string variableText = "float4x4 matrix;";
|
||||
var walker = new ParseTextWalker(variableText);
|
||||
var result = Variable.TryParse(walker);
|
||||
|
||||
Assert.AreEqual(variableText, result.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user