diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-02 18:58:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-02 18:58:10 -0500 |
commit | 4e4bf459240125816fc684219e4843f2071bcf2a (patch) | |
tree | 21eee3df8cb3dc7c39e1262afa513e504e9eb003 | |
parent | 33d475dd56b8c0513771139da2f04e7542eaadb3 (diff) | |
parent | a9d52d1d4764ba9bfc5106d64388ab1380388461 (diff) |
Auto merge of #195 - emilio:stupid-blocks, r=fitzgen
clang: Remove stupid `match` blocks and change them for well-supported functions.
r? @fitzgen
-rwxr-xr-x | src/clang.rs | 234 |
1 files changed, 4 insertions, 230 deletions
diff --git a/src/clang.rs b/src/clang.rs index b58cf017..7f81c379 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -1159,239 +1159,13 @@ impl UnsavedFile { } /// Convert a cursor kind into a static string. -pub fn kind_to_str(x: Enum_CXCursorKind) -> &'static str { - match x { - CXCursor_UnexposedDecl => "UnexposedDecl", - CXCursor_StructDecl => "StructDecl", - CXCursor_UnionDecl => "UnionDecl", - CXCursor_ClassDecl => "ClassDecl", - CXCursor_EnumDecl => "EnumDecl", - CXCursor_FieldDecl => "FieldDecl", - CXCursor_EnumConstantDecl => "EnumConstantDecl", - CXCursor_FunctionDecl => "FunctionDecl", - CXCursor_VarDecl => "VarDecl", - CXCursor_ParmDecl => "ParmDecl", - CXCursor_ObjCInterfaceDecl => "ObjCInterfaceDecl", - CXCursor_ObjCCategoryDecl => "ObjCCategoryDecl", - CXCursor_ObjCProtocolDecl => "ObjCProtocolDecl", - CXCursor_ObjCPropertyDecl => "ObjCPropertyDecl", - CXCursor_ObjCIvarDecl => "ObjCIvarDecl", - CXCursor_ObjCInstanceMethodDecl => "ObjCInstanceMethodDecl", - CXCursor_ObjCClassMethodDecl => "ObjCClassMethodDecl", - CXCursor_ObjCImplementationDecl => "ObjCImplementationDecl", - CXCursor_ObjCCategoryImplDecl => "ObjCCategoryImplDecl", - CXCursor_TypedefDecl => "TypedefDecl", - CXCursor_CXXMethod => "CXXMethod", - CXCursor_Namespace => "Namespace", - CXCursor_LinkageSpec => "LinkageSpec", - CXCursor_Constructor => "Constructor", - CXCursor_Destructor => "Destructor", - CXCursor_ConversionFunction => "ConversionFunction", - CXCursor_TemplateTypeParameter => "TemplateTypeParameter", - CXCursor_NonTypeTemplateParameter => "NonTypeTemplateParameter", - CXCursor_TemplateTemplateParameter => "TemplateTemplateParameter", - CXCursor_FunctionTemplate => "FunctionTemplate", - CXCursor_ClassTemplate => "ClassTemplate", - CXCursor_ClassTemplatePartialSpecialization => { - // FIXME: Ugly hack for rustfmt, should go away! - // - // I plan to convert this into an enum right away anyway, though. - return "ClassTemplatePartialSpecialization"; - } - CXCursor_NamespaceAlias => "NamespaceAlias", - CXCursor_UsingDirective => "UsingDirective", - CXCursor_UsingDeclaration => "UsingDeclaration", - CXCursor_TypeAliasDecl => "TypeAliasDecl", - CXCursor_ObjCSynthesizeDecl => "ObjCSynthesizeDecl", - CXCursor_ObjCDynamicDecl => "ObjCDynamicDecl", - CXCursor_CXXAccessSpecifier => "CXXAccessSpecifier", - // CXCursor_FirstDecl => "FirstDecl", - // CXCursor_LastDecl => "LastDecl", - CXCursor_FirstRef => "FirstRef", - // CXCursor_ObjCSuperClassRef => "ObjCSuperClassRef", - CXCursor_ObjCProtocolRef => "ObjCProtocolRef", - CXCursor_ObjCClassRef => "ObjCClassRef", - CXCursor_TypeRef => "TypeRef", - CXCursor_CXXBaseSpecifier => "CXXBaseSpecifier", - CXCursor_TemplateRef => "TemplateRef", - CXCursor_NamespaceRef => "NamespaceRef", - CXCursor_MemberRef => "MemberRef", - // CXCursor_LabelRef => "LabelRef", - CXCursor_OverloadedDeclRef => "OverloadedDeclRef", - CXCursor_VariableRef => "VariableRef", - // CXCursor_LastRef => "LastRef", - CXCursor_FirstInvalid => "FirstInvalid", - // CXCursor_InvalidFile => "InvalidFile", - CXCursor_NoDeclFound => "NoDeclFound", - CXCursor_NotImplemented => "NotImplemented", - CXCursor_InvalidCode => "InvalidCode", - // CXCursor_LastInvalid => "LastInvalid", - CXCursor_FirstExpr => "FirstExpr", - // CXCursor_UnexposedExpr => "UnexposedExpr", - CXCursor_DeclRefExpr => "DeclRefExpr", - CXCursor_MemberRefExpr => "MemberRefExpr", - CXCursor_CallExpr => "CallExpr", - CXCursor_ObjCMessageExpr => "ObjCMessageExpr", - CXCursor_BlockExpr => "BlockExpr", - CXCursor_IntegerLiteral => "IntegerLiteral", - CXCursor_FloatingLiteral => "FloatingLiteral", - CXCursor_ImaginaryLiteral => "ImaginaryLiteral", - CXCursor_StringLiteral => "StringLiteral", - CXCursor_CharacterLiteral => "CharacterLiteral", - CXCursor_ParenExpr => "ParenExpr", - CXCursor_UnaryOperator => "UnaryOperator", - CXCursor_ArraySubscriptExpr => "ArraySubscriptExpr", - CXCursor_BinaryOperator => "BinaryOperator", - CXCursor_CompoundAssignOperator => "CompoundAssignOperator", - CXCursor_ConditionalOperator => "ConditionalOperator", - CXCursor_CStyleCastExpr => "CStyleCastExpr", - CXCursor_CompoundLiteralExpr => "CompoundLiteralExpr", - CXCursor_InitListExpr => "InitListExpr", - CXCursor_AddrLabelExpr => "AddrLabelExpr", - CXCursor_StmtExpr => "StmtExpr", - CXCursor_GenericSelectionExpr => "GenericSelectionExpr", - CXCursor_GNUNullExpr => "GNUNullExpr", - CXCursor_CXXStaticCastExpr => "CXXStaticCastExpr", - CXCursor_CXXDynamicCastExpr => "CXXDynamicCastExpr", - CXCursor_CXXReinterpretCastExpr => "CXXReinterpretCastExpr", - CXCursor_CXXConstCastExpr => "CXXConstCastExpr", - CXCursor_CXXFunctionalCastExpr => "CXXFunctionalCastExpr", - CXCursor_CXXTypeidExpr => "CXXTypeidExpr", - CXCursor_CXXBoolLiteralExpr => "CXXBoolLiteralExpr", - CXCursor_CXXNullPtrLiteralExpr => "CXXNullPtrLiteralExpr", - CXCursor_CXXThisExpr => "CXXThisExpr", - CXCursor_CXXThrowExpr => "CXXThrowExpr", - CXCursor_CXXNewExpr => "CXXNewExpr", - CXCursor_CXXDeleteExpr => "CXXDeleteExpr", - CXCursor_UnaryExpr => "UnaryExpr", - CXCursor_ObjCStringLiteral => "ObjCStringLiteral", - CXCursor_ObjCEncodeExpr => "ObjCEncodeExpr", - CXCursor_ObjCSelectorExpr => "ObjCSelectorExpr", - CXCursor_ObjCProtocolExpr => "ObjCProtocolExpr", - CXCursor_ObjCBridgedCastExpr => "ObjCBridgedCastExpr", - CXCursor_PackExpansionExpr => "PackExpansionExpr", - CXCursor_SizeOfPackExpr => "SizeOfPackExpr", - CXCursor_LambdaExpr => "LambdaExpr", - CXCursor_ObjCBoolLiteralExpr => "ObjCBoolLiteralExpr", - // CXCursor_LastExpr => "LastExpr", - CXCursor_FirstStmt => "FirstStmt", - // CXCursor_UnexposedStmt => "UnexposedStmt", - CXCursor_LabelStmt => "LabelStmt", - CXCursor_CompoundStmt => "CompoundStmt", - CXCursor_CaseStmt => "CaseStmt", - CXCursor_DefaultStmt => "DefaultStmt", - CXCursor_IfStmt => "IfStmt", - CXCursor_SwitchStmt => "SwitchStmt", - CXCursor_WhileStmt => "WhileStmt", - CXCursor_DoStmt => "DoStmt", - CXCursor_ForStmt => "ForStmt", - CXCursor_GotoStmt => "GotoStmt", - CXCursor_IndirectGotoStmt => "IndirectGotoStmt", - CXCursor_ContinueStmt => "ContinueStmt", - CXCursor_BreakStmt => "BreakStmt", - CXCursor_ReturnStmt => "ReturnStmt", - CXCursor_AsmStmt => "AsmStmt", - CXCursor_ObjCAtTryStmt => "ObjCAtTryStmt", - CXCursor_ObjCAtCatchStmt => "ObjCAtCatchStmt", - CXCursor_ObjCAtFinallyStmt => "ObjCAtFinallyStmt", - CXCursor_ObjCAtThrowStmt => "ObjCAtThrowStmt", - CXCursor_ObjCAtSynchronizedStmt => "ObjCAtSynchronizedStmt", - CXCursor_ObjCAutoreleasePoolStmt => "ObjCAutoreleasePoolStmt", - CXCursor_ObjCForCollectionStmt => "ObjCForCollectionStmt", - CXCursor_CXXCatchStmt => "CXXCatchStmt", - CXCursor_CXXTryStmt => "CXXTryStmt", - CXCursor_CXXForRangeStmt => "CXXForRangeStmt", - CXCursor_SEHTryStmt => "SEHTryStmt", - CXCursor_SEHExceptStmt => "SEHExceptStmt", - CXCursor_SEHFinallyStmt => "SEHFinallyStmt", - CXCursor_NullStmt => "NullStmt", - CXCursor_DeclStmt => "DeclStmt", - // CXCursor_LastStmt => "LastStmt", - CXCursor_TranslationUnit => "TranslationUnit", - CXCursor_FirstAttr => "FirstAttr", - // CXCursor_UnexposedAttr => "UnexposedAttr", - CXCursor_IBActionAttr => "IBActionAttr", - CXCursor_IBOutletAttr => "IBOutletAttr", - CXCursor_IBOutletCollectionAttr => "IBOutletCollectionAttr", - CXCursor_CXXFinalAttr => "CXXFinalAttr", - CXCursor_CXXOverrideAttr => "CXXOverrideAttr", - CXCursor_AnnotateAttr => "AnnotateAttr", - CXCursor_AsmLabelAttr => "AsmLabelAttr", - // CXCursor_LastAttr => "LastAttr", - CXCursor_PreprocessingDirective => "PreprocessingDirective", - CXCursor_MacroDefinition => "MacroDefinition", - CXCursor_MacroExpansion => "MacroExpansion", - // CXCursor_MacroInstantiation => "MacroInstantiation", - CXCursor_InclusionDirective => "InclusionDirective", - // CXCursor_FirstPreprocessing => "FirstPreprocessing", - // CXCursor_LastPreprocessing => "LastPreprocessing", - CXCursor_PackedAttr => "PackedAttr", - CXCursor_ModuleImportDecl => "ModuleImportDecl", - CXCursor_TypeAliasTemplateDecl => "TypeAliasTemplateDecl", - CXCursor_StaticAssert => "StaticAssert", - _ => "?", - } +pub fn kind_to_str(x: Enum_CXCursorKind) -> String { + unsafe { clang_getCursorKindSpelling(x) }.into() } /// Convert a type kind to a static string. -pub fn type_to_str(x: Enum_CXTypeKind) -> &'static str { - match x { - CXType_Invalid => "Invalid", - CXType_Unexposed => "Unexposed", - CXType_Void => "Void", - CXType_Bool => "Bool", - CXType_Char_U => "Char_U", - CXType_UChar => "UChar", - CXType_Char16 => "Char16", - CXType_Char32 => "Char32", - CXType_UShort => "UShort", - CXType_UInt => "UInt", - CXType_ULong => "ULong", - CXType_ULongLong => "ULongLong", - CXType_UInt128 => "UInt128", - CXType_Char_S => "Char_S", - CXType_SChar => "SChar", - CXType_WChar => "WChar", - CXType_Short => "Short", - CXType_Int => "Int", - CXType_Long => "Long", - CXType_LongLong => "LongLong", - CXType_Int128 => "Int128", - CXType_Float => "Float", - CXType_Double => "Double", - CXType_LongDouble => "LongDouble", - CXType_NullPtr => "NullPtr", - CXType_Overload => "Overload", - CXType_Dependent => "Dependent", - CXType_ObjCId => "ObjCId", - CXType_ObjCClass => "ObjCClass", - CXType_ObjCSel => "ObjCSel", - // CXType_FirstBuiltin => "FirstBuiltin", - // CXType_LastBuiltin => "LastBuiltin", - CXType_Complex => "Complex", - CXType_Pointer => "Pointer", - CXType_BlockPointer => "BlockPointer", - CXType_LValueReference => "LValueReference", - CXType_RValueReference => "RValueReference", - CXType_Record => "Record", - CXType_Enum => "Enum", - CXType_Typedef => "Typedef", - CXType_ObjCInterface => "ObjCInterface", - CXType_ObjCObjectPointer => "ObjCObjectPointer", - CXType_FunctionNoProto => "FunctionNoProto", - CXType_FunctionProto => "FunctionProto", - CXType_ConstantArray => "ConstantArray", - CXType_Vector => "Vector", - CXType_IncompleteArray => "IncompleteArray", - CXType_VariableArray => "VariableArray", - CXType_DependentSizedArray => "DependentSizedArray", - CXType_MemberPointer => "MemberPointer", - #[cfg(not(feature="llvm_stable"))] - CXType_Auto => "Auto", - #[cfg(not(feature="llvm_stable"))] - CXType_Elaborated => "Elaborated", - _ => "?", - } +pub fn type_to_str(x: Enum_CXTypeKind) -> String { + unsafe { clang_getTypeKindSpelling(x).into() } } /// Dump the Clang AST to stdout for debugging purposes. |