private CXChildVisitResult Visitor(CXCursor cursor, CXCursor parent, IntPtr data) { if (cursor.kind == CXCursorKind.CXCursor_EnumConstantDecl) { // prepare enumeration // prepare client data GCHandle enumHandle = (GCHandle)data; Enumeration thisEnum = enumHandle.Target as Enumeration; // get constant name string constantName = clang.getCursorSpelling(cursor).ToString(); // get enum constant value EnumField c = new EnumField { Name = constantName }; CXType underlyingType = clang.getEnumDeclIntegerType(parent); NativeType underlyingNativeType = TypeVisitorHelper.GetNativeType(AST_, underlyingType); if (ASTTraits.IsSigned(underlyingNativeType)) { c.Constant = clang.getEnumConstantDeclValue(cursor); } else { Debug.Assert(ASTTraits.IsUnSigned(underlyingNativeType)); c.Constant = (long)clang.getEnumConstantDeclUnsignedValue(cursor); } // add it to enumeration thisEnum.AddConstant(c); } return(CXChildVisitResult.CXChildVisit_Continue); }
public void SetExtra(NativeType extra, string literal) { Debug.Assert(TemplateParameterKind.NoneType == Kind); Debug.Assert(ASTTraits.IsIntegral(extra) || ASTTraits.IsEnum(extra)); Extra = new TemplateNonTypeParam { NoneType = extra, DefaultLiteral = literal }; }
public string GetCollapsedName(bool collapseTypedef = true, bool withConst = true) { bool valid = true; string result; if (ASTTraits.IsBuiltInType(TypeKind)) { result = ASTTraits.ToString(TypeKind); } else if (ASTTraits.IsObject(TypeKind)) { result = (Type as NativeClass).Name; } else if (ASTTraits.IsEnum(TypeKind)) { result = (Type as Enumeration).Name; } else if (ASTTraits.IsPointer(TypeKind)) { result = string.Format("{0} *", (Type as NativeType).CollapsedName); } else if (ASTTraits.IsLValueReference(TypeKind)) { result = string.Format("{0} &", (Type as NativeType).CollapsedName); } else if (ASTTraits.IsRValueReference(TypeKind)) { result = string.Format("{0} &&", (Type as NativeType).CollapsedName); } else if (ASTTraits.IsTypedef(TypeKind)) { Debug.Assert(!IsConst); if (collapseTypedef) { result = (Type as NativeType).CollapsedName; } else { if (!withConst) { result = StringTools.RemoveFirstOf(TypeName, "const"); } else { result = TypeName; } } } else { valid = false; result = "unknown"; } if (valid && IsConst && withConst) { result += " const"; } return(result); }
public void SetBuiltin(BasicType type) { Debug.Assert(ASTTraits.IsBuiltInType(type)); SetType(type, null); }