Tools and libraries to glue C/C++ APIs to high-level languages
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

88 lines
2.3 KiB

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace CppSharp.AST
{
/// <summary>
/// Represents a parsed C++ unit.
/// </summary>
[DebuggerDisplay("File = {FileName}, Ignored = {Ignore}")]
public class TranslationUnit : Namespace
{
public TranslationUnit()
{
Macros = new List<MacroDefinition>();
Access = AccessSpecifier.Public;
}
public TranslationUnit(string file) : this()
{
FilePath = file;
}
/// Contains the macros present in the unit.
public List<MacroDefinition> Macros;
public Module Module
{
get { return (Module) module.Target; }
set { module = new WeakReference(value); }
}
public bool IsSystemHeader { get; set; }
public bool IsValid { get { return FilePath != "<invalid>"; } }
/// Contains the path to the file.
public string FilePath;
private string fileName;
private string fileNameWithoutExtension;
/// Contains the name of the file.
public string FileName
{
get { return fileName ?? (fileName = Path.GetFileName(FilePath)); }
}
/// Contains the name of the module.
public string FileNameWithoutExtension
{
get
{
return fileNameWithoutExtension ??
(fileNameWithoutExtension = Path.GetFileNameWithoutExtension(FileName));
}
}
/// Contains the include path.
public string IncludePath;
private string fileRelativeDirectory;
private string fileRelativePath;
public string FileRelativeDirectory
{
get
{
if (fileRelativeDirectory != null) return fileRelativeDirectory;
var path = IncludePath.Replace('\\', '/');
var index = path.LastIndexOf('/');
return fileRelativeDirectory = path.Substring(0, index);
}
}
public string FileRelativePath
{
get
{
return fileRelativePath ??
(fileRelativePath = Path.Combine(FileRelativeDirectory, FileName));
}
}
private WeakReference module;
}
}