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 { 47 } 48 49 const string &Name() const { return fName; } 50 int32 Offset() const { return fOffset; } 51 52 private: 53 string fName; 54 int32 fOffset; 55 }; 56 57 // Syscall 58 class Syscall { 59 public: 60 Syscall(string name, string returnTypeName, TypeHandler *returnTypeHandler) 61 : fName(name), 62 fReturnType(new Type(returnTypeName, returnTypeHandler)) 63 { 64 } 65 66 const string &Name() const 67 { 68 return fName; 69 } 70 71 Type *ReturnType() const 72 { 73 return fReturnType; 74 } 75 76 void AddParameter(Parameter *parameter) 77 { 78 fParameters.push_back(parameter); 79 } 80 81 void AddParameter(string name, int32 offset, string typeName, 82 TypeHandler *handler) 83 { 84 AddParameter(new Parameter(name, offset, typeName, handler)); 85 } 86 87 int32 CountParameters() const 88 { 89 return fParameters.size(); 90 } 91 92 Parameter *ParameterAt(int32 index) const 93 { 94 return fParameters[index]; 95 } 96 97 Parameter *GetParameter(string name) const 98 { 99 int32 count = CountParameters(); 100 for (int32 i = 0; i < count; i++) { 101 Parameter *parameter = ParameterAt(i); 102 if (parameter->Name() == name) 103 return parameter; 104 } 105 106 return NULL; 107 } 108 109 private: 110 string fName; 111 Type *fReturnType; 112 vector<Parameter*> fParameters; 113 }; 114 115 #endif // STRACE_SYSCALL_H 116