From f32375be4fce2220083fb37a394aa75b49212f31 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Fri, 14 Oct 2016 00:22:56 +0100 Subject: [PATCH] Refactored and renamed ASTContext.FindOrCreateModule. --- src/AST/ASTContext.cs | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/AST/ASTContext.cs b/src/AST/ASTContext.cs index 74829d6f..9d588e60 100644 --- a/src/AST/ASTContext.cs +++ b/src/AST/ASTContext.cs @@ -26,31 +26,37 @@ namespace CppSharp.AST TranslationUnits = new List(); } - /// Finds an existing module or creates a new one given a file path. - public TranslationUnit FindOrCreateModule(string file) + static private string NormalizeTranslationUnitFilePath(string name) { - if (!file.StartsWith("<")) + if (name.StartsWith("<")) + return name; + + try + { + name = Path.GetFullPath(name); + } + catch (ArgumentException) { - try - { - file = Path.GetFullPath(file); - } - catch (ArgumentException) - { - // Normalization errors are expected when dealing with virtual - // compiler files like . - } + // Normalization errors are expected when dealing with virtual + // compiler files like . } - - var module = TranslationUnits.Find(m => m.FilePath.Equals(file)); - if (module == null) + return name; + } + + /// Finds an existing or creates a new one translation unit given a path. + public TranslationUnit FindOrCreateTranslationUnit(string file) + { + file = NormalizeTranslationUnitFilePath(file); + var translationUnit = TranslationUnits.Find(m => m.FilePath.Equals(file)); + + if (translationUnit == null) { - module = new TranslationUnit(file); - TranslationUnits.Add(module); + translationUnit = new TranslationUnit(file); + TranslationUnits.Add(translationUnit); } - return module; + return translationUnit; } /// Finds an existing enum in the library modules.