Browse Source

Refactored and renamed ASTContext.FindOrCreateModule.

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

26
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 try
{ {
file = Path.GetFullPath(file); name = Path.GetFullPath(name);
} }
catch (ArgumentException) catch (ArgumentException)
{ {
// Normalization errors are expected when dealing with virtual // Normalization errors are expected when dealing with virtual
// compiler files like <built-in>. // compiler files like <built-in>.
} }
return name;
} }
var module = TranslationUnits.Find(m => m.FilePath.Equals(file)); /// 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