00001 /* 00002 * YaST2: Core system 00003 * 00004 * Description: 00005 * YaST2 execution environment, i.e. processing context. 00006 * Contains reference to the current block, the current statement, 00007 * the current file name and backtrace. 00008 * This information can be used for logging, debugger etc. 00009 * 00010 * Authors: 00011 * Stanislav Visnovsky <visnov@suse.cz> 00012 * 00013 */ 00014 00015 #ifndef _execution_environment_h 00016 #define _execution_environment_h 00017 00018 #include <stack> 00019 #include <string> 00020 00021 #include "y2log.h" 00022 #include "ycp/YStatement.h" 00023 00024 using namespace std; 00025 00027 struct CallFrame { 00028 string called_function; 00029 string filename; 00030 int linenumber; 00031 00032 CallFrame (string f, int l, string func): 00033 called_function (func), 00034 filename (f), 00035 linenumber (l) 00036 {} 00037 }; 00038 00047 class ExecutionEnvironment { 00048 00049 public: 00050 typedef vector<const CallFrame*> CallStack; 00051 00052 private: 00053 int m_linenumber; 00054 string m_filename; 00055 bool m_forced_filename; 00056 YStatementPtr m_statement; 00057 CallStack m_backtrace; 00063 size_t m_recursion_limit; 00064 00065 public: 00066 ExecutionEnvironment (); 00067 ~ExecutionEnvironment() {}; 00068 00072 int linenumber () const; 00073 00077 void setLinenumber (int line); 00078 00082 const string filename () const; 00083 00087 void setFilename (const string & filename); 00088 00092 YStatementPtr statement () const; 00093 00097 void setStatement (YStatementPtr s); 00098 00102 bool endlessRecursion (); 00103 00110 void pushframe (string called_function); 00111 00115 void popframe (); 00116 00123 void backtrace (loglevel_t level, uint skip = 0) const; 00124 00131 CallStack callstack() const; 00132 }; 00133 00134 #endif /* _execution_environment_h */