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

158
src/AST/TypeExtensions.cs

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

20
src/Parser/Parser.cpp

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

Loading…
Cancel
Save