diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-12 07:40:41 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-12 07:40:41 +0000 |
commit | e9fba573bd9433b89a12f747f2c4ccfa490a79cb (patch) | |
tree | c590019021699ccd00bf99512932e0f8212efc75 /lib/Driver/Types.cpp | |
parent | 644eade617a4e2e665455accf18c455e8d025699 (diff) |
Driver: Add information on Driver input/temporary types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66781 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Types.cpp')
-rw-r--r-- | lib/Driver/Types.cpp | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/lib/Driver/Types.cpp b/lib/Driver/Types.cpp new file mode 100644 index 0000000000..a8eabeaaca --- /dev/null +++ b/lib/Driver/Types.cpp @@ -0,0 +1,125 @@ +//===--- Types.cpp - Driver input & temporary type information ----------*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "clang/Driver/Types.h" + +#include <string.h> +#include <cassert> + +using namespace clang; +using namespace clang::driver; +using namespace clang::driver::types; + +struct Info { + const char *Name; + const char *Flags; + const char *TempSuffix; + ID PreprocessedType; +}; + +static Info TypeInfos[] = { +#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) \ + { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, }, +#include "clang/Driver/Types.def" +#undef TYPE +}; +static const unsigned numTypes = sizeof(TypeInfos) / sizeof(TypeInfos[0]); + +static Info &getInfo(unsigned id) { + assert(id > 0 && id - 1 < numTypes && "Invalid Type ID."); + return TypeInfos[id - 1]; +} + +const char *types::getTypeName(ID Id) { + return getInfo(Id).Name; +} + +types::ID types::getPreprocessedType(ID Id) { + return getInfo(Id).PreprocessedType; +} + +const char *types::getTypeTempSuffix(ID Id) { + return getInfo(Id).TempSuffix; +} + +bool types::onlyAssembleType(ID Id) { + return strchr(getInfo(Id).Flags, 'a'); +} + +bool types::onlyPrecompileType(ID Id) { + return strchr(getInfo(Id).Flags, 'p'); +} + +bool types::canTypeBeUserSpecified(ID Id) { + return strchr(getInfo(Id).Flags, 'u'); +} + +bool types::appendSuffixForType(ID Id) { + return strchr(getInfo(Id).Flags, 'A'); +} + +types::ID types::lookupTypeForExtension(const char *Ext) { + unsigned N = strlen(Ext); + + switch (N) { + case 1: + if (memcmp(Ext, "c", 1) == 0) return TY_C; + if (memcmp(Ext, "i", 1) == 0) return TY_PP_C; + if (memcmp(Ext, "m", 1) == 0) return TY_ObjC; + if (memcmp(Ext, "M", 1) == 0) return TY_ObjCXX; + if (memcmp(Ext, "h", 1) == 0) return TY_CHeader; + if (memcmp(Ext, "C", 1) == 0) return TY_CXX; + if (memcmp(Ext, "H", 1) == 0) return TY_CXXHeader; + if (memcmp(Ext, "f", 1) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "F", 1) == 0) return TY_Fortran; + if (memcmp(Ext, "s", 1) == 0) return TY_PP_Asm; + if (memcmp(Ext, "S", 1) == 0) return TY_Asm; + case 2: + if (memcmp(Ext, "ii", 2) == 0) return TY_PP_CXX; + if (memcmp(Ext, "mi", 2) == 0) return TY_PP_ObjC; + if (memcmp(Ext, "mm", 2) == 0) return TY_ObjCXX; + if (memcmp(Ext, "cc", 2) == 0) return TY_CXX; + if (memcmp(Ext, "cc", 2) == 0) return TY_CXX; + if (memcmp(Ext, "cp", 2) == 0) return TY_CXX; + if (memcmp(Ext, "hh", 2) == 0) return TY_CXXHeader; + break; + case 3: + if (memcmp(Ext, "ads", 3) == 0) return TY_Ada; + if (memcmp(Ext, "adb", 3) == 0) return TY_Ada; + if (memcmp(Ext, "cxx", 3) == 0) return TY_CXX; + if (memcmp(Ext, "cpp", 3) == 0) return TY_CXX; + if (memcmp(Ext, "CPP", 3) == 0) return TY_CXX; + if (memcmp(Ext, "cXX", 3) == 0) return TY_CXX; + if (memcmp(Ext, "for", 3) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "FOR", 3) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "fpp", 3) == 0) return TY_Fortran; + if (memcmp(Ext, "FPP", 3) == 0) return TY_Fortran; + if (memcmp(Ext, "f90", 3) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "f95", 3) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "F90", 3) == 0) return TY_Fortran; + if (memcmp(Ext, "F95", 3) == 0) return TY_Fortran; + if (memcmp(Ext, "mii", 3) == 0) return TY_PP_ObjCXX; + break; + } + + return TY_INVALID; +} + +types::ID types::lookupTypeForTypeSpecifier(const char *Name) { + unsigned N = strlen(Name); + + for (unsigned i=0; i<numTypes; ++i) { + types::ID Id = (types::ID) (i + 1); + if (canTypeBeUserSpecified(Id) && + memcmp(Name, getInfo(Id).Name, N) == 0) + return Id; + } + + return TY_INVALID; +} |