Browse Source

Refactored and renamed ASTContext.FindOrCreateModule.

pull/700/head
Joao Matos 10 years ago
parent
commit
f32375be4f
  1. 40
      src/AST/ASTContext.cs

40
src/AST/ASTContext.cs

@ -26,31 +26,37 @@ namespace CppSharp.AST
TranslationUnits = new List<TranslationUnit>(); TranslationUnits = new List<TranslationUnit>();
} }
/// Finds an existing module or creates a new one given a file path. static private string NormalizeTranslationUnitFilePath(string name)
public TranslationUnit FindOrCreateModule(string file)
{ {
if (!file.StartsWith("<")) if (name.StartsWith("<"))
return name;
try
{
name = Path.GetFullPath(name);
}
catch (ArgumentException)
{ {
try // Normalization errors are expected when dealing with virtual
{ // compiler files like <built-in>.
file = Path.GetFullPath(file);
}
catch (ArgumentException)
{
// Normalization errors are expected when dealing with virtual
// compiler files like <built-in>.
}
} }
var module = TranslationUnits.Find(m => m.FilePath.Equals(file)); 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 (module == null) if (translationUnit == null)
{ {
module = new TranslationUnit(file); translationUnit = new TranslationUnit(file);
TranslationUnits.Add(module); TranslationUnits.Add(translationUnit);
} }
return module; return translationUnit;
} }
/// Finds an existing enum in the library modules. /// Finds an existing enum in the library modules.

Loading…
Cancel
Save