blob: 70a4eadda2f958c2a00439dea77613284dd9fa9d [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObjectScript.cpp ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CommandObjectScript.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Jim Ingham84cdc152010-06-15 19:49:27 +000016#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017
18#include "lldb/Interpreter/CommandReturnObject.h"
19#include "lldb/Interpreter/ScriptInterpreter.h"
Caroline Tice0aa2e552011-01-14 00:29:16 +000020#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021
22using namespace lldb;
23using namespace lldb_private;
24
25//-------------------------------------------------------------------------
26// CommandObjectScript
27//-------------------------------------------------------------------------
28
Greg Clayton238c0a12010-09-18 01:14:36 +000029CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
30 CommandObject (interpreter,
31 "script",
Caroline Ticec1ad82e2010-09-07 22:38:08 +000032 "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.",
33 "script [<script-expression-for-evaluation>]"),
Caroline Tice0aa2e552011-01-14 00:29:16 +000034 m_script_lang (script_lang)
Chris Lattner24943d22010-06-08 16:52:24 +000035{
36}
37
38CommandObjectScript::~CommandObjectScript ()
39{
40}
41
42bool
43CommandObjectScript::ExecuteRawCommandString
44(
45 const char *command,
Chris Lattner24943d22010-06-08 16:52:24 +000046 CommandReturnObject &result
47)
48{
Caroline Tice0aa2e552011-01-14 00:29:16 +000049 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter ();
Chris Lattner24943d22010-06-08 16:52:24 +000050
51 if (script_interpreter == NULL)
52 {
Greg Clayton5d187e52011-01-08 20:28:42 +000053 result.AppendError("no script interpreter");
Chris Lattner24943d22010-06-08 16:52:24 +000054 result.SetStatus (eReturnStatusFailed);
55 }
56
Johnny Chen60dde642010-07-30 22:33:14 +000057 if (command == NULL || command[0] == '\0') {
Greg Clayton238c0a12010-09-18 01:14:36 +000058 script_interpreter->ExecuteInterpreterLoop ();
Johnny Chen60dde642010-07-30 22:33:14 +000059 result.SetStatus (eReturnStatusSuccessFinishNoResult);
60 return result.Succeeded();
61 }
62
63 // We can do better when reporting the status of one-liner script execution.
Greg Clayton238c0a12010-09-18 01:14:36 +000064 if (script_interpreter->ExecuteOneLine (command, &result))
Johnny Chen60dde642010-07-30 22:33:14 +000065 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +000066 else
Johnny Chen60dde642010-07-30 22:33:14 +000067 result.SetStatus(eReturnStatusFailed);
68
Chris Lattner24943d22010-06-08 16:52:24 +000069 return result.Succeeded();
70}
71
72bool
73CommandObjectScript::WantsRawCommandString()
74{
75 return true;
76}
77
78bool
79CommandObjectScript::Execute
80(
81 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000082 CommandReturnObject &result
83)
84{
Greg Clayton63094e02010-06-23 01:19:29 +000085 // everything should be handled in ExecuteRawCommandString
86 return false;
Chris Lattner24943d22010-06-08 16:52:24 +000087}
88