And updated hresultwrap to produce signatures. Man this is so un-C++-y it actually feels like I'm doing it wrong...
This commit is contained in:
parent
ef9e08d4ad
commit
481e1e30bb
|
@ -1,23 +1,81 @@
|
||||||
// 21 may 2018
|
// 21 may 2018
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "lib.hpp"
|
#include "lib.hpp"
|
||||||
|
|
||||||
|
struct item {
|
||||||
|
Slice *name;
|
||||||
|
Slice *callingConvention;
|
||||||
|
Slice **params;
|
||||||
|
size_t nParams;
|
||||||
|
Slice *returns;
|
||||||
|
bool keepReturn;
|
||||||
|
Slice *cond[2];
|
||||||
|
};
|
||||||
|
|
||||||
bool generate(const char *line, size_t n, FILE *fout)
|
bool generate(const char *line, size_t n, FILE *fout)
|
||||||
{
|
{
|
||||||
std::vector<char> genout;
|
std::vector<char> genout;
|
||||||
std::vector<Slice *> *tokens;
|
std::vector<Slice *> *tokens;
|
||||||
std::vector<Slice *>::const_iterator i;
|
size_t i, j;
|
||||||
|
struct item item;
|
||||||
size_t nw;
|
size_t nw;
|
||||||
|
|
||||||
tokens = TokenizeWhitespace(line, n);
|
tokens = TokenizeWhitespace(line, n);
|
||||||
for (i = tokens->begin(); i < tokens->end(); i++) {
|
|
||||||
genout.push_back('/');
|
memset(&item, 0, sizeof (struct item));
|
||||||
genout.push_back('/');
|
i = 0;
|
||||||
genout.push_back(' ');
|
item.returns = tokens->at(i);
|
||||||
AppendSlice(&genout, *i);
|
if (item.returns->Data()[0] == '*') {
|
||||||
genout.push_back('\n');
|
item.returns = new Slice(item.returns->Data() + 1, item.returns->Len() - 1);
|
||||||
|
item.keepReturn = true;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
|
if (tokens->size() % 2 == 1) {
|
||||||
|
item.callingConvention = tokens->at(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
item.name = tokens->at(i);
|
||||||
|
i++;
|
||||||
|
item.cond[0] = tokens->at(tokens->size() - 2);
|
||||||
|
item.cond[1] = tokens->at(tokens->size() - 1);
|
||||||
|
item.nParams = (tokens->size() - 2) - i;
|
||||||
|
item.params = new Slice *[item.nParams];
|
||||||
|
for (j = 0; j < item.nParams; j++) {
|
||||||
|
item.params[j] = tokens->at(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppendString(&genout, "HRESULT ");
|
||||||
|
if (item.callingConvention != NULL) {
|
||||||
|
AppendSlice(&genout, item.callingConvention);
|
||||||
|
genout.push_back(' ');
|
||||||
|
}
|
||||||
|
AppendSlice(&genout, item.name);
|
||||||
|
genout.push_back('(');
|
||||||
|
for (i = 0; i < item.nParams; i += 2) {
|
||||||
|
AppendSlice(&genout, item.params[i]);
|
||||||
|
genout.push_back(' ');
|
||||||
|
AppendSlice(&genout, item.params[i + 1]);
|
||||||
|
genout.push_back(',');
|
||||||
|
genout.push_back(' ');
|
||||||
|
}
|
||||||
|
if (item.keepReturn) {
|
||||||
|
AppendSlice(&genout, item.returns);
|
||||||
|
AppendString(&genout, " *ret");
|
||||||
|
} else if (item.nParams != 0) {
|
||||||
|
// remove the trailing comma and space
|
||||||
|
genout.pop_back();
|
||||||
|
genout.pop_back();
|
||||||
|
} else
|
||||||
|
AppendString(&genout, "void");
|
||||||
|
genout.push_back(')');
|
||||||
|
genout.push_back('\n');
|
||||||
|
|
||||||
|
delete[] item.params;
|
||||||
|
if (item.keepReturn)
|
||||||
|
delete item.returns;
|
||||||
FreeTokenized(tokens);
|
FreeTokenized(tokens);
|
||||||
|
|
||||||
genout.push_back('\n');
|
genout.push_back('\n');
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <string.h>
|
||||||
#include "lib.hpp"
|
#include "lib.hpp"
|
||||||
|
|
||||||
class eofError : public Error {
|
class eofError : public Error {
|
||||||
|
@ -146,6 +147,11 @@ Error *Scanner::Err(void) const
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppendString(std::vector<char> *v, const char *str)
|
||||||
|
{
|
||||||
|
v->insert(v->end(), str, str + strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
Slice::Slice(const char *p, size_t n)
|
Slice::Slice(const char *p, size_t n)
|
||||||
{
|
{
|
||||||
this->p = p;
|
this->p = p;
|
||||||
|
|
|
@ -47,6 +47,8 @@ public:
|
||||||
Error *Err(void) const;
|
Error *Err(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern void AppendString(std::vector<char> *v, const char *str);
|
||||||
|
|
||||||
class Slice {
|
class Slice {
|
||||||
const char *p;
|
const char *p;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
Loading…
Reference in New Issue