Skip to content

Commit df0dade

Browse files
authored
Hack to print OCaml values as pointers or integers (#3)
1 parent 9414ef9 commit df0dade

File tree

19 files changed

+396
-0
lines changed

19 files changed

+396
-0
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
11071107
CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
11081108
CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
11091109
CanQualType ObjCBuiltinBoolTy;
1110+
CanQualType OCamlValueTy;
11101111
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
11111112
CanQualType SingletonId;
11121113
#include "clang/Basic/OpenCLImageTypes.def"

clang/include/clang/AST/BuiltinTypes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ FLOATING_TYPE(Ibm128, Ibm128Ty)
226226
// This is the type of C++0x 'nullptr'.
227227
BUILTIN_TYPE(NullPtr, NullPtrTy)
228228

229+
// OCaml values
230+
BUILTIN_TYPE(OCamlValue, OCamlValueTy)
231+
229232
// The primitive Objective C 'id' type. The user-visible 'id'
230233
// type is a typedef of an ObjCObjectPointerType to an
231234
// ObjCObjectType with this as its base. In fact, this only ever

clang/lib/AST/ASTContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
14411441

14421442
ObjCSuperType = QualType();
14431443

1444+
InitBuiltinType(OCamlValueTy, BuiltinType::OCamlValue);
1445+
14441446
// void * type
14451447
if (LangOpts.OpenCLGenericAddressSpace) {
14461448
auto Q = VoidTy.getQualifiers();
@@ -2040,6 +2042,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
20402042
case Type::Builtin:
20412043
switch (cast<BuiltinType>(T)->getKind()) {
20422044
default: llvm_unreachable("Unknown builtin type!");
2045+
case BuiltinType::OCamlValue:
2046+
Width = 64;
2047+
Align = 64;
2048+
break;
20432049
case BuiltinType::Void:
20442050
// GCC extension: alignof(void) = 8 bits.
20452051
Width = 0;
@@ -8038,6 +8044,9 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
80388044
return ' ';
80398045
}
80408046

8047+
case BuiltinType::OCamlValue:
8048+
llvm_unreachable("@encoding OCaml value type");
8049+
80418050
case BuiltinType::ObjCId:
80428051
case BuiltinType::ObjCClass:
80438052
case BuiltinType::ObjCSel:

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11338,6 +11338,7 @@ EvaluateBuiltinClassifyType(QualType T, const LangOptions &LangOpts) {
1133811338

1133911339
case BuiltinType::NullPtr:
1134011340

11341+
case BuiltinType::OCamlValue:
1134111342
case BuiltinType::ObjCId:
1134211343
case BuiltinType::ObjCClass:
1134311344
case BuiltinType::ObjCSel:

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,6 +3064,9 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
30643064
Out << "Dn";
30653065
break;
30663066

3067+
case BuiltinType::OCamlValue:
3068+
llvm_unreachable("mangling an OCaml value type");
3069+
30673070
#define BUILTIN_TYPE(Id, SingletonId)
30683071
#define PLACEHOLDER_TYPE(Id, SingletonId) \
30693072
case BuiltinType::Id:

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,6 +2415,9 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
24152415
case BuiltinType::Dependent:
24162416
llvm_unreachable("placeholder types shouldn't get to name mangling");
24172417

2418+
case BuiltinType::OCamlValue:
2419+
llvm_unreachable("cannot mangle OCaml value types");
2420+
24182421
case BuiltinType::ObjCId:
24192422
mangleArtificialTagType(TTK_Struct, "objc_object");
24202423
break;

clang/lib/AST/NSAPI.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
459459
case BuiltinType::Float128:
460460
case BuiltinType::Ibm128:
461461
case BuiltinType::NullPtr:
462+
case BuiltinType::OCamlValue:
462463
case BuiltinType::ObjCClass:
463464
case BuiltinType::ObjCId:
464465
case BuiltinType::ObjCSel:

clang/lib/AST/Type.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,6 +3106,8 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
31063106
return "<ARC unbridged cast type>";
31073107
case BuiltinFn:
31083108
return "<builtin fn type>";
3109+
case OCamlValue:
3110+
return "ocaml_value";
31093111
case ObjCId:
31103112
return "id";
31113113
case ObjCClass:
@@ -4257,6 +4259,7 @@ bool Type::canHaveNullability(bool ResultIfUnknown) const {
42574259
return ResultIfUnknown;
42584260

42594261
case BuiltinType::Void:
4262+
case BuiltinType::OCamlValue:
42604263
case BuiltinType::ObjCId:
42614264
case BuiltinType::ObjCClass:
42624265
case BuiltinType::ObjCSel:

clang/lib/AST/TypeLoc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
402402
case BuiltinType::UnknownAny:
403403
case BuiltinType::ARCUnbridgedCast:
404404
case BuiltinType::PseudoObject:
405+
case BuiltinType::OCamlValue:
405406
case BuiltinType::ObjCId:
406407
case BuiltinType::ObjCClass:
407408
case BuiltinType::ObjCSel:

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
844844
case BuiltinType::Long:
845845
case BuiltinType::WChar_S:
846846
case BuiltinType::LongLong:
847+
case BuiltinType::OCamlValue:
847848
Encoding = llvm::dwarf::DW_ATE_signed;
848849
break;
849850
case BuiltinType::Bool:

0 commit comments

Comments
 (0)