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.