Browse Source

Fixed line endings.

pull/245/head
Elias Holzer 11 years ago
parent
commit
3f813bc3ee
  1. 48
      src/AST/Namespace.cs
  2. 158
      src/AST/TypeExtensions.cs
  3. 20
      src/Parser/Parser.cpp

48
src/AST/Namespace.cs

@ -51,20 +51,20 @@ namespace CppSharp.AST @@ -51,20 +51,20 @@ namespace CppSharp.AST
Anonymous = new Dictionary<ulong, Declaration>();
}
protected DeclarationContext(DeclarationContext dc)
: base(dc)
{
Namespaces = new List<Namespace>(dc.Namespaces);
Enums = new List<Enumeration>(dc.Enums);
Functions = new List<Function>(dc.Functions);
Classes = new List<Class>(dc.Classes);
Templates = new List<Template>(dc.Templates);
Typedefs = new List<TypedefDecl>(dc.Typedefs);
Variables = new List<Variable>(dc.Variables);
Events = new List<Event>(dc.Events);
TypeReferences = new List<TypeReference>(dc.TypeReferences);
Anonymous = new Dictionary<ulong, Declaration>(dc.Anonymous);
IsAnonymous = dc.IsAnonymous;
protected DeclarationContext(DeclarationContext dc)
: base(dc)
{
Namespaces = new List<Namespace>(dc.Namespaces);
Enums = new List<Enumeration>(dc.Enums);
Functions = new List<Function>(dc.Functions);
Classes = new List<Class>(dc.Classes);
Templates = new List<Template>(dc.Templates);
Typedefs = new List<TypedefDecl>(dc.Typedefs);
Variables = new List<Variable>(dc.Variables);
Events = new List<Event>(dc.Events);
TypeReferences = new List<TypeReference>(dc.TypeReferences);
Anonymous = new Dictionary<ulong, Declaration>(dc.Anonymous);
IsAnonymous = dc.IsAnonymous;
}
public IEnumerable<DeclarationContext> GatherParentNamespaces()
@ -178,11 +178,11 @@ namespace CppSharp.AST @@ -178,11 +178,11 @@ namespace CppSharp.AST
return null;
return @namespace.FindEnum(enumName, createDecl);
}
public Enumeration FindEnum(IntPtr ptr)
{
return Enums.FirstOrDefault(f => f.OriginalPtr == ptr);
}
public Enumeration FindEnum(IntPtr ptr)
{
return Enums.FirstOrDefault(f => f.OriginalPtr == ptr);
}
public Function FindFunction(string name, bool createDecl = false)
@ -353,11 +353,11 @@ namespace CppSharp.AST @@ -353,11 +353,11 @@ namespace CppSharp.AST
public Enumeration FindEnumWithItem(string name)
{
var result = Enums.Find(e => e.ItemsByName.ContainsKey(name));
if (result == null)
result = Namespaces.Select(ns => ns.FindEnumWithItem(name)).FirstOrDefault();
if (result == null)
result = Classes.Select(c => c.FindEnumWithItem(name)).FirstOrDefault();
var result = Enums.Find(e => e.ItemsByName.ContainsKey(name));
if (result == null)
result = Namespaces.Select(ns => ns.FindEnumWithItem(name)).FirstOrDefault();
if (result == null)
result = Classes.Select(c => c.FindEnumWithItem(name)).FirstOrDefault();
return result;
}

