1 //===--- Types.cpp - Driver input & temporary type information ----------*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/Driver/Types.h"
12 #include "llvm/ADT/StringSwitch.h"
16 using namespace clang::driver
;
17 using namespace clang::driver::types
;
22 const char *TempSuffix
;
26 static const TypeInfo TypeInfos
[] = {
27 #define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) \
28 { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, },
29 #include "clang/Driver/Types.def"
32 static const unsigned numTypes
= sizeof(TypeInfos
) / sizeof(TypeInfos
[0]);
34 static const TypeInfo
&getInfo(unsigned id
) {
35 assert(id
> 0 && id
- 1 < numTypes
&& "Invalid Type ID.");
36 return TypeInfos
[id
- 1];
39 const char *types::getTypeName(ID Id
) {
40 return getInfo(Id
).Name
;
43 types::ID
types::getPreprocessedType(ID Id
) {
44 return getInfo(Id
).PreprocessedType
;
47 const char *types::getTypeTempSuffix(ID Id
) {
48 return getInfo(Id
).TempSuffix
;
51 bool types::onlyAssembleType(ID Id
) {
52 return strchr(getInfo(Id
).Flags
, 'a');
55 bool types::onlyPrecompileType(ID Id
) {
56 return strchr(getInfo(Id
).Flags
, 'p');
59 bool types::canTypeBeUserSpecified(ID Id
) {
60 return strchr(getInfo(Id
).Flags
, 'u');
63 bool types::appendSuffixForType(ID Id
) {
64 return strchr(getInfo(Id
).Flags
, 'A');
67 bool types::canLipoType(ID Id
) {
68 return (Id
== TY_Nothing
||
73 bool types::isAcceptedByClang(ID Id
) {
79 case TY_C
: case TY_PP_C
:
81 case TY_ObjC
: case TY_PP_ObjC
:
82 case TY_CXX
: case TY_PP_CXX
:
83 case TY_ObjCXX
: case TY_PP_ObjCXX
:
84 case TY_CHeader
: case TY_PP_CHeader
:
85 case TY_ObjCHeader
: case TY_PP_ObjCHeader
:
86 case TY_CXXHeader
: case TY_PP_CXXHeader
:
87 case TY_ObjCXXHeader
: case TY_PP_ObjCXXHeader
:
89 case TY_LLVM_IR
: case TY_LLVM_BC
:
94 bool types::isOnlyAcceptedByClang(ID Id
) {
102 case TY_RewrittenObjC
:
107 bool types::isObjC(ID Id
) {
112 case TY_ObjC
: case TY_PP_ObjC
:
113 case TY_ObjCXX
: case TY_PP_ObjCXX
:
114 case TY_ObjCHeader
: case TY_PP_ObjCHeader
:
115 case TY_ObjCXXHeader
: case TY_PP_ObjCXXHeader
:
120 bool types::isCXX(ID Id
) {
125 case TY_CXX
: case TY_PP_CXX
:
126 case TY_ObjCXX
: case TY_PP_ObjCXX
:
127 case TY_CXXHeader
: case TY_PP_CXXHeader
:
128 case TY_ObjCXXHeader
: case TY_PP_ObjCXXHeader
:
133 types::ID
types::lookupTypeForExtension(const char *Ext
) {
134 return llvm::StringSwitch
<types::ID
>(Ext
)
138 .Case("M", TY_ObjCXX
)
139 .Case("h", TY_CHeader
)
141 .Case("H", TY_CXXHeader
)
142 .Case("f", TY_PP_Fortran
)
143 .Case("F", TY_Fortran
)
144 .Case("s", TY_PP_Asm
)
146 .Case("ii", TY_PP_CXX
)
147 .Case("mi", TY_PP_ObjC
)
148 .Case("mm", TY_ObjCXX
)
149 .Case("bc", TY_LLVM_BC
)
154 .Case("hh", TY_CXXHeader
)
155 .Case("ll", TY_LLVM_IR
)
156 .Case("hpp", TY_CXXHeader
)
166 .Case("for", TY_PP_Fortran
)
167 .Case("FOR", TY_PP_Fortran
)
168 .Case("fpp", TY_Fortran
)
169 .Case("FPP", TY_Fortran
)
170 .Case("f90", TY_PP_Fortran
)
171 .Case("f95", TY_PP_Fortran
)
172 .Case("F90", TY_Fortran
)
173 .Case("F95", TY_Fortran
)
174 .Case("mii", TY_PP_ObjCXX
)
175 .Default(TY_INVALID
);
178 types::ID
types::lookupTypeForTypeSpecifier(const char *Name
) {
179 unsigned N
= strlen(Name
);
181 for (unsigned i
=0; i
<numTypes
; ++i
) {
182 types::ID Id
= (types::ID
) (i
+ 1);
183 if (canTypeBeUserSpecified(Id
) &&
184 memcmp(Name
, getInfo(Id
).Name
, N
+ 1) == 0)
191 // FIXME: Why don't we just put this list in the defs file, eh.
193 unsigned types::getNumCompilationPhases(ID Id
) {
198 if (getPreprocessedType(Id
) != TY_INVALID
)
201 if (onlyAssembleType(Id
))
202 return N
+ 2; // assemble, link
203 if (onlyPrecompileType(Id
))
204 return N
+ 1; // precompile
206 return N
+ 3; // compile, assemble, link
209 phases::ID
types::getCompilationPhase(ID Id
, unsigned N
) {
210 assert(N
< getNumCompilationPhases(Id
) && "Invalid index.");
215 if (getPreprocessedType(Id
) != TY_INVALID
) {
217 return phases::Preprocess
;
221 if (onlyAssembleType(Id
))
222 return N
== 0 ? phases::Assemble
: phases::Link
;
224 if (onlyPrecompileType(Id
))
225 return phases::Precompile
;
228 return phases::Compile
;
230 return phases::Assemble
;
235 ID
types::lookupCXXTypeForCType(ID Id
) {
241 return types::TY_CXX
;
243 return types::TY_PP_CXX
;
244 case types::TY_CHeader
:
245 return types::TY_CXXHeader
;
246 case types::TY_PP_CHeader
:
247 return types::TY_PP_CXXHeader
;