Implement a shebang support in cling.
This commit is contained in:
parent
a1781be78f
commit
a415711407
20
test/Driver/Shebang.C
Normal file
20
test/Driver/Shebang.C
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/cling
|
||||
//------------------------------------------------------------------------------
|
||||
// CLING - the C++ LLVM-based InterpreterG :)
|
||||
//
|
||||
// This file is dual-licensed: you can choose to license it under the University
|
||||
// of Illinois Open Source License or the GNU Lesser General Public License. See
|
||||
// LICENSE.TXT for details.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// RUN: %cling %s 2>&1 | FileCheck %s
|
||||
|
||||
//CHECK-NOT: {{.*error|warning|note:.*}}
|
||||
float shebang = 1.0
|
||||
//CHECK: (float) 1.0
|
||||
extern "C" int printf(const char* fmt, ...);
|
||||
if(shebang == 1.0) {
|
||||
printf("I am executed\n"); // CHECK: I am executed
|
||||
}
|
||||
.q
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@ -52,13 +53,23 @@ int main( int argc, char **argv ) {
|
||||
// If we are not interactive we're supposed to parse files
|
||||
if (!Interactive) {
|
||||
for (size_t I = 0, N = Inputs.size(); I < N; ++I) {
|
||||
std::string line;
|
||||
if (!interp.lookupFileOrLibrary(Inputs[I]).empty())
|
||||
line += ".x ";
|
||||
|
||||
line += Inputs[I];
|
||||
std::string cmd;
|
||||
cling::Interpreter::CompilationResult compRes;
|
||||
ui.getMetaProcessor()->process(line.c_str(), compRes, 0);
|
||||
if (!interp.lookupFileOrLibrary(Inputs[I]).empty()) {
|
||||
std::ifstream infile(interp.lookupFileOrLibrary(Inputs[I]));
|
||||
std::string line;
|
||||
std::getline(infile, line);
|
||||
if (line[0] == '#' && line[1] == '!') {
|
||||
while(std::getline(infile, line)) {
|
||||
ui.getMetaProcessor()->process(line.c_str(), compRes, 0);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else
|
||||
cmd += ".x ";
|
||||
}
|
||||
cmd += Inputs[I];
|
||||
ui.getMetaProcessor()->process(cmd.c_str(), compRes, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user