158
src/AST/TypeExtensions.cs

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
public static bool IsPrimitiveType(this Type t, out PrimitiveType primitive)
{
var builtin = t.Desugar() as BuiltinType;
var builtin = t.Desugar() as BuiltinType;
if (builtin != null)
{
primitive = builtin.Type;
@ -105,55 +105,55 @@ @@ -105,55 +105,55 @@
return type != null;
}
public static bool IsClass(this Type t)
{
Class @class;
return t.TryGetClass(out @class);
}
public static bool TryGetClass(this Type t, out Class @class)
{
t = t.Desugar();
public static bool IsClass(this Type t)
{
Class @class;
return t.TryGetClass(out @class);
}
public static bool TryGetClass(this Type t, out Class @class)
{
t = t.Desugar();
var tag = t as TagType;
if (tag != null)
{
@class = tag.Declaration as Class;
{
@class = tag.Declaration as Class;
return @class != null;
}
var type = t as TemplateSpecializationType;
if (type != null)
{
var templatedClass = ((ClassTemplate)type.Template).TemplatedClass;
@class = templatedClass.CompleteDeclaration == null
? templatedClass
: (Class)templatedClass.CompleteDeclaration;
return @class != null;
}
@class = null;
}
var type = t as TemplateSpecializationType;
if (type != null)
{
var templatedClass = ((ClassTemplate)type.Template).TemplatedClass;
@class = templatedClass.CompleteDeclaration == null
? templatedClass
: (Class)templatedClass.CompleteDeclaration;
return @class != null;
}
@class = null;
return false;
}
public static bool IsEnum(this Type t)
{
Enumeration @enum;
return t.TryGetEnum(out @enum);
}
public static bool TryGetEnum(this Type t, out Enumeration @enum)
{
var tag = t.Desugar() as TagType;
if (tag == null)
{
@enum = null;
return false;
}
@enum = tag.Declaration as Enumeration;
return @enum != null;
}
public static bool IsEnum(this Type t)
{
Enumeration @enum;
return t.TryGetEnum(out @enum);
}
public static bool TryGetEnum(this Type t, out Enumeration @enum)
{
var tag = t.Desugar() as TagType;
if (tag == null)
{
@enum = null;
return false;
}
@enum = tag.Declaration as Enumeration;
return @enum != null;
}
public static Type Desugar(this Type t)
@ -184,39 +184,39 @@ @@ -184,39 +184,39 @@
}
return t;
}
/// <summary>
/// If t is a pointer type the type pointed to by t will be returned.
/// Otherwise null.
/// </summary>
public static Type GetPointee(this Type t)
{
var ptr = t as PointerType;
if (ptr != null)
return ptr.Pointee;
var memberPtr = t as MemberPointerType;
if (memberPtr != null)
return memberPtr.Pointee;
return null;
}
/// <summary>
/// If t is a pointer type the type pointed to by t will be returned
/// after fully dereferencing it. Otherwise null.
/// For example int** -> int.
/// </summary>
public static Type GetFinalPointee(this Type t)
{
var finalPointee = t.GetPointee();
var pointee = finalPointee;
while (pointee != null)
{
pointee = pointee.GetPointee();
if (pointee != null)
finalPointee = pointee;
}
return finalPointee;
}
/// <summary>
/// If t is a pointer type the type pointed to by t will be returned.
/// Otherwise null.
/// </summary>
public static Type GetPointee(this Type t)
{
var ptr = t as PointerType;
if (ptr != null)
return ptr.Pointee;
var memberPtr = t as MemberPointerType;
if (memberPtr != null)
return memberPtr.Pointee;
return null;
}
/// <summary>
/// If t is a pointer type the type pointed to by t will be returned
/// after fully dereferencing it. Otherwise null.
/// For example int** -> int.
/// </summary>
public static Type GetFinalPointee(this Type t)
{
var finalPointee = t.GetPointee();
var pointee = finalPointee;
while (pointee != null)
{
pointee = pointee.GetPointee();
if (pointee != null)
finalPointee = pointee;
}
return finalPointee;
}
}
}

20
src/Parser/Parser.cpp

@ -2159,16 +2159,16 @@ CppSharp::AST::PreprocessedEntity^ Parser::WalkPreprocessedEntity( @@ -2159,16 +2159,16 @@ CppSharp::AST::PreprocessedEntity^ Parser::WalkPreprocessedEntity(
return nullptr;
Entity->OriginalPtr = System::IntPtr(PPEntity);
Entity->Namespace = GetTranslationUnit(PPEntity->getSourceRange().getBegin(), NULL);
if (Decl->GetType() == CppSharp::AST::TranslationUnit::typeid)
{
Entity->Namespace->PreprocessedEntities->Add(Entity);
}
else
{
Decl->PreprocessedEntities->Add(Entity);
}
Entity->Namespace = GetTranslationUnit(PPEntity->getSourceRange().getBegin(), NULL);
if (Decl->GetType() == CppSharp::AST::TranslationUnit::typeid)
{
Entity->Namespace->PreprocessedEntities->Add(Entity);
}
else
{
Decl->PreprocessedEntities->Add(Entity);
}
return Entity;
}

Loading…
Cancel
Save