1 //===--- OpenMPKinds.cpp - Token Kinds Support ----------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// \file 10 /// \brief This file implements the OpenMP enum and support functions. 11 /// 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/Basic/OpenMPKinds.h" 15 #include "clang/Basic/IdentifierTable.h" 16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/ADT/StringSwitch.h" 18 #include "llvm/Support/ErrorHandling.h" 19 #include <cassert> 20 21 using namespace clang; 22 23 OpenMPDirectiveKind clang::getOpenMPDirectiveKind(StringRef Str) { 24 return llvm::StringSwitch<OpenMPDirectiveKind>(Str) 25 #define OPENMP_DIRECTIVE(Name) \ 26 .Case(#Name, OMPD_##Name) 27 #include "clang/Basic/OpenMPKinds.def" 28 .Default(OMPD_unknown); 29 } 30 31 const char *clang::getOpenMPDirectiveName(OpenMPDirectiveKind Kind) { 32 assert(Kind < NUM_OPENMP_DIRECTIVES); 33 switch (Kind) { 34 case OMPD_unknown: 35 return "unknown"; 36 #define OPENMP_DIRECTIVE(Name) \ 37 case OMPD_##Name : return #Name; 38 #include "clang/Basic/OpenMPKinds.def" 39 case NUM_OPENMP_DIRECTIVES: 40 break; 41 } 42 llvm_unreachable("Invalid OpenMP directive kind"); 43 } 44 45 OpenMPClauseKind clang::getOpenMPClauseKind(StringRef Str) { 46 return llvm::StringSwitch<OpenMPClauseKind>(Str) 47 #define OPENMP_CLAUSE(Name, Class) \ 48 .Case(#Name, OMPC_##Name) 49 #include "clang/Basic/OpenMPKinds.def" 50 .Default(OMPC_unknown); 51 } 52 53 const char *clang::getOpenMPClauseName(OpenMPClauseKind Kind) { 54 assert(Kind < NUM_OPENMP_CLAUSES); 55 switch (Kind) { 56 case OMPC_unknown: 57 return "unknown"; 58 #define OPENMP_CLAUSE(Name, Class) \ 59 case OMPC_##Name : return #Name; 60 #include "clang/Basic/OpenMPKinds.def" 61 case OMPC_threadprivate: 62 return "threadprivate or thread local"; 63 case NUM_OPENMP_CLAUSES: 64 break; 65 } 66 llvm_unreachable("Invalid OpenMP clause kind"); 67 } 68 69 unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, 70 StringRef Str) { 71 switch (Kind) { 72 case OMPC_default: 73 return llvm::StringSwitch<OpenMPDefaultClauseKind>(Str) 74 #define OPENMP_DEFAULT_KIND(Name) \ 75 .Case(#Name, OMPC_DEFAULT_##Name) 76 #include "clang/Basic/OpenMPKinds.def" 77 .Default(OMPC_DEFAULT_unknown); 78 case OMPC_unknown: 79 case OMPC_threadprivate: 80 case OMPC_private: 81 case NUM_OPENMP_CLAUSES: 82 break; 83 } 84 llvm_unreachable("Invalid OpenMP simple clause kind"); 85 } 86 87 const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, 88 unsigned Type) { 89 switch (Kind) { 90 case OMPC_default: 91 switch (Type) { 92 case OMPC_DEFAULT_unknown: 93 return "unknown"; 94 #define OPENMP_DEFAULT_KIND(Name) \ 95 case OMPC_DEFAULT_##Name : return #Name; 96 #include "clang/Basic/OpenMPKinds.def" 97 } 98 llvm_unreachable("Invalid OpenMP 'default' clause type"); 99 case OMPC_unknown: 100 case OMPC_threadprivate: 101 case OMPC_private: 102 case NUM_OPENMP_CLAUSES: 103 break; 104 } 105 llvm_unreachable("Invalid OpenMP simple clause kind"); 106 } 107 108 bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, 109 OpenMPClauseKind CKind) { 110 assert(DKind < NUM_OPENMP_DIRECTIVES); 111 assert(CKind < NUM_OPENMP_CLAUSES); 112 switch (DKind) { 113 case OMPD_parallel: 114 switch (CKind) { 115 #define OPENMP_PARALLEL_CLAUSE(Name) \ 116 case OMPC_##Name: return true; 117 #include "clang/Basic/OpenMPKinds.def" 118 default: 119 break; 120 } 121 break; 122 case OMPD_unknown: 123 case OMPD_threadprivate: 124 case OMPD_task: 125 case NUM_OPENMP_DIRECTIVES: 126 break; 127 } 128 return false; 129 } 130