Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectSyntax.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 "CommandObjectSyntax.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Jim Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/Args.h" |
| 17 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | |
| 19 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 20 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 21 | #include "lldb/Interpreter/CommandObjectMultiword.h" |
| 22 | |
| 23 | using namespace lldb; |
| 24 | using namespace lldb_private; |
| 25 | |
| 26 | //------------------------------------------------------------------------- |
| 27 | // CommandObjectSyntax |
| 28 | //------------------------------------------------------------------------- |
| 29 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 30 | CommandObjectSyntax::CommandObjectSyntax (CommandInterpreter &interpreter) : |
| 31 | CommandObject (interpreter, |
| 32 | "syntax", |
| 33 | "Shows the correct syntax for a given debugger command.", |
| 34 | "syntax <command>") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | { |
| 36 | } |
| 37 | |
| 38 | CommandObjectSyntax::~CommandObjectSyntax() |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | |
| 43 | bool |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 44 | CommandObjectSyntax::Execute |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | ( |
| 46 | Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | CommandReturnObject &result |
| 48 | ) |
| 49 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | CommandObject::CommandMap::iterator pos; |
| 51 | CommandObject *cmd_obj; |
| 52 | const int argc = command.GetArgumentCount(); |
| 53 | |
| 54 | if (argc > 0) |
| 55 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame^] | 56 | cmd_obj = m_interpreter.GetCommandObject (command.GetArgumentAtIndex(0)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | bool all_okay = true; |
| 58 | for (int i = 1; i < argc; ++i) |
| 59 | { |
| 60 | std::string sub_command = command.GetArgumentAtIndex (i); |
| 61 | if (! cmd_obj->IsMultiwordObject()) |
| 62 | all_okay = false; |
| 63 | else |
| 64 | { |
| 65 | pos = ((CommandObjectMultiword *) cmd_obj)->m_subcommand_dict.find (sub_command); |
| 66 | if (pos != ((CommandObjectMultiword *) cmd_obj)->m_subcommand_dict.end()) |
| 67 | cmd_obj = pos->second.get(); |
| 68 | else |
| 69 | all_okay = false; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | if (all_okay && (cmd_obj != NULL)) |
| 74 | { |
| 75 | Stream &output_strm = result.GetOutputStream(); |
| 76 | if (cmd_obj->GetOptions() != NULL) |
| 77 | { |
| 78 | output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | output_strm.Printf ("(Try 'help %s' for more information on command options syntax.)\n", |
| 80 | cmd_obj->GetCommandName()); |
| 81 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax()); |
| 86 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 87 | } |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | std::string cmd_string; |
| 92 | command.GetCommandString (cmd_string); |
| 93 | result.AppendErrorWithFormat ("'%s' is not a known command.\n", cmd_string.c_str()); |
| 94 | result.AppendError ("Try 'help' to see a current list of commands."); |
| 95 | result.SetStatus (eReturnStatusFailed); |
| 96 | } |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | result.AppendError ("Must call 'syntax' with a valid command."); |
| 101 | result.SetStatus (eReturnStatusFailed); |
| 102 | } |
| 103 | |
| 104 | return result.Succeeded(); |
| 105 | } |