1 /* 2 Copyright (C) 1998,199 T. Scott Dattalo 3 4 This file is part of gpsim. 5 6 gpsim is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 gpsim is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with gpsim; see the file COPYING. If not, write to 18 the Free Software Foundation, 59 Temple Place - Suite 330, 19 Boston, MA 02111-1307, USA. */ 20 21 #if !defined (__COMMAND_H_) 22 #define __COMMAND_H_ 23 #include <string> 24 #include <list> 25 using namespace std; 26 #include <unistd.h> 27 #include <glib.h> 28 #include "misc.h" 29 #include "../src/errors.h" 30 #include "../src/expr.h" 31 #include "../src/gpsim_def.h" 32 33 class Processor; 34 35 enum COMMAND_MODES 36 { 37 NO_COMMAND, 38 COMMAND_PENDING, 39 COMMAND_ERROR 40 }; 41 42 // Token types for command options 43 #define OPT_TT_BITFLAG 1 // 44 #define OPT_TT_NUMERIC 2 // indicates that a numeric parameter 45 // is associated with the option 46 #define OPT_TT_STRING 3 // indicates that a string parameter 47 // is associated with the option 48 #define OPT_TT_SUBTYPE 4 // indicates that this command can 49 // be subtyped (e.g. the stimulus command 50 // is subtyped by the type of stimulus 51 // that is being created). 52 #define OPT_TT_SYMBOL 5 // A symbol is the option parameter 53 54 class command 55 { 56 57 public: 58 struct cmd_options *op; 59 string brief_doc; 60 string long_doc; 61 62 int token_value; 63 can_span_lines()64 virtual bool can_span_lines() {return 0;}; 65 66 command(const char *_name, const char *_abbr); ~command()67 virtual ~command() {} 68 get_op()69 struct cmd_options *get_op() 70 { 71 return op; 72 }; 73 name()74 const char *name() { return m_pName; } abbreviation()75 const char *abbreviation() { return m_pAbbreviation; } 76 static Processor * GetActiveCPU(bool bDisplayWarnings=false); 77 get_token()78 int get_token() {return token_value;}; 79 80 // Assume command is not repeatable is_repeatable()81 virtual int is_repeatable() { return 0; }; 82 virtual double evaluate(Expression *); 83 virtual void evaluate(ExprList_t *eList,guint64 *, int *); 84 virtual Value *toValue(Expression *expr); 85 private: 86 const char *m_pName; 87 const char *m_pAbbreviation; 88 89 }; 90 91 class cmd_options_expr 92 { 93 public: 94 95 cmd_options_expr(cmd_options *, Expression *); 96 ~cmd_options_expr(); 97 98 cmd_options *co; 99 Expression *expr; 100 }; 101 102 extern command *command_list[]; 103 extern int number_of_commands; 104 extern command *search_commands(const string &s); 105 extern int quit_gpsim; 106 extern void execute_line(char *); 107 108 #define DEBUG_PARSER 0 109 110 //======================================== 111 // typedefs 112 113 typedef list<string> StringList_t; 114 115 #endif 116