Exemplo n.º 1
0
/* put the class value for the escape code */
static void c_map_put_esc_class(symbol_t *sp, list_t *entry)
{
	list_t *pp = entry;
    list_t *stmts = find_class_stmts(sp->ptype);
	if (stmts == NULL) 
        fatal("Internal error CM%d: Cannot find declaration of class '%s'", __LINE__, sp->name);
	
    /* no map cascades at this time */
    if (entry->type == ESC_MAP) 
        fatal("Internal error CM%d: Map cascading not supported", __LINE__);
		
    while (stmts != NULL) {
        switch (stmts->type) {
		case DECL:
            /* declarations are ok, even parsable ones, but not with classes */
            if (stmts->sp->ptype->ident == CLASS_TYPE) return; 
            if (pp == NULL) return;
          	if (!is_literal(pp->e3->op)) {
                c_out("0");
                return;
            }

            c_outi("%sbs.%sput", prefix, (stmts->sp->modifiers & M_LITTLE ? "little_" : ""));

            if (stmts->sp->ptype->ident <= INT) {
                if (java() && stmts->sp->modifiers & M_LONG)
                    c_out("long(%sarg%s%s,", prefix, c_scope(), stmts->sp->name);
                else 
                    c_out("bits(%sarg%s%s,", prefix, c_scope(), stmts->sp->name);
                c_expression(pp->e3, 0);
		        c_out(");\n");
            }
            else if (stmts->sp->ptype->ident == FLOAT)
                c_out("float(%sarg%s%s);\n", prefix, c_scope(), stmts->sp->name);
            else if (stmts->sp->ptype->ident == DOUBLE && (stmts->sp->modifiers & M_LONG)) 
                c_out("ldouble(%sarg%s%s);\n", prefix, c_scope(), stmts->sp->name);
            else 
                c_out("double(%sarg%s%s);\n", prefix, c_scope(), stmts->sp->name);

            pp = pp->next;
            break;
            
        default:
            /* everything else, isn't - has been reported already */
            return;
        }
        stmts = stmts->next;
    }
}
Exemplo n.º 2
0
/* compare statements for a class map entry */
static void c_map_put_compare_class(symbol_t *sp, list_t *entry)
{
	 list_t *p = entry->sub1;
 
     /* find the statements for this class */
     list_t *stmts = find_class_stmts(sp->ptype);
     if (stmts == NULL)
        fatal("Internal error CM%d: Cannot find declaration of class '%s'", __LINE__, sp->name);
 
     /* traverse declarations and output assignment code for each variable */
	 while (stmts != NULL) {
        switch (stmts->type) {
		case DECL:
            /* declarations are ok, even parsable ones, but not with classes */
            if (stmts->sp->ptype->ident == CLASS_TYPE) return; 
            if (p == NULL) return;

            c_out("(%sarg%s%s == ", prefix, c_scope(), stmts->sp->name);

            if (stmts->sp->ptype->ident == FLOAT && p->e1->type == DOUBLE)
                c_out("(float)");
            c_expression(p->e1, 0);
			c_out(")");
            if (stmts->next != NULL && !is_verbatim(stmts->next->type)) 
                c_out(" && ");
            p = p->next;
            break;
            
        default:
            /* everything else, isn't - has been reported already */
            return;
        }
        stmts = stmts->next;
    }
}
Exemplo n.º 3
0
c_scope
c_scopeNew(
    c_base base)
{
    c_scope o;

    o = c_scope(c_new(c_resolve(base,"c_scope")));
    if (o) {
        c_scopeInit(o);
    }

    return o;
}
Exemplo n.º 4
0
/* helper function called by the function below */
static void c_xml_map_var_helper(symbol_t* sp, int simple)
{
    if (sp->ptype->ident != CHAR) 
        c_out("%s", (sp->modifiers & M_LITTLE ? " big=\\\"false\\\"" : ""));
    
    if (cpp()) {
        c_out(" bitLen=\\\"%%d\\\">");
        /* output the content (between the element tags) in the correct format */
		if (sp->ptype->ident <= INT) {
			if (sp->ptype->ident == CHAR) 
                c_out("%%c");
			else if (sp->modifiers & M_UNSIGNED) 
                c_out("%%u");
            else 
                c_out("%%d");
		}
		else if (sp->ptype->ident <= DOUBLE) 
            c_out("%%g");
		else
            fatal("Internal error CX%d: Expected simple type", __LINE__);
 
        if (simple)
            c_out("</%s>\", %sesc_bits, *%sarg);\n", "value", prefix, prefix);
        else
            c_out("</%s>\", %sesc_bits, %sarg%s%s);\n", sp->name, prefix, prefix, c_scope(), sp->name);
    }
    else if (java()) {
        c_out(" bitLen=\\\"");
        c_out("\" + %sesc_bits + \"\\\">", prefix);
        /* output the content (between the element tags) in the correct format */
        if (simple)
            c_out("\" + %sarg", prefix);
        else
            c_out("\" + %sarg%s%s", prefix, c_scope(), sp->name);

        c_out(" + \"</%s>\");\n", (simple ? "value" : sp->name));
    }
}
Exemplo n.º 5
0
/* output assignment statements for a class map entry */
static void c_map_get_assign_class(symbol_t *sp, list_t *entry)
{
    list_t *p;

    /* find the statements for this class */
    list_t *stmts = find_class_stmts(sp->ptype);
    if (stmts == NULL) 
        fatal("Internal error CM%d: Cannot find declaration of class '%s'", __LINE__, sp->name);

    if (entry->sub1->type == ESC_FTYPE || entry->sub1->type == ESC_MAP)
        p = entry->sub1;
    else
        p = entry->sub1->sub1;

    /* traverse declarations and output assignment code for each variable */
	while (stmts != NULL) {
        switch (stmts->type) {
        case DECL:
			if (p == NULL) return;
            if (p->type == ESC_FTYPE || p->type == ESC_MAP) {
                c_outi("%sesc_bits = ", prefix);
                c_expression(p->e3, 0);
                c_out(";\n");
            }

            c_outi("%sarg%s%s = ", prefix, c_scope(), stmts->sp->name);

            /* figure out if we have simple assignment or escape */
            if (p->type == ESC_FTYPE || p->type == ESC_MAP)
                c_map_get_assign_esc(p);
            else {
		        if (stmts->sp->ptype->ident == FLOAT && p->e1->type == DOUBLE)
                    c_out("(float)");
                c_expression(p->e1, 0);
            }
            c_out(";\n");

            p = p->next;
            break;
            
        default:
            return;
        }
        stmts = stmts->next;
    }
}
Exemplo n.º 6
0
/* output assignment statements for a class map entry */
static void c_map_putxml_assign_class(symbol_t *sp, list_t *entry)
{
    list_t *p;

    /* find the statements for this class */
    list_t *stmts = find_class_stmts(sp->ptype);
    if (stmts == NULL) 
        fatal("Internal error CM%d: Cannot find declaration of class '%s'", __LINE__, sp->name);

    if (entry->sub1->type == ESC_FTYPE || entry->sub1->type == ESC_MAP)
        p = entry->sub1;
    else
        p = entry->sub1->sub1;

    /* output the beginning of the value element for the XML document */ 
    if (cpp())
        c_outi("%s(", xml_func4);
    else if (java())
        c_outi("XML.%s(", xml_func4);
    c_out("\"value\", 0);\n");

    /* traverse declarations and output assignment code for each variable */
	while (stmts != NULL) {
        switch (stmts->type) {
        case DECL:
			if (p == NULL) return;
            if (p->type == ESC_FTYPE || p->type == ESC_MAP) {
                c_outi("%sesc_bits = ", prefix);
                c_expression(p->e3, 0);
                c_out(";\n");
            }
            else
                c_outi("%sesc_bits = 0;\n", prefix);

            c_outi("%sarg%s%s = ", prefix, c_scope(), stmts->sp->name);

            /* figure out if we have simple assignment or escape */
            if (entry->sub1->type == ESC_FTYPE || entry->sub1->type == ESC_MAP)
                c_map_get_assign_esc(p);
            else {
		        if (stmts->sp->ptype->ident == FLOAT && p->e1->type == DOUBLE)
                    c_out("(float)");
                c_expression(p->e1, 0);
            }
            c_out(";\n");
       
            /* output an element for each class member value, which corresponds to the code */
            c_xml_map_var_simple(stmts->sp, 0);

            p = p->next;
            break;
            
        default:
            break;
        }
        stmts = stmts->next;
    }

    /* output the end of the value element for the xml document */ 
    if (cpp())
        c_outi("%s(", xml_func5);
    else if (java())
        c_outi("XML.%s(", xml_func5);
    c_out("\"</value>\");\n");
}