Permalink
Browse files

very first outline of a C compiler task

  • Loading branch information...
1 parent 21854cd commit 6eef101b1b2c2e113df474784b80575d3385e1ba Lucas Meijer committed Apr 14, 2012
Showing with 82 additions and 0 deletions.
  1. +44 −0 CCompilerTask.cs
  2. +13 −0 IncludeScanner.cs
  3. +22 −0 Tests/CCompilerTests.cs
  4. +3 −0 bs.csproj
View
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using bs.Tests;
+
+namespace bs
+{
+ public class CCompilerTask
+ {
+ private readonly string _targetFile;
+ private readonly string _sourceFile;
+
+ public CCompilerTask(string targetFile, string sourceFile)
+ {
+ _targetFile = targetFile;
+ _sourceFile = sourceFile;
+ }
+
+ public IEnumerable<string> GetInputFiles()
+ {
+ yield return _sourceFile;
+ foreach (var file in GetFilesIncludedBy(_sourceFile))
+ yield return file;
+ }
+
+ private static IEnumerable<string> GetFilesIncludedBy(string file)
+ {
+ var includeScanner = new IncludeScanner();
+ foreach(var includedFile in includeScanner.Scan(file))
+ {
+ var foundIncludeFile = FindSpecifiedIncludeFileInSearchDirs(includedFile);
+ if (foundIncludeFile == null)
+ throw new InvalidOperationException("unable to find the header file: "+includedFile+" in the header search paths.");
+ yield return foundIncludeFile;
+ foreach (var file2 in GetFilesIncludedBy(foundIncludeFile))
+ yield return file2;
+ }
+ }
+
+ private static string FindSpecifiedIncludeFileInSearchDirs(string includedFile)
+ {
+ return includedFile;
+ }
+ }
+}
View
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+
+namespace bs
+{
+ internal class IncludeScanner
+ {
+ public IEnumerable<string> Scan(string file)
+ {
+ yield break;
+ }
+ }
+}
View
@@ -0,0 +1,22 @@
+using System.IO;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using System.Collections.Generic;
+
+namespace bs.Tests
+{
+ [TestFixture]
+ public class CCompilerTests
+ {
+ [Test]
+ public void Test()
+ {
+ File.WriteAllText("test.c", "void main() {}");
+ var task = new CCompilerTask("test.o", "test.c");
+ var inputfiles = task.GetInputFiles();
+
+ CollectionAssert.AreEquivalent(new List<string> {"test.c"}, inputfiles);
+ }
+ }
+}
View
@@ -51,10 +51,13 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TargetBuildInstructions.cs" />
<Compile Include="TargetBuildSettings.cs" />
+ <Compile Include="CCompilerTask.cs" />
+ <Compile Include="Tests\CCompilerTests.cs" />
<Compile Include="Tests\DependencyGraphTests.cs" />
<Compile Include="DependencyGraph.cs" />
<Compile Include="MissingDependencyException.cs" />
<Compile Include="Tests\DifferentInputFiles.cs" />
+ <Compile Include="IncludeScanner.cs" />
<Compile Include="Tests\SimpleCopyDepGraph.cs" />
<Compile Include="Tests\TargetWithoutSources.cs" />
</ItemGroup>

0 comments on commit 6eef101

Please sign in to comment.