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