Skip to content

Commit 3176b35

Browse files
committed
[cling] Provide C value printer, adopted from Ruben De Smet!
Fixes root-project/cling#364 Fixes root-project/cling#419 Adapts the corresponding ctest
1 parent 68570ba commit 3176b35

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
#include "clang/Sema/Sema.h"
2323
#include "clang/Sema/SemaDiagnostic.h"
2424

25+
// Implements the CValueExtractionPrinter interface.
26+
extern "C" {
27+
CLING_LIB_EXPORT
28+
void cling_SetValueNoAlloc(void* /*cling::Value* V*/) {}
29+
CLING_LIB_EXPORT
30+
void cling_SetValueWithAlloc(void* /*cling::Value* V*/) {}
31+
}
32+
2533
using namespace clang;
2634

2735
namespace cling {
@@ -436,6 +444,10 @@ namespace {
436444
return VSError(m_Sema, E, "cling::runtime::gCling");
437445
if (!(NSD = utils::Lookup::Namespace(m_Sema, "internal", NSD)))
438446
return VSError(m_Sema, E, "cling::runtime::internal namespace");
447+
} else {
448+
// C, ObjC,...
449+
if (!(NSD = utils::Lookup::Namespace(m_Sema, "cling")))
450+
return VSError(m_Sema, E, "cling namespace");
439451
}
440452
LookupResult R(*m_Sema, &m_Context->Idents.get("setValueNoAlloc"),
441453
SourceLocation(), Sema::LookupOrdinaryName,

interpreter/cling/test/Driver/C.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
// Validate cling C mode.
1313

14-
// Fix value printing!
15-
1614
int printf(const char*,...);
1715
printf("CHECK 123 %p\n", gCling); // CHECK: CHECK 123
1816

19-
12 // expected-error {{ValueExtractionSynthesizer could not find: 'cling::runtime::internal::setValueNoAlloc'.}}
20-
21-
32 // expected-error {{ValueExtractionSynthesizer could not find: 'cling::runtime::internal::setValueNoAlloc'.}}
17+
int i = 1 // CHECK: (int) 1
18+
sizeof(int) // CHECK: (unsigned long) 4
19+
int x = sizeof(int);
20+
printf("CHECK %d\n", x); // CHECK: CHECK 4
2221

22+
// expected-no-diagnostics
2323
.q

0 commit comments

Comments
 (0)