/// <summary> /// Parses the specified input. /// </summary> /// <param name="input">The input.</param> /// <param name="fileName">Name of the file.</param> /// <returns>Result of parsing</returns> private EffectParserResult PrepareParsing(string input, string fileName) { var filePath = Path.GetFullPath(fileName); fileName = Path.GetFileName(fileName); var localResult = new EffectParserResult { SourceFileName = Path.Combine(Environment.CurrentDirectory, filePath), IncludeHandler = new FileIncludeHandler { Logger = Logger } }; localResult.IncludeHandler.CurrentDirectory.Push(Path.GetDirectoryName(localResult.SourceFileName)); localResult.IncludeHandler.IncludeDirectories.AddRange(IncludeDirectoryList); localResult.IncludeHandler.IncludeFileCallback = IncludeFileCallback; localResult.IncludeHandler.FileResolved.Add(fileName, new FileIncludeHandler.FileItem(fileName, filePath, File.GetLastWriteTime(filePath))); string compilationErrors = null; var preprocessedInput = ShaderBytecode.Preprocess(input, Macros.ToArray(), localResult.IncludeHandler, out compilationErrors, filePath); localResult.PreprocessedSource = preprocessedInput; localResult.DependencyList = CalculateDependencies(localResult); return(localResult); }
/// <summary> /// Continues the parsing. /// </summary> /// <param name="previousParsing">The previous parsing.</param> /// <returns>EffectParserResult.</returns> private EffectParserResult ContinueParsing(EffectParserResult previousParsing) { // Reset count parentCount = 0; curlyBraceCount = 0; bracketCount = 0; result = previousParsing; newPreprocessedSource = result.PreprocessedSource; tokenEnumerator = Tokenizer.Run(previousParsing.PreprocessedSource).GetEnumerator(); do { var token = NextToken(); if (token.Type == TokenType.EndOfFile) { break; } switch (token.Type) { case TokenType.Identifier: if ((token.EqualString("technique") || token.EqualString("technique10") || token.EqualString("technique11")) && curlyBraceCount == 0) { ParseTechnique(); } break; } } while (true); if (!CheckAllBracketsClosed()) { if (parentCount != 0) { Logger.Error("Error matching closing parentheses for '('", lastParentToken.Span); } if (bracketCount != 0) { Logger.Error("Error matching closing bracket for '['", lastBracketToken.Span); } if (curlyBraceCount != 0) { Logger.Error("Error matching closing curly brace for '{'", lastCurlyBraceToken.Span); } } result.PreprocessedSource = newPreprocessedSource; return(result); }
private FileDependencyList CalculateDependencies(EffectParserResult parserResult) { var keys = new List <string>(parserResult.IncludeHandler.FileResolved.Keys); keys.Sort(StringComparer.InvariantCultureIgnoreCase); var dependency = new FileDependencyList(); dependency.AddDefaultDependencies(); foreach (var fileKey in keys) { var fileItem = parserResult.IncludeHandler.FileResolved[fileKey]; dependency.AddDependencyPath(fileItem.FilePath); } return(dependency); }
private FileDependencyList CalculateDependencies(EffectParserResult parserResult) { var keys = new List<string>(parserResult.IncludeHandler.FileResolved.Keys); keys.Sort(StringComparer.InvariantCultureIgnoreCase); var dependency = new FileDependencyList(); dependency.AddDefaultDependencies(); foreach (var fileKey in keys) { var fileItem = parserResult.IncludeHandler.FileResolved[fileKey]; dependency.AddDependencyPath(fileItem.FilePath); } return dependency; }
/// <summary> /// Continues the parsing. /// </summary> /// <param name="previousParsing">The previous parsing.</param> /// <returns>EffectParserResult.</returns> private EffectParserResult ContinueParsing(EffectParserResult previousParsing) { // Reset count parentCount = 0; curlyBraceCount = 0; bracketCount = 0; result = previousParsing; newPreprocessedSource = result.PreprocessedSource; tokenEnumerator = Tokenizer.Run(previousParsing.PreprocessedSource).GetEnumerator(); do { var token = NextToken(); if (token.Type == TokenType.EndOfFile) break; switch (token.Type) { case TokenType.Identifier: if ((token.EqualString("technique") || token.EqualString("technique10") || token.EqualString("technique11")) && curlyBraceCount == 0) ParseTechnique(); break; } } while (true); if (!CheckAllBracketsClosed()) { if (parentCount != 0) { Logger.Error("Error matching closing parentheses for '('", lastParentToken.Span); } if (bracketCount != 0) { Logger.Error("Error matching closing bracket for '['", lastBracketToken.Span); } if (curlyBraceCount != 0) { Logger.Error("Error matching closing curly brace for '{'", lastCurlyBraceToken.Span); } } result.PreprocessedSource = newPreprocessedSource; return result; }
/// <summary> /// Parses the specified input. /// </summary> /// <param name="input">The input.</param> /// <param name="fileName">Name of the file.</param> /// <returns>Result of parsing</returns> private EffectParserResult PrepareParsing(string input, string fileName) { var filePath = Path.GetFullPath(fileName); fileName = Path.GetFileName(fileName); var localResult = new EffectParserResult { SourceFileName = Path.Combine(Environment.CurrentDirectory, filePath), IncludeHandler = new FileIncludeHandler { Logger = Logger } }; localResult.IncludeHandler.CurrentDirectory.Push(Path.GetDirectoryName(localResult.SourceFileName)); localResult.IncludeHandler.IncludeDirectories.AddRange(IncludeDirectoryList); localResult.IncludeHandler.IncludeFileCallback = IncludeFileCallback; localResult.IncludeHandler.FileResolved.Add(fileName, new FileIncludeHandler.FileItem(fileName, filePath, File.GetLastWriteTime(filePath))); string compilationErrors = null; var preprocessedInput = ShaderBytecode.Preprocess(input, Macros.ToArray(), localResult.IncludeHandler, out compilationErrors, filePath); localResult.PreprocessedSource = preprocessedInput; localResult.DependencyList = CalculateDependencies(localResult); return localResult; }
private int CalculateHashcode(EffectParserResult parserResult) { var keys = new List<string>(parserResult.IncludeHandler.FileResolved.Keys); keys.Sort(StringComparer.InvariantCultureIgnoreCase); // Compute a HashCode using FNVModified // based on filename and file write time const uint p = 16777619; uint hash = 2166136261; foreach (var fileKey in keys) { var fileItem = parserResult.IncludeHandler.FileResolved[fileKey]; var modifiedTime = fileItem.ModifiedTime; var fileName = fileKey.ToLower(); hash = (hash ^ (uint)fileName.GetHashCode()) * p; hash = (hash ^ (uint)modifiedTime.GetHashCode()) * p; } hash += hash << 13; hash ^= hash >> 7; hash += hash << 3; hash ^= hash >> 17; hash += hash << 5; return unchecked((int)hash); }