public void WildcardIncludes() { string[] sharpmakeIncludedFiles = { Path.Combine("folder", "sub1", "file1.sharpmake.cs"), Path.Combine("folder", "sub1", "file3.sharpmake.cs"), Path.Combine("folder", "sub1", "file2.sharpmake.cs"), Path.Combine("folder", "sub1", "anotherfiletonotinclude.sharpmake.cs"), Path.Combine("folder", "sub2", "file1.sharpmake.cs"), Path.Combine("folder", "sub2", "file3.sharpmake.cs"), Path.Combine("folder", "sub2", "anotherfiletonotinclude.sharpmake.cs") }; string[] sharpmakeIncludesFullPath = sharpmakeIncludedFiles.Select(file => Path.Combine(_fakeFileInfo.DirectoryName, file)).ToArray(); foreach (string file in sharpmakeIncludedFiles) { Util.AddNewFakeFile(file, 0); } string line = @"[module: Sharpmake.Include(""folder/*sub*/file*.cs"")]"; var assemblerContext = new AssemblerContext(); new Assembler().ParseSourceAttributesFromLine(line, _fakeFileInfo, _fakeFileLine, assemblerContext); Assert.That(assemblerContext.Sources.Count, Is.EqualTo(5)); CollectionAssert.IsSubsetOf(assemblerContext.Sources, sharpmakeIncludesFullPath); foreach (string include in assemblerContext.Sources) { StringAssert.DoesNotContain(include, "anotherfiletonotinclude.sharpmake.cs"); } }
private void AnalyseSourceFiles(AssemblerContext context) { var newParsers = Enumerable.Empty <ISourceAttributeParser>(); var allParsers = context.AllParsers.ToList(); // Copy, as it may be modified when parsing other files int partiallyParsedCount = 0; do { // Get all using namespace from sourceFiles for (int i = 0; i < context.SourceFiles.Count; ++i) { string sourceFile = context.SourceFiles[i]; if (File.Exists(sourceFile)) { AnalyseSourceFile(sourceFile, (i < partiallyParsedCount) ? newParsers : allParsers, context.AllParsingFlowParsers, context); } else { throw new Error("source file not found: " + sourceFile); } } // Get parsers discovered while parsing these files // We need to reparse all files currently in the list (partiallyParsedCount) again with the new parsers only, // and all files discovered after this with all the parsers. newParsers = context.ImportedParsers; context.ImportedParsers = new List <ISourceAttributeParser>(); allParsers.AddRange(newParsers); partiallyParsedCount = context.SourceFiles.Count; } while (newParsers.Any()); }
public void ConvolutedIncludeWithComments_NoInclude() { string[] sharpmakeIncludedFiles = { Path.Combine("folder", "sub1", "file1.sharpmake.cs"), Path.Combine("folder", "sub1", "file3.sharpmake.cs"), Path.Combine("folder", "sub1", "file2.sharpmake.cs"), Path.Combine("folder", "sub1", "nottoinclude.sharpmake.cs"), Path.Combine("folder", "sub2", "file1.sharpmake.cs"), Path.Combine("folder", "sub2", "file3.sharpmake.cs"), Path.Combine("folder", "sub2", "nottoinclude.sharpmake.cs") }; foreach (string file in sharpmakeIncludedFiles) { Util.AddNewFakeFile(file, 0); } string line = @"//**/[module: Sharpmake.Include(@""folder*/sub*/*file*.cs"")] // asdmvie aas */ [module: Sharpmake.Include(@""folder/sub1/nottoinclude.sharpmake.cs"")]"; var assemblerContext = new AssemblerContext(); new Assembler().ParseSourceAttributesFromLine(line, _fakeFileInfo, _fakeFileLine, assemblerContext); Assert.That(assemblerContext.Sources.Count, Is.EqualTo(0)); }
public void ConvolutedIncludeWithComments1() { string[] sharpmakeIncludedFiles = { Path.Combine("folder", "sub1", "file1.sharpmake.cs"), Path.Combine("folder", "sub1", "file3.sharpmake.cs"), Path.Combine("folder", "sub1", "file2.sharpmake.cs"), Path.Combine("folder", "sub1", "nottoinclude.sharpmake.cs"), Path.Combine("folder", "sub2", "file1.sharpmake.cs"), Path.Combine("folder", "sub2", "file3.sharpmake.cs"), Path.Combine("folder", "sub2", "nottoinclude.sharpmake.cs") }; string[] sharpmakeIncludesFullPath = sharpmakeIncludedFiles.Select(file => Path.Combine(_fakeFileInfo.DirectoryName, file)).ToArray(); foreach (string file in sharpmakeIncludedFiles) { Util.AddNewFakeFile(file, 0); } string line = @"[module/*:Sharpmake.Include(@""folder/sub1/nottoinclude.sharpmake.cs"")]/**/: Sharpmake/*.Reference*/.Include(/*asda(@"" /*dsa*/@""folder*/sub*/*file*.cs"")]// asdmvie aas */ asd [module: Sharpmake.Include(@""folder/sub1/nottoinclude.sharpmake.cs"")]"; var assemblerContext = new AssemblerContext(); new Assembler().ParseSourceAttributesFromLine(line, _fakeFileInfo, _fakeFileLine, assemblerContext); Assert.That(assemblerContext.Sources.Count, Is.EqualTo(5)); CollectionAssert.IsSubsetOf(assemblerContext.Sources, sharpmakeIncludesFullPath); foreach (string include in assemblerContext.Sources) { StringAssert.DoesNotContain(include, "nottoinclude.sharpmake.cs"); } }
public void EmptyLine() { var assemblerContext = new AssemblerContext(); new Assembler().ParseSourceAttributesFromLine("", _fakeFileInfo, _fakeFileLine, assemblerContext); Assert.That(assemblerContext.Sources.Count, Is.EqualTo(0)); }
private void EvaluateLines(LineTest[] lines, HashSet <string> defines) { var assemblerContext = new AssemblerContext(); IParsingFlowParser parser = new PreprocessorConditionParser(defines); LineTestNestedFile wrapperFile = new LineTestNestedFile(lines); wrapperFile.Test(parser, _fakeFileInfo, 0, assemblerContext); }
internal List <string> GetSourceFiles(IBuilderContext builderContext, string[] sources) { var assemblyInfo = new AssemblyInfo() { Id = string.Join(";", sources), }; var context = new AssemblerContext(this, assemblyInfo, builderContext, sources); AnalyseSourceFiles(context); return(assemblyInfo.SourceFiles.ToList()); }
private void EvaluateLines(LineTest[] lines, HashSet <string> defines) { var assemblerContext = new AssemblerContext(); IParsingFlowParser parser = new PreprocessorConditionParser(defines); for (int i = 0; i < lines.Length; i++) { parser.ParseLine(lines[i].Line, _fakeFileInfo, i, assemblerContext); bool shouldParseLine = parser.ShouldParseLine(); Assert.AreEqual(lines[i].ExpectedResult, shouldParseLine, $"ShouldParseLine for line ({i}) \"{lines[i].Line}\" should return {lines[i].ExpectedResult}!"); } }
public void IncorrectFormattedReference() { const string sharpmakeReferencedFile = "yetanotherassembly.dll"; Util.AddNewFakeFile(sharpmakeReferencedFile, 0); string line = $"\t \t [module:\t \t SharpmakeAReference(\t stuffstuff \"{sharpmakeReferencedFile}\")]"; var assemblerContext = new AssemblerContext(); new Assembler().ParseSourceAttributesFromLine(line, _fakeFileInfo, _fakeFileLine, assemblerContext); Assert.That(assemblerContext.References.Count, Is.EqualTo(0)); }
private AssemblyInfo LoadAssemblyInfo(IBuilderContext builderContext, string[] sources) { var assemblyInfo = new AssemblyInfo() { Id = string.Join(";", sources), }; var context = new AssemblerContext(this, assemblyInfo, builderContext, sources); AnalyseSourceFiles(context); _references.AddRange(assemblyInfo.References); return(assemblyInfo); }
public void SimpleInclude() { const string sharpmakeIncludedFile = "someproject.sharpmake.cs"; string sharpmakeIncludeFullPath = Path.Combine(_fakeFileInfo.DirectoryName, sharpmakeIncludedFile); Util.AddNewFakeFile(sharpmakeIncludedFile, 0); string line = $@"[module: Sharpmake.Include(""{sharpmakeIncludedFile}"")]"; var assemblerContext = new AssemblerContext(); new Assembler().ParseSourceAttributesFromLine(line, _fakeFileInfo, _fakeFileLine, assemblerContext); Assert.That(assemblerContext.Sources.Count, Is.EqualTo(1)); StringAssert.AreEqualIgnoringCase(sharpmakeIncludeFullPath, assemblerContext.Sources.First()); }
public void ConvolutedReference() { const string sharpmakeReferencedFile = "some assembly with spaces.dll"; string sharpmakeReferenceFullPath = Path.Combine(_fakeFileInfo.DirectoryName, sharpmakeReferencedFile); Util.AddNewFakeFile(sharpmakeReferencedFile, 0); string line = $" [ module\t : Sharpmake .\t Reference ( @\"{sharpmakeReferencedFile}\" \t) ] \t"; var assemblerContext = new AssemblerContext(); new Assembler().ParseSourceAttributesFromLine(line, _fakeFileInfo, _fakeFileLine, assemblerContext); Assert.That(assemblerContext.References.Count, Is.EqualTo(1)); StringAssert.AreEqualIgnoringCase(sharpmakeReferenceFullPath, assemblerContext.References.First()); }
public AstCompileVisitor(Assembler assembler) { _inference = new AstTypeInferenceVisitor(); _context = assembler.CreateContext(); }
public AssemblerContext CreateContext() { var context = new AssemblerContext(); _contexts.Add(context); return context; }
public abstract void Test(IParsingFlowParser parser, FileInfo fileInfo, int index, AssemblerContext assemblerContext);
public override void Test(IParsingFlowParser parser, FileInfo fileInfo, int index, AssemblerContext assemblerContext) { parser.ParseLine(Line, fileInfo, index, assemblerContext); bool shouldParseLine = parser.ShouldParseLine(); Assert.AreEqual(ExpectedResult, shouldParseLine, $"ShouldParseLine for line ({index}) \"{Line}\" should return {ExpectedResult} after evaluation!"); }
public override void Test(IParsingFlowParser parser, FileInfo fileInfo, int index, AssemblerContext assemblerContext) { Assert.DoesNotThrow(() => parser.FileParsingBegin(fileInfo.FullName)); for (int i = 0; i < Lines.Length; i++) { Lines[i].Test(parser, fileInfo, i, assemblerContext); } Assert.DoesNotThrow(() => parser.FileParsingEnd(fileInfo.FullName)); }