Removed "VALID" after address output, fixes roottest. Various fixes based on comments after second round.

This commit is contained in:
Boris Perovic 2015-08-18 17:48:45 +02:00 committed by sftnight
parent 2d317b983d
commit 800c644352
7 changed files with 59 additions and 52 deletions

View File

@ -10,7 +10,6 @@
#define CLING_RUNTIME_PRINT_VALUE_H
#include <string>
#include "Value.h"
namespace cling {
@ -59,6 +58,7 @@ namespace cling {
// std::string
std::string printValue(const std::string &val);
class Value;
// cling::Value
std::string printValue(const Value &value);
@ -99,7 +99,7 @@ namespace cling {
for (int i = 0; i < N; ++i) {
str = str + printValue(obj[i]);
if (i < N-1) str = str + ", ";
if (i < N-1) str += ", ";
}
return str + " }";

View File

@ -272,16 +272,16 @@ namespace cling {
}
namespace valuePrinterInternal {
std::string printType_New(const Value& V);
std::string printValue_New(const Value& V);
std::string printTypeInternal(const Value& V);
std::string printValueInternal(const Value& V);
} // end namespace valuePrinterInternal
void Value::print(llvm::raw_ostream& Out) const {
// Get the default type string representation
std::string typeStr = cling::valuePrinterInternal::printType_New(*this);
std::string typeStr = cling::valuePrinterInternal::printTypeInternal(*this);
// Get the value string representation, by printValue() method overloading
std::string valueStr = cling::valuePrinterInternal::printValue_New(*this);
std::string valueStr = cling::valuePrinterInternal::printValueInternal(*this);
// Print the type and the value:
Out << typeStr + " " + valueStr << "\n";

View File

@ -64,8 +64,8 @@ extern "C" void cling_PrintValue(void* /*cling::Value**/ V) {
// the results in pipes (Savannah #99234).
//llvm::raw_fd_ostream outs (STDOUT_FILENO, /*ShouldClose*/false);
//std::string typeStr = printType_New(*value);
//std::string valueStr = printValue_New(*value);
//std::string typeStr = printTypeInternal(*value);
//std::string valueStr = printValueInternal(*value);
}
// Checking whether the pointer points to a valid memory location
@ -348,7 +348,7 @@ static std::string printUnpackedClingValue(const Value& V) {
if(Ty-> isNullPtrType()) {
// special case nullptr_t
strm << "<<<NULL>>>";
strm << "nullptr";
} else if (Ty->isEnumeralType()) {
// special case enum printing, using compiled information
strm << printEnumValue(V);
@ -369,42 +369,52 @@ static std::string printUnpackedClingValue(const Value& V) {
namespace cling {
std::string printValue(void* ptr) {
std::ostringstream strm;
if (!ptr) {
strm << "<<<NULL>>>";
return "nullptr";
} else {
std::ostringstream strm;
strm << ptr;
if (isAddressValid(ptr))
strm << " VALID";
else
strm << " INVALID";
if (!isAddressValid(ptr))
strm << " <invalid memory address>";
return strm.str();
}
return strm.str();
}
// Bool
std::string printValue(bool val) {
std::ostringstream strm;
strm << std::boolalpha;
strm << val;
strm << std::noboolalpha;
return strm.str();
if (val) {
return "true";
} else {
return "false";
}
}
// Chars
std::string printValue(char val) {
static std::string printChar(signed char val, bool apostrophe){
std::ostringstream strm;
if (val > 0x1F && val < 0x7F) strm << "'" << val << "'";
else strm << "0x" << std::hex << (int) val << std::dec;
if (val > 0x1F && val < 0x7F) {
if (apostrophe)
strm << "'";
strm << val;
if (apostrophe)
strm << "'";
} else {
strm << "0x" << std::hex << (int) val;
}
return strm.str();
}
std::string printValue(signed char val) {
return printValue((char) val);
std::string printValue(char val) {
return printChar(val, true);
}
std::string printValue(const unsigned char val) {
return printValue((char) val);
std::string printValue(signed char val) {
return printChar(val, true);
}
std::string printValue(unsigned char val) {
return printChar(val, true);
}
// Ints
@ -458,13 +468,13 @@ namespace cling {
std::string printValue(float val) {
std::ostringstream strm;
strm << val;
strm << std::showpoint << val << "f";
return strm.str();
}
std::string printValue(double val) {
std::ostringstream strm;
strm << val;
strm << std::showpoint << val;
return strm.str();
}
@ -476,17 +486,18 @@ namespace cling {
// Char pointers
std::string printValue(const char *const val) {
std::ostringstream strm;
if (!val) {
strm << "<<<NULL>>>";
return "nullptr";
} else {
std::ostringstream strm;
strm << "\"";
for (const char *cobj = val; *cobj != 0; ++cobj) {
strm << *cobj;
// 10000 limit to prevent potential printing of the whole RAM / inf loop
for (const char *cobj = val; *cobj != 0 && cobj-val < 10000; ++cobj) {
strm << printChar(*cobj, false);
}
strm << "\"";
return strm.str();
}
return strm.str();
}
std::string printValue(char *val) {
@ -495,11 +506,7 @@ namespace cling {
// std::string
std::string printValue(const std::string & val) {
std::ostringstream strm;
strm << "\"";
strm << val;
strm << "\"";
return strm.str();
return "\"" + val + "\"";
}
std::string printValue(const Value &value) {
@ -525,7 +532,7 @@ namespace cling {
namespace valuePrinterInternal {
std::string printType_New(const Value& V) {
std::string printTypeInternal(const Value& V) {
using namespace clang;
std::ostringstream strm;
clang::ASTContext& C = V.getASTContext();
@ -549,7 +556,7 @@ namespace valuePrinterInternal {
return strm.str();
}
std::string printValue_New(const Value& V) {
std::string printValueInternal(const Value& V) {
static bool includedRuntimePrintValue = false; // initialized only once as a static function variable
// Include "RuntimePrintValue.h" only on the first printing.
// This keeps the interpreter lightweight and reduces the startup time.

View File

@ -36,7 +36,7 @@ gCling->evaluate("bool a = [](){return true;};", V);
V // CHECK-NEXT: (cling::Value &) boxes [(bool) true]
gCling->evaluate("auto a = 12.3; a;", V);
V // CHECK: (cling::Value &) boxes [(double) 12.3]
V // CHECK: (cling::Value &) boxes [(double) 12.3000]
long LongV = 17;
gCling->evaluate("LongV;", V);
@ -44,20 +44,20 @@ V // CHECK: (cling::Value &) boxes [(long) 17]
int* IntP = (int*)0x12;
gCling->evaluate("IntP;", V);
V // CHECK: (cling::Value &) boxes [(int *) 0x12 INVALID]
V // CHECK: (cling::Value &) boxes [(int *) 0x12 <invalid memory address>]
cling::Value Result;
gCling->evaluate("V", Result);
// Here we check what happens for record type like cling::Value; they are returned by reference.
Result // CHECK: (cling::Value &) boxes [(cling::Value &) boxes [(int *) 0x12 INVALID]]
V // CHECK: (cling::Value &) boxes [(int *) 0x12 INVALID]
Result // CHECK: (cling::Value &) boxes [(cling::Value &) boxes [(int *) 0x12 <invalid memory address>]]
V // CHECK: (cling::Value &) boxes [(int *) 0x12 <invalid memory address>]
// Savannah #96277
gCling->evaluate("gCling->declare(\"double sin(double);\"); double one = sin(3.141/2);", V);
V // CHECK: (cling::Value &) boxes [(double) 1]
V // CHECK: (cling::Value &) boxes [(double) 1.00000]
gCling->process("double one = sin(3.141/2);", &V);
V // CHECK: (cling::Value &) boxes [(double) 1]
V // CHECK: (cling::Value &) boxes [(double) 1.00000]
one // CHECK: (double) 1
int one; // expected-error {{redefinition of 'one' with a different type: 'int' vs 'double'}} expected-note {{previous definition is here}}

View File

@ -59,7 +59,7 @@ class A {};
const clang::Decl* cl_A_in_NMP = lookup.findScope("N::M::P::A", diags);
cl_A_in_NMP
//CHECK: (const clang::Decl *) 0x{{[1-9a-f][0-9a-f]*}} VALID
//CHECK: (const clang::Decl *) 0x{{[1-9a-f][0-9a-f]*$}}
cast<clang::NamedDecl>(cl_A_in_NMP)->getQualifiedNameAsString().c_str()
//CHECK-NEXT: ({{[^)]+}}) "N::M::P::A"

View File

@ -11,7 +11,7 @@ int a = 12;
a // CHECK: (int) 12
const char* b = "b" // CHECK: (const char *) "b"
const char* n = 0 // CHECK: (const char *) <<<NULL>>
const char* n = 0 // CHECK: (const char *) nullptr
struct C {int d;} E = {22};
E // CHECK: (struct C &) @0x{{[0-9A-Fa-f]{6,12}.}}
@ -47,7 +47,7 @@ e2
// Arrays:
float farr[] = {0.,1.,2.,3.,4.,5.} // CHECK: (float [6]) { 0, 1, 2, 3, 4, 5 }
float farr[] = {0.,1.,2.,3.,4.,5.} // CHECK: (float [6]) { 0.00000f, 1.00000f, 2.00000f, 3.00000f, 4.00000f, 5.00000f }
std::string sarr[3] = {"A", "B", "C"} // CHECK: (std::string [3]) { "A", "B", "C" }
.rawInput

View File

@ -47,7 +47,7 @@ q // CHECK: (const int *) 0x123
// PR ROOT-5467
&A::someFunc // CHECK: (int (A::*)(float)) Function @0x{{[0-9a-f]+}}
nullptr // CHECK: (nullptr_t) <<<NULL>>>
nullptr // CHECK: (nullptr_t) nullptr
#include <unordered_set>
std::unordered_multiset<float> {1} // ROOT-7310