public void CheckPositionNumberWithSingleUnit() { var srcmlObject = new ABB.SrcML.SrcML(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile(@"srctest\foo.c", @"srctest_xml\singleunit_position.xml"); var firstUnit = doc.FileUnits.First(); Assert.AreEqual(0, firstUnit.GetSrcLinePosition()); Assert.AreEqual(1, firstUnit.Descendants(SRC.Type).First().Element(SRC.Name).GetSrcLinePosition()); Assert.AreEqual(1, firstUnit.Element(SRC.Function).GetSrcLinePosition()); Assert.AreEqual(5, firstUnit.Descendants(SRC.Name).First(n => n.Value == "foo").GetSrcLinePosition()); Assert.AreEqual(5, firstUnit.Descendants(SRC.Name).First(n => n.Value == "printf").GetSrcLinePosition()); Assert.AreEqual(45, firstUnit.Descendants(SRC.Name).First(n => n.Value == "printd").GetSrcLinePosition()); Assert.AreEqual(6, firstUnit.Descendants(SRC.Name).First(n => n.Value == "bar").GetSrcLinePosition()); Assert.AreEqual(10, firstUnit.Descendants(SRC.Condition).First().GetSrcLinePosition()); Assert.AreEqual(9, firstUnit.Descendants(SRC.Name).First(n => n.Value == "printg").GetSrcLinePosition()); }
public static IEnumerable<Tuple<string, string, MethodDefinition>> ExtractAllMethodsFromFile(string filePath) { // open the file and convert to srcml //var srcml = new SrcMLFile( filePath ); //var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //var srcmlPath = Path.Combine(baseDir,"..", "..","..","..","External"); var srcmlPath = @"C:\Users\kh\Documents\GitHubVisualStudio\Swummary\External"; Console.WriteLine(srcmlPath); var srcml = new SrcML(srcmlPath); //var srcml = new SrcMLGenerator(); srcml.GenerateSrcMLFromFile(filePath, Path.Combine(filePath, ".xml")); //var srcmlFile = var srcmlFile = srcml.GenerateSrcMLFromFile(filePath, Path.Combine(filePath, ".xml")); //var ns = new NamespaceDefinition(); // get a grip on the parts we care about var fileUnits = srcmlFile.FileUnits; var parser = new CPlusPlusCodeParser(); //TODO: allow language to be chosen or detected // iterate through the mess to build a list of what we want var methodList = new List<Tuple<string, string, MethodDefinition>>(); foreach (var file in fileUnits) { var fileScope = parser.ParseFileUnit(file); var methods = fileScope.GetDescendants<MethodDefinition>(); string filename = file.Name.ToString(); foreach (var method in methods) { string methodName = method.Name.ToString(); var definition = method.GetDescendants<MethodDefinition>().Single(); var element = new Tuple<string, string, MethodDefinition>(filename, methodName, definition); methodList.Add( element); } } // done! return methodList.AsEnumerable(); }
public void CheckPositionNumberWithSingleUnit() { var srcmlObject = new ABB.SrcML.SrcML(); var doc = srcmlObject.GenerateSrcMLFromFile(@"srctest\foo.c", @"srctest_xml\singleunit_position.xml"); var firstUnit = doc.FileUnits.First(); Assert.AreEqual(0, firstUnit.GetSrcLinePosition()); Assert.AreEqual(1, firstUnit.Descendants(SRC.Type).First().Element(SRC.Name).GetSrcLinePosition()); Assert.AreEqual(1, firstUnit.Element(SRC.Function).GetSrcLinePosition()); Assert.AreEqual(5, firstUnit.Descendants(SRC.Name).First(n => n.Value == "foo").GetSrcLinePosition()); Assert.AreEqual(5, firstUnit.Descendants(SRC.Name).First(n => n.Value == "printf").GetSrcLinePosition()); Assert.AreEqual(45, firstUnit.Descendants(SRC.Name).First(n => n.Value == "printd").GetSrcLinePosition()); Assert.AreEqual(6, firstUnit.Descendants(SRC.Name).First(n => n.Value == "bar").GetSrcLinePosition()); Assert.AreEqual(10, firstUnit.Descendants(SRC.Condition).First().GetSrcLinePosition()); Assert.AreEqual(9, firstUnit.Descendants(SRC.Name).First(n => n.Value == "printg").GetSrcLinePosition()); }
public void FileWithBom() { var srcmlObject = new ABB.SrcML.SrcML(); var doc = srcmlObject.GenerateSrcMLFromFile("external\\fileWithBom.cpp", "external_xml\\fileWithBom.xml"); }
public void FileWithBom() { var srcmlObject = new ABB.SrcML.SrcML(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation)); var doc = srcmlObject.GenerateSrcMLFromFile("external\\fileWithBom.cpp", "external_xml\\fileWithBom.xml"); }