本文整理汇总了C++中Var::isVoid方法的典型用法代码示例。如果您正苦于以下问题:C++ Var::isVoid方法的具体用法?C++ Var::isVoid怎么用?C++ Var::isVoid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Var
的用法示例。
在下文中一共展示了Var::isVoid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeVarEncodingExpression
static void writeVarEncodingExpression(Var& var, FILE* fp)
{
const char* varname = var.name().c_str();
if (var.isPointer()) {
// encode a pointer header
fprintf(fp, "\t*(unsigned int *)(ptr) = __size_%s; ptr += 4;\n", varname);
Var::PointerDir dir = var.pointerDir();
if (dir == Var::POINTER_INOUT || dir == Var::POINTER_IN) {
if (var.nullAllowed()) {
fprintf(fp, "\tif (%s != NULL) ", varname);
} else {
fprintf(fp, "\t");
}
if (var.packExpression().size() != 0) {
fprintf(fp, "%s;", var.packExpression().c_str());
} else {
fprintf(fp, "memcpy(ptr, %s, __size_%s);",
varname, varname);
}
fprintf(fp, "ptr += __size_%s;\n", varname);
}
} else {
// encode a non pointer variable
if (!var.isVoid()) {
fprintf(fp, "\t\tmemcpy(ptr, &%s, %u); ptr += %u;\n",
varname,
(unsigned) var.type()->bytes(),
(unsigned) var.type()->bytes());
}
}
}
示例2: genDecoderImpl
int ApiGen::genDecoderImpl(const std::string &filename)
{
FILE *fp = fopen(filename.c_str(), "wt");
if (fp == NULL) {
perror(filename.c_str());
return -1;
}
printHeader(fp);
std::string classname = m_basename + "_decoder_context_t";
size_t n = size();
fprintf(fp, "\n\n#include <string.h>\n");
fprintf(fp, "#include \"%s_opcodes.h\"\n\n", m_basename.c_str());
fprintf(fp, "#include \"%s_dec.h\"\n\n\n", m_basename.c_str());
fprintf(fp, "#include \"ProtocolUtils.h\"\n\n");
fprintf(fp, "#include <stdio.h>\n\n");
fprintf(fp, "typedef unsigned int tsize_t; // Target \"size_t\", which is 32-bit for now. It may or may not be the same as host's size_t when emugen is compiled.\n\n");
// helper macros
fprintf(fp,
"#ifdef DEBUG_PRINTOUT\n"
"# define DEBUG(...) fprintf(stderr, __VA_ARGS__)\n"
"#else\n"
"# define DEBUG(...) ((void)0)\n"
"#endif\n\n");
fprintf(fp,
"#ifdef CHECK_GLERROR\n"
"# define SET_LASTCALL(name) sprintf(lastCall, #name)\n"
"#else\n"
"# define SET_LASTCALL(name) ((void)0)\n"
"#endif\n\n");
// helper templates
fprintf(fp, "using namespace emugl;\n\n");
// decoder switch;
fprintf(fp, "size_t %s::decode(void *buf, size_t len, IOStream *stream)\n{\n", classname.c_str());
fprintf(fp,
" \n\
\tsize_t pos = 0;\n\
\tif (len < 8) return pos; \n\
\tunsigned char *ptr = (unsigned char *)buf;\n\
\tbool unknownOpcode = false; \n\
#ifdef CHECK_GL_ERROR \n\
\tchar lastCall[256] = {0}; \n\
#endif \n\
\twhile ((len - pos >= 8) && !unknownOpcode) { \n\
\t\tuint32_t opcode = *(uint32_t *)ptr; \n\
\t\tsize_t packetLen = *(uint32_t *)(ptr + 4);\n\
\t\tif (len - pos < packetLen) return pos; \n\
\t\tswitch(opcode) {\n");
for (size_t f = 0; f < n; f++) {
enum Pass_t {
PASS_FIRST = 0,
PASS_VariableDeclarations = PASS_FIRST,
PASS_TmpBuffAlloc,
PASS_MemAlloc,
PASS_DebugPrint,
PASS_FunctionCall,
PASS_FlushOutput,
PASS_Epilog,
PASS_LAST
};
EntryPoint *e = &at(f);
// construct a printout string;
std::string printString = "";
for (size_t i = 0; i < e->vars().size(); i++) {
Var *v = &e->vars()[i];
if (!v->isVoid()) printString += (v->isPointer() ? "%p(%u)" : v->type()->printFormat()) + " ";
}
printString += "";
// TODO - add for return value;
fprintf(fp, "\t\tcase OP_%s: {\n", e->name().c_str());
bool totalTmpBuffExist = false;
std::string totalTmpBuffOffset = "0";
std::string *tmpBufOffset = new std::string[e->vars().size()];
// construct retval type string
std::string retvalType;
if (!e->retval().isVoid()) {
retvalType = e->retval().type()->name();
}
for (int pass = PASS_FIRST; pass < PASS_LAST; pass++) {
if (pass == PASS_FunctionCall &&
!e->retval().isVoid() &&
!e->retval().isPointer()) {
fprintf(fp, "\t\t\t*(%s *)(&tmpBuf[%s]) = ", retvalType.c_str(),
totalTmpBuffOffset.c_str());
}
//.........这里部分代码省略.........