StrucCmp::StrucCmp(tid_t struc_id) throw() : m_struc_id(struc_id), m_is_union(false) { // find a struct/union by its id // should only be used for debug purpose if(struc_id != BADNODE) { m_is_union = is_union(struc_id); add_all_members(); } }
StrucCmp::StrucCmp(char const *struc_name) throw() : m_struc_id(BADNODE), m_is_union(false) { // find a struct/union by its (non null) name if(struc_name != NULL) { m_struc_id = ::get_struc_id(struc_name); if(m_struc_id != BADNODE) { m_is_union = is_union(m_struc_id); add_all_members(); } } }
static void generate_stub(int nparms) { FILE *stream = open_stub(); char formal[MAX_PARMSIZE]; char actual[MAX_PARMSIZE]; int i; int j; /* Generate "up-front" information, include correct header files */ fprintf(stream, "/* Auto-generated %s stub file -- do not edit */\n\n", g_parm[0]); fprintf(stream, "#include <nuttx/config.h>\n"); fprintf(stream, "#include <stdint.h>\n"); fprintf(stream, "#include <%s>\n\n", g_parm[HEADER_INDEX]); if (g_parm[COND_INDEX][0] != '\0') { fprintf(stream, "#if %s\n\n", g_parm[COND_INDEX]); } /* Generate the function definition that matches standard function prototype */ if (g_inline) { fprintf(stream, "static inline "); } fprintf(stream, "uintptr_t STUB_%s(", g_parm[NAME_INDEX]); /* Generate the formal parameter list. A function received no parameters is a special case. */ if (nparms <= 0) { fprintf(stream, "void"); } else { for (i = 0; i < nparms; i++) { /* Treat the first argument in the list differently from the others.. * It does not need a comma before it. */ if (i > 0) { /* Check for a variable number of arguments */ if (is_vararg(g_parm[PARM1_INDEX+i], i, nparms)) { /* Always receive six arguments in this case */ for (j = i+1; j <= 6; j++) { fprintf(stream, ", uintptr_t parm%d", j); } } else { fprintf(stream, ", uintptr_t parm%d", i+1); } } else { fprintf(stream, "uintptr_t parm%d", i+1); } } } fprintf(stream, ")\n{\n"); /* Then call the proxied function. Functions that have no return value are * a special case. */ if (strcmp(g_parm[RETTYPE_INDEX], "void") == 0) { fprintf(stream, " %s(", g_parm[NAME_INDEX]); } else { fprintf(stream, " return (uintptr_t)%s(", g_parm[NAME_INDEX]); } /* The pass all of the system call parameters, casting to the correct type * as necessary. */ for (i = 0; i < nparms; i++) { /* Get the formal type of the parameter, and get the type that we * actually have to cast to. For example for a formal type like 'int parm[]' * we have to cast the actual parameter to 'int*'. The worst is a union * type like 'union sigval' where we have to cast to (union sigval)((FAR void *)parm) * -- Yech. */ get_formalparmtype(g_parm[PARM1_INDEX+i], formal); get_actualparmtype(g_parm[PARM1_INDEX+i], actual); /* Treat the first argument in the list differently from the others.. * It does not need a comma before it. */ if (i > 0) { /* Check for a variable number of arguments */ if (is_vararg(actual, i, nparms)) { /* Always pass six arguments */ for (j = i+1; j <=6; j++) { fprintf(stream, ", parm%d", j); } } else { if (is_union(formal)) { fprintf(stream, ", (%s)((%s)parm%d)", formal, actual, i+1); } else { fprintf(stream, ", (%s)parm%d", actual, i+1); } } } else { if (is_union(formal)) { fprintf(stream, "(%s)((%s)parm%d)", formal, actual, i+1); } else { fprintf(stream, "(%s)parm%d",actual, i+1); } } } /* Tail end of the function. If the proxied function has no return * value, just return zero (OK). */ if (strcmp(g_parm[RETTYPE_INDEX], "void") == 0) { fprintf(stream, ");\n return 0;\n}\n\n"); } else { fprintf(stream, ");\n}\n\n"); } if (g_parm[COND_INDEX][0] != '\0') { fprintf(stream, "#endif /* %s */\n", g_parm[COND_INDEX]); } stub_close(stream); }
static void generate_proxy(int nparms) { FILE *stream = open_proxy(); char formal[MAX_PARMSIZE]; char fieldname[MAX_PARMSIZE]; bool bvarargs = false; int nformal; int nactual; int i; /* Generate "up-front" information, include correct header files */ fprintf(stream, "/* Auto-generated %s proxy file -- do not edit */\n\n", g_parm[NAME_INDEX]); fprintf(stream, "#include <nuttx/config.h>\n"); /* Does this function have a variable number of parameters? If so then the * final parameter type will be encoded as "..." */ if (is_vararg(g_parm[PARM1_INDEX+nparms-1], nparms-1, nparms)) { nformal = nparms-1; bvarargs = true; fprintf(stream, "#include <stdarg.h>\n"); } else { nformal = nparms; } fprintf(stream, "#include <%s>\n", g_parm[HEADER_INDEX]); fprintf(stream, "#include <syscall.h>\n\n"); if (g_parm[COND_INDEX][0] != '\0') { fprintf(stream, "#if %s\n\n", g_parm[COND_INDEX]); } /* Generate the function definition that matches standard function prototype */ fprintf(stream, "%s %s(", g_parm[RETTYPE_INDEX], g_parm[NAME_INDEX]); /* Generate the formal parameter list */ if (nformal <= 0) { fprintf(stream, "void"); } else { for (i = 0; i < nformal; i++) { /* The formal and actual parameter types may be encoded.. extra the * formal parameter type. */ get_formalparmtype(g_parm[PARM1_INDEX+i], formal); /* Arguments after the first must be separated from the preceding * parameter with a comma. */ if (i > 0) { fprintf(stream, ", "); } print_formalparm(stream, formal, i+1); } } /* Handle the end of the formal parameter list */ if (bvarargs) { fprintf(stream, ", ...)\n{\n"); /* Get parm variables .. some from the parameter list and others from * the varargs. */ if (nparms < 7) { fprintf(stream, " va_list ap;\n"); for (i = nparms; i < 7; i++) { fprintf(stream, " uintptr_t parm%d;\n", i); } fprintf(stream, "\n va_start(ap, parm%d);\n", nparms-1); for (i = nparms; i < 7; i++) { fprintf(stream, " parm%d = va_arg(ap, uintptr_t);\n", i); } fprintf(stream, " va_end(ap);\n\n"); } } else { fprintf(stream, ")\n{\n"); } /* Generate the system call. Functions that do not return or return void * are special cases. */ nactual = bvarargs ? 6 : nparms; if (strcmp(g_parm[RETTYPE_INDEX], "void") == 0) { fprintf(stream, " (void)sys_call%d(", nactual); } else { fprintf(stream, " return (%s)sys_call%d(", g_parm[RETTYPE_INDEX], nactual); } /* Create the parameter list with the matching types. The first parameter * is always the syscall number. */ fprintf(stream, "(unsigned int)SYS_%s", g_parm[NAME_INDEX]); for (i = 0; i < nactual; i++) { /* Is the parameter a union member */ if (i < nparms && is_union(g_parm[PARM1_INDEX+i])) { /* Then we will have to pick a field name that can be cast to a * uintptr_t. There probably should be some error handling here * to catch the case where the fieldname was not supplied. */ get_fieldname(g_parm[PARM1_INDEX+i], fieldname); fprintf(stream, ", (uintptr_t)parm%d.%s", i+1, fieldname); } else { fprintf(stream, ", (uintptr_t)parm%d", i+1); } } /* Handle the tail end of the function. */ fprintf(stream, ");\n}\n\n"); if (g_parm[COND_INDEX][0] != '\0') { fprintf(stream, "#endif /* %s */\n", g_parm[COND_INDEX]); } fclose(stream); }
char *get_token(char *lexeme , int mode){ char *token=(char*)calloc(strlen(lexeme)+50,sizeof(char)); //printf("Getting token\n"); if(is_long(lexeme)){ sprintf(token,"%d",LONG); } else if(is_static(lexeme)){ sprintf(token,"%d",STATIC); } else if(is_union(lexeme)){ sprintf(token,"%d",UNION); } else if(is_default(lexeme)){ sprintf(token,"%d",DEFAULT); } else if(is_break(lexeme)){ sprintf(token,"%d",BREAK); } else if(is_case(lexeme)){ sprintf(token,"%d",CASE); } else if(is_continue(lexeme)){ sprintf(token,"%d",CONTINUE); } else if(is_goto(lexeme)){ sprintf(token,"%d",GOTO); } else if(is_struct(lexeme)){ sprintf(token,"%d",STRUCT); } else if(is_const(lexeme)){ sprintf(token,"%d",CONST); } else if(is_void(lexeme)){ sprintf(token,"%d",VOID); } else if(is_switch(lexeme)){ sprintf(token,"%d",SWITCH); } else if(is_for(lexeme)){ sprintf(token,"%d",FOR); } else if(is_while(lexeme)){ sprintf(token,"%d",WHILE); } else if(is_do(lexeme)){ sprintf(token,"%d",DO); } else if(is_return(lexeme)){ sprintf(token,"%d",RETURN); } else if(is_bool(lexeme)){ sprintf(token,"%d",BOOL); } else if(is_char(lexeme)){ sprintf(token,"%d",CHAR); } else if(is_signed(lexeme)){ sprintf(token,"%d",SIGNED); } else if(is_unsigned(lexeme)){ sprintf(token,"%d",UNSIGNED); } else if(is_short(lexeme)){ sprintf(token,"%d",SHORT); } else if(is_int(lexeme)){ sprintf(token,"%d",INT); } else if(is_float(lexeme)){ sprintf(token,"%d",FLOAT); } else if(is_double(lexeme)){ sprintf(token,"%d",DOUBLE); } else if(is_l_square(lexeme)){ sprintf(token,"%d",L_SQUARE); } else if(is_r_square(lexeme)){ sprintf(token,"%d",R_SQUARE); } else if(is_l_paraen(lexeme)){ sprintf(token,"%d",L_PARAEN); } else if(is_r_paraen(lexeme)){ sprintf(token,"%d",R_PARAEN); } else if(is_l_cbrace(lexeme)){ sprintf(token,"%d",L_CBRACE); } else if(is_r_cbrace(lexeme)){ sprintf(token,"%d",R_CBRACE); } else if(is_comma(lexeme)){ sprintf(token,"%d",COMMA); } else if(is_semicol(lexeme)){ sprintf(token,"%d",SEMICOL); } else if(is_eq_eq(lexeme)){ sprintf(token,"%d",EQ_EQ); } else if(is_lesser(lexeme)){ sprintf(token,"%d",LESSER); } else if(is_less_eq(lexeme)){ sprintf(token,"%d",LESS_EQ); } else if(is_div(lexeme)){ sprintf(token,"%d",DIV); } else if(is_greater(lexeme)){ sprintf(token,"%d",GREATER); } else if(is_great_eq(lexeme)){ sprintf(token,"%d",GREAT_EQ); } else if(is_plus_eq(lexeme)){ sprintf(token,"%d",PLUS_EQ); } else if(is_minus_eq(lexeme)){ sprintf(token,"%d",MINUS_EQ); } else if(is_div_eq(lexeme)){ sprintf(token,"%d",DIV_EQ); } else if(is_mult_eq(lexeme)){ sprintf(token,"%d",MULT_EQ); } else if(is_minus_minus(lexeme)){ sprintf(token,"%d",MINUS_MINUS); } else if(is_plus_plus(lexeme)){ sprintf(token,"%d",PLUS_PLUS); } else if(is_percent(lexeme)){ sprintf(token,"%d",PERCENT); } else if(is_div(lexeme)){ sprintf(token,"%d",DIV); } else if(is_mult(lexeme)){ sprintf(token,"%d",MULT); } else if(is_minus(lexeme)){ sprintf(token,"%d",MINUS); } else if(is_plus(lexeme)){ sprintf(token,"%d",PLUS); } else if(is_int_const(lexeme)){ printf("int"); sprintf(token,"%d\t%s",INT_CONST,lexeme); } else if(is_flo_const(lexeme)){ printf("float"); sprintf(token,"%d\t%s",FLO_CONST,lexeme); } else if(is_comment_start(lexeme)){ sprintf(token,"$start"); } else if(is_comment_end(lexeme)){ sprintf(token,"$end"); } else if(is_identifier(lexeme)){ printf("Identifier"); if(mode==1) ht_set( symboltable, lexeme, "1"); sprintf(token,"%d\t%s",IDNTIFIER,lexeme); } else sprintf(token,"%d",NOTOK); return token; }
bool Type::is_alt() const { return is_union() || is_any(); }