Style cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34319 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-11-27 16:55:10 +00:00
parent b79c499571
commit 0dfceb2b8a

View File

@ -1,7 +1,8 @@
// gensyscallinfos.cpp /*
// * Copyright 2004-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
// Copyright (c) 2004, Ingo Weinhold <bonefish@cs.tu-berlin.de> * Distributed under the terms of the MIT License.
// All rights reserved. Distributed under the terms of the OpenBeOS License. */
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
@ -14,62 +15,64 @@
#include "gensyscalls_common.h" #include "gensyscalls_common.h"
// usage
const char *kUsage =
"Usage: gensyscallinfos <header> <syscall infos>\n"
"\n"
"Given the (preprocessed) header file that defines the syscall prototypes the\n"
"command generates a source file consisting of syscall infos, which is needed\n"
"to build gensyscalls, which in turn generates the assembly syscall\n"
"definitions and code for the kernelland syscall dispatcher.\n"
"\n"
" <header> - Input: The preprocessed header file with the\n"
" syscall prototypes.\n"
" <syscall infos> - Output: The syscall infos source file needed to\n"
" build gensyscalls.";
// print_usage const char* kUsage =
static "Usage: gensyscallinfos <header> <syscall infos>\n"
void "\n"
"Given the (preprocessed) header file that defines the syscall prototypes "
"the\n"
"command generates a source file consisting of syscall infos, which is "
"needed\n"
"to build gensyscalls, which in turn generates the assembly syscall\n"
"definitions and code for the kernelland syscall dispatcher.\n"
"\n"
" <header> - Input: The preprocessed header file with the\n"
" syscall prototypes.\n"
" <syscall infos> - Output: The syscall infos source file needed "
"to\n"
" build gensyscalls.";
static void
print_usage(bool error) print_usage(bool error)
{ {
fprintf((error ? stderr : stdout), kUsage); fprintf((error ? stderr : stdout), kUsage);
} }
// Type
struct Type { struct Type {
Type(const char *type) : type(type) {} Type(const char* type) : type(type) {}
Type(const string &type) : type(type) {} Type(const string& type) : type(type) {}
string type; string type;
}; };
// NamedType
struct NamedType : Type { struct NamedType : Type {
NamedType(const char *type, const char *name) NamedType(const char* type, const char* name)
: Type(type), name(name) {} : Type(type), name(name) {}
NamedType(const string &type, const string &name) NamedType(const string& type, const string& name)
: Type(type), name(name) {} : Type(type), name(name) {}
string name; string name;
}; };
// Function
class Function { class Function {
public: public:
Function() : fReturnType("") {} Function() : fReturnType("") {}
void SetName(const string &name) void SetName(const string& name)
{ {
fName = name; fName = name;
} }
const string &GetName() const const string& GetName() const
{ {
return fName; return fName;
} }
void AddParameter(const NamedType &type) void AddParameter(const NamedType& type)
{ {
fParameters.push_back(type); fParameters.push_back(type);
} }
@ -79,17 +82,17 @@ public:
return fParameters.size(); return fParameters.size();
} }
const NamedType &ParameterAt(int index) const const NamedType& ParameterAt(int index) const
{ {
return fParameters[index]; return fParameters[index];
} }
void SetReturnType(const Type &type) void SetReturnType(const Type& type)
{ {
fReturnType = type; fReturnType = type;
} }
const Type &GetReturnType() const const Type& GetReturnType() const
{ {
return fReturnType; return fReturnType;
} }
@ -100,7 +103,7 @@ protected:
Type fReturnType; Type fReturnType;
}; };
// Syscall
class Syscall : public Function { class Syscall : public Function {
public: public:
string GetKernelName() const string GetKernelName() const
@ -116,10 +119,10 @@ public:
} }
}; };
// Tokenizer
class Tokenizer { class Tokenizer {
public: public:
Tokenizer(istream &input) Tokenizer(istream& input)
: fInput(input), : fInput(input),
fHasCurrent(false) fHasCurrent(false)
{ {
@ -137,12 +140,12 @@ public:
return GetNextToken(NULL); return GetNextToken(NULL);
} }
string GetNextToken(stack<string> &skippedTokens) string GetNextToken(stack<string>& skippedTokens)
{ {
return GetNextToken(&skippedTokens); return GetNextToken(&skippedTokens);
} }
string GetNextToken(stack<string> *skippedTokens) string GetNextToken(stack<string>* skippedTokens)
{ {
if (fHasCurrent) { if (fHasCurrent) {
fTokens.pop_front(); fTokens.pop_front();
@ -156,7 +159,7 @@ public:
return fTokens.front(); return fTokens.front();
} }
void ExpectToken(const string &expectedToken) void ExpectToken(const string& expectedToken)
{ {
string token = GetCurrentToken(); string token = GetCurrentToken();
if (expectedToken != token) { if (expectedToken != token) {
@ -165,19 +168,19 @@ public:
} }
} }
void ExpectNextToken(const string &expectedToken) void ExpectNextToken(const string& expectedToken)
{ {
GetNextToken(); GetNextToken();
ExpectToken(expectedToken); ExpectToken(expectedToken);
} }
bool CheckToken(const string &expectedToken) bool CheckToken(const string& expectedToken)
{ {
string token = GetCurrentToken(); string token = GetCurrentToken();
return (expectedToken == token); return (expectedToken == token);
} }
bool CheckNextToken(const string &expectedToken) bool CheckNextToken(const string& expectedToken)
{ {
GetNextToken(); GetNextToken();
bool result = CheckToken(expectedToken); bool result = CheckToken(expectedToken);
@ -202,7 +205,7 @@ public:
fTokens.push_front(token); fTokens.push_front(token);
} }
void PutTokens(stack<string> &tokens) void PutTokens(stack<string>& tokens)
{ {
if (fHasCurrent) { if (fHasCurrent) {
fTokens.pop_front(); fTokens.pop_front();
@ -265,17 +268,16 @@ private:
} }
private: private:
istream &fInput; istream& fInput;
list<string> fTokens; list<string> fTokens;
bool fHasCurrent; bool fHasCurrent;
}; };
// Main
class Main { class Main {
public: public:
int Run(int argc, char **argv) int Run(int argc, char** argv)
{ {
// parse parameters // parse parameters
if (argc >= 2 if (argc >= 2
@ -292,9 +294,8 @@ public:
return 0; return 0;
} }
private: private:
void _ParseSyscalls(const char *filename) void _ParseSyscalls(const char* filename)
{ {
// open the input file // open the input file
ifstream file(filename, ifstream::in); ifstream file(filename, ifstream::in);
@ -325,7 +326,7 @@ private:
tokenizer.ExpectNextToken("end"); tokenizer.ExpectNextToken("end");
} }
void _WriteSyscallInfoFile(const char *filename) void _WriteSyscallInfoFile(const char* filename)
{ {
// open the syscall info file // open the syscall info file
ofstream file(filename, ofstream::out | ofstream::trunc); ofstream file(filename, ofstream::out | ofstream::trunc);
@ -344,15 +345,15 @@ private:
// syscalls // syscalls
for (int i = 0; i < (int)fSyscalls.size(); i++) { for (int i = 0; i < (int)fSyscalls.size(); i++) {
const Syscall &syscall = fSyscalls[i]; const Syscall& syscall = fSyscalls[i];
// syscall = syscallVector->CreateSyscall("syscallName", // syscall = syscallVector->CreateSyscall("syscallName",
// "syscallKernelName"); // "syscallKernelName");
file << "\tsyscall = syscallVector->CreateSyscall(\"" file << "\tsyscall = syscallVector->CreateSyscall(\""
<< syscall.GetName() << "\", \"" << syscall.GetName() << "\", \""
<< syscall.GetKernelName() << "\");" << endl; << syscall.GetKernelName() << "\");" << endl;
const Type &returnType = syscall.GetReturnType(); const Type& returnType = syscall.GetReturnType();
// syscall->SetReturnType<ReturnType>("returnType"); // syscall->SetReturnType<ReturnType>("returnType");
file << "\tsyscall->SetReturnType<" << returnType.type file << "\tsyscall->SetReturnType<" << returnType.type
@ -361,7 +362,7 @@ private:
// parameters // parameters
int paramCount = syscall.CountParameters(); int paramCount = syscall.CountParameters();
for (int k = 0; k < paramCount; k++) { for (int k = 0; k < paramCount; k++) {
const NamedType &param = syscall.ParameterAt(k); const NamedType& param = syscall.ParameterAt(k);
// syscall->AddParameter<ParameterType>("parameterTypeName", // syscall->AddParameter<ParameterType>("parameterTypeName",
// "parameterName"); // "parameterName");
file << "\tsyscall->AddParameter<" file << "\tsyscall->AddParameter<"
@ -377,7 +378,7 @@ private:
file << "}" << endl; file << "}" << endl;
} }
void _ParseSyscall(Tokenizer &tokenizer, Syscall &syscall) void _ParseSyscall(Tokenizer& tokenizer, Syscall& syscall)
{ {
// get return type and function name // get return type and function name
vector<string> returnType; vector<string> returnType;
@ -410,7 +411,7 @@ private:
tokenizer.ExpectNextToken(";"); tokenizer.ExpectNextToken(";");
} }
void _ParseParameter(Tokenizer &tokenizer, Syscall &syscall) void _ParseParameter(Tokenizer& tokenizer, Syscall& syscall)
{ {
vector<string> type; vector<string> type;
while (tokenizer.GetNextToken() != ")" while (tokenizer.GetNextToken() != ")"
@ -445,8 +446,8 @@ private:
syscall.AddParameter(NamedType(typeString, typeName)); syscall.AddParameter(NamedType(typeString, typeName));
} }
void _ParseFunctionPointerParameter(Tokenizer &tokenizer, Syscall &syscall, void _ParseFunctionPointerParameter(Tokenizer& tokenizer, Syscall& syscall,
vector<string> &type) vector<string>& type)
{ {
// When this method is entered, the return type and the opening // When this method is entered, the return type and the opening
// parenthesis must already be parse and stored in the supplied type // parenthesis must already be parse and stored in the supplied type
@ -488,15 +489,13 @@ private:
}; };
// main
int int
main(int argc, char **argv) main(int argc, char** argv)
{ {
try { try {
return Main().Run(argc, argv); return Main().Run(argc, argv);
} catch (Exception &exception) { } catch (Exception& exception) {
fprintf(stderr, "%s\n", exception.what()); fprintf(stderr, "%s\n", exception.what());
return 1; return 1;
} }
} }