From: DeLesley Hutchins Date: Thu, 15 May 2014 22:07:41 +0000 (+0000) Subject: Thread Safety Analysis: fixes to SExpr pretty printing. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4415008e09aab84dd503ff0312589ee569522c3;p=clang Thread Safety Analysis: fixes to SExpr pretty printing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208924 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/Analyses/ThreadSafetyTIL.h b/include/clang/Analysis/Analyses/ThreadSafetyTIL.h index 93dc2ffcbf..dcb196f1fb 100644 --- a/include/clang/Analysis/Analyses/ThreadSafetyTIL.h +++ b/include/clang/Analysis/Analyses/ThreadSafetyTIL.h @@ -613,6 +613,8 @@ public: // The clang expression for this literal. const clang::Expr *clangExpr() const { return Cexpr; } + ValueType valueType() const { return ValType; } + template typename V::R_SExpr traverse(V &Visitor) { return Visitor.reduceLiteral(*this); } @@ -623,7 +625,7 @@ public: } private: - ValueType ValType; + const ValueType ValType; const clang::Expr *Cexpr; }; @@ -926,7 +928,12 @@ public: const clang::ValueDecl *clangValueDecl() const { return Cvdecl; } - StringRef slotName() const { return Cvdecl->getName(); } + StringRef slotName() const { + if (Cvdecl) + return Cvdecl->getName(); + else + return SlotName; + } template typename V::R_SExpr traverse(V &Visitor) { typename V::R_SExpr Nr = Visitor.traverse(Rec); diff --git a/include/clang/Analysis/Analyses/ThreadSafetyTraverse.h b/include/clang/Analysis/Analyses/ThreadSafetyTraverse.h index 7973e0b365..b28085ba3e 100644 --- a/include/clang/Analysis/Analyses/ThreadSafetyTraverse.h +++ b/include/clang/Analysis/Analyses/ThreadSafetyTraverse.h @@ -546,8 +546,89 @@ protected: SS << "_"; } + template + void printLiteralT(LiteralT *E, StreamType &SS) { + SS << E->value(); + } + void printLiteral(Literal *E, StreamType &SS) { - SS << getSourceLiteralString(E->clangExpr()); + if (E->clangExpr()) + SS << getSourceLiteralString(E->clangExpr()); + else { + ValueType VT = E->valueType(); + switch (VT.Base) { + case ValueType::BT_Void: { + SS << "void"; + return; + } + case ValueType::BT_Bool: { + if (reinterpret_cast*>(E)->value()) + SS << "true"; + else + SS << "false"; + return; + } + case ValueType::BT_Int: { + switch (VT.Size) { + case ValueType::ST_8: + if (VT.Signed) + printLiteralT(reinterpret_cast*>(E), SS); + else + printLiteralT(reinterpret_cast*>(E), SS); + return; + case ValueType::ST_16: + if (VT.Signed) + printLiteralT(reinterpret_cast*>(E), SS); + else + printLiteralT(reinterpret_cast*>(E), SS); + return; + case ValueType::ST_32: + if (VT.Signed) + printLiteralT(reinterpret_cast*>(E), SS); + else + printLiteralT(reinterpret_cast*>(E), SS); + return; + case ValueType::ST_64: + if (VT.Signed) + printLiteralT(reinterpret_cast*>(E), SS); + else + printLiteralT(reinterpret_cast*>(E), SS); + return; + default: + break; + } + break; + } + case ValueType::BT_Float: { + switch (VT.Size) { + case ValueType::ST_32: + printLiteralT(reinterpret_cast*>(E), SS); + return; + case ValueType::ST_64: + printLiteralT(reinterpret_cast*>(E), SS); + return; + default: + break; + } + break; + } + case ValueType::BT_String: { + SS << "\""; + printLiteralT(reinterpret_cast*>(E), SS); + SS << "\""; + return; + } + case ValueType::BT_Pointer: { + SS << "#ptr"; + return; + } + case ValueType::BT_ValueRef: { + SS << "#vref"; + return; + } + } + } + SS << "#lit"; } void printLiteralPtr(LiteralPtr *E, StreamType &SS) { @@ -575,6 +656,7 @@ protected: switch (sugared) { default: SS << "\\("; // Lambda + break; case 1: SS << "("; // Slot declarations break; @@ -589,8 +671,10 @@ protected: SExpr *B = E->body(); if (B && B->opcode() == COP_Function) self()->printFunction(cast(B), SS, 2); - else + else { + SS << ")"; self()->printSExpr(B, SS, Prec_Decl); + } } void printSFunction(SFunction *E, StreamType &SS) { @@ -769,7 +853,7 @@ protected: } void printIdentifier(Identifier *E, StreamType &SS) { - SS << "$" << E->name(); + SS << E->name(); } void printIfThenElse(IfThenElse *E, StreamType &SS) { @@ -786,7 +870,7 @@ protected: printVariable(E->variableDecl(), SS, true); SS << " = "; printSExpr(E->variableDecl()->definition(), SS, Prec_Decl-1); - SS << ";"; + SS << "; "; printSExpr(E->body(), SS, Prec_Decl-1); } };