1 /* 2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef STRACE_SYSCALL_H 6 #define STRACE_SYSCALL_H 7 8 #include <string> 9 #include <vector> 10 11 #include <SupportDefs.h> 12 13 #include "TypeHandler.h" 14 15 using std::string; 16 using std::vector; 17 18 // Type 19 class Type { 20 public: 21 Type(string typeName, TypeHandler *handler) 22 : fTypeName(typeName), fHandler(handler) {} 23 24 const string &TypeName() const { return fTypeName; } 25 26 void SetHandler(TypeHandler *handler) 27 { 28 delete fHandler; 29 fHandler = handler; 30 } 31 32 TypeHandler *Handler() const { return fHandler; } 33 34 private: 35 string fTypeName; 36 TypeHandler *fHandler; 37 }; 38 39 // Parameter 40 class Parameter : public Type { 41 public: 42 Parameter(string name, int32 offset, string typeName, TypeHandler *handler) 43 : Type(typeName, handler), 44 fName(name), 45 fOffset(offset), 46 fInOut(false), 47 fOut(false) 48 { 49 } 50 51 const string &Name() const { return fName; } 52 int32 Offset() const { return fOffset; } 53 bool InOut() const { return fInOut; } 54 void SetInOut(bool inout) { fInOut = inout; } 55 bool Out() const { return fOut; } 56 void SetOut(bool out) { fOut = out; } 57 58 private: 59 string fName; 60 int32 fOffset; 61 bool fInOut; 62 bool fOut; 63 }; 64 65 // Syscall 66 class Syscall { 67 public: 68 Syscall(string name, string returnTypeName, TypeHandler *returnTypeHandler) 69 : fName(name), 70 fReturnType(new Type(returnTypeName, returnTypeHandler)) 71 { 72 } 73 74 const string &Name() const 75 { 76 return fName; 77 } 78 79 Type *ReturnType() const 80 { 81 return fReturnType; 82 } 83 84 void AddParameter(Parameter *parameter) 85 { 86 fParameters.push_back(parameter); 87 } 88 89 void AddParameter(string name, int32 offset, string typeName, 90 TypeHandler *handler) 91 { 92 AddParameter(new Parameter(name, offset, typeName, handler)); 93 } 94 95 int32 CountParameters() const 96 { 97 return fParameters.size(); 98 } 99 100 Parameter *ParameterAt(int32 index) const 101 { 102 return fParameters[index]; 103 } 104 105 Parameter *GetParameter(string name) const 106 { 107 int32 count = CountParameters(); 108 for (int32 i = 0; i < count; i++) { 109 Parameter *parameter = ParameterAt(i); 110 if (parameter->Name() == name) 111 return parameter; 112 } 113 114 return NULL; 115 } 116 117 private: 118 string fName; 119 Type *fReturnType; 120 vector<Parameter*> fParameters; 121 }; 122 123 #endif // STRACE_SYSCALL_H 124