Пример #1
0
/* output assignment statements for a simple map entry */
static void c_map_get_assign_simple(symbol_t* sp, list_t* entry)
{
    list_t *p = entry->sub1;

    if (p->type == ESC_FTYPE || p->type == ESC_MAP) {
        c_outi("%sesc_bits = ", prefix);
        c_expression(p->e3, 0);
        c_out(";\n");
    }

    if (cpp()) 
        c_outi("*%sarg = ", prefix);
    else if (java())
        c_outi("%sarg = ", prefix);

    /* 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 (sp->ptype->ident == FLOAT && p->e1->type == DOUBLE)
            c_out("(float)");
		c_expression(p->e1, 0);
	}
    c_out(";\n");
}
Пример #2
0
/* output assignment statements for a simple map entry */
static void c_map_putxml_assign_simple(symbol_t* sp, list_t* entry)
{
    list_t *p = entry->sub1;

    if (p->type == ESC_FTYPE || p->type == ESC_MAP) {
        c_outi("%sesc_bits = ", prefix);
        c_expression(p->e3, 0);
        c_out(";\n");
    }

    if (cpp()) 
        c_outi("*%sarg = ", prefix);
    else if (java())
        c_outi("%sarg = ", prefix);

    /* 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 (sp->ptype->ident == FLOAT && entry->sub1->e1->type == DOUBLE)
            c_out("(float)");
		c_expression(p->e1, 0);
	}
    c_out(";\n");

    /* output an element for the value, which corresponds to the code */
    c_xml_map_var_simple(sp, 1);
}
Пример #3
0
/* compare statements for a simple map entry */
static void c_map_put_compare_simple(symbol_t *sp, list_t *entry)
{
    c_out("%sarg == ", prefix);
	if (sp->ptype->ident == FLOAT && entry->e1->type == DOUBLE) 
        c_out("(float)");
	c_expression(entry->e1, 0);
}
Пример #4
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;
    }
}
Пример #5
0
/* output verbatim code */
void verbatim(verbatim_t *vp)
{
    if (vp == NULL || vp->str == NULL) return;
    
    /* output preprocessor directive for file/line info */
    if (!supp_lineno && cpp()) {
        c_out("#");
        c_out("line %d \"%s\"\n", vp->lineno, filename);
    }
    c_outi("%s\n", vp->str);
}
Пример #6
0
void write_cdr(SE *e) {
  if(e==NIL){c_out(")"); return;}
  _write_se(car(e));
  if(cdr(e)==NIL){c_out(")"); return;}
  if(type(cdr(e))!=CONS) {
      c_out(" . ");
      _write_se(cdr(e));
      c_out(")");
      return;
    }
  c_out(" ");
  write_cdr(cdr(e));
}
Пример #7
0
void _write_se(SE *e) {
  char numbuf[23];
  if(e==NIL) {
      c_out("()");
      return;
    }
  switch(type(e)) {
    case NUM: sprintf(numbuf,"%d",numval(e));
              c_out(numbuf); break;
    case SYM: c_out(symval(e)); break;
    case CONS: c_out("("); write_cdr(e); break;
    }
}
Пример #8
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;
    }
}
Пример #9
0
/* put the simple value for the escape code */
static void c_map_put_esc_simple(symbol_t *sp, list_t *entry)
{
	node_t *pp = entry->e3;
	if (!is_literal(pp->op)) {
        c_out("0");
        return;
    }

	/* no map cascades at this time */
    if (entry->type == ESC_MAP) 
        fatal("Internal error CM%d: Map cascading not supported", __LINE__);
	
    c_outi("%sbs.%s%s%s", prefix, 
	       (sp->modifiers & M_LITTLE ? "little_" : ""),
	       (sp->modifiers & M_UNSIGNED || sp->ptype->ident > INT ? "" : "s"), "put");

    if (sp->ptype->ident <= INT) {
        if (java() && sp->modifiers & M_LONG) 
            c_out("long(");
        else
            c_out("bits(%sarg,", prefix);
        c_expression(pp, 0);
		c_out(");\n");
    }
    else if (sp->ptype->ident == FLOAT)
        c_out("float(%sarg);\n", prefix);
    else if (sp->ptype->ident == DOUBLE && (sp->modifiers & M_LONG))
        c_out("ldouble(%sarg);\n", prefix);
    else
        c_out("double(%sarg);\n", prefix);
}
Пример #10
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;
    }
}
Пример #11
0
/* generate map putxml method */
static void c_map_putxml(symbol_t* sp, list_t* stmts)
{
	c_out("\n");
    if (cpp()) {
        c_outi("int %s::putxml(%s &%sbs, short int bAttr, %s%s *%sarg, int *%sparse, int *%scode) {\n", 
               sp->name, bitstream_class, prefix, 
               ((sp->modifiers & M_UNSIGNED) ? "unsigned " : ""),
               sp->ptype->name, prefix, prefix, prefix);
		c_identlevel++;
		/* declare hit variable (used for return value), data and size */
		c_outi("int %sdata = 0, %ssize = 0;\n", prefix, prefix);
        c_outi("int %sesc_bits = 0;\n", prefix);
		c_outi("int %shit = 1;\n\n", prefix);
    } 
    else if (java()) {
		c_outi("public static %s putxml(%s %sbs, boolean bAttr) throws IOException {\n", 
               map_result, bitstream_class, prefix, sp->ptype->name, prefix, prefix, prefix);
		c_identlevel++;
		/* declare hit variable (used for return value), data and size */
		c_outi("int %sdata = 0, %ssize = 0;\n", prefix, prefix);
        c_outi("int %sesc_bits = 0;\n", prefix);
		c_outi("boolean %shit = true;\n", prefix);
		if (sp->ptype->ident == CLASS_TYPE) 
			c_outi("%s %sarg = new %s();\n\n", sp->ptype->name, prefix, sp->ptype->name);
		else
			c_outi("%s %sarg = %s%s;\n\n",
                   sp->ptype->name, prefix, (sp->ptype->ident == FLOAT) ? "(float)" : "",
                   (sp->ptype->ident <= INT) ? "0" : "0.0");
	}
    
    /* output the core putxml code (series of getbits with case statements) */
    c_map_putxml_core(sp, stmts);

    /* return code and size, if requested */
    if (cpp()) {
        c_outi("if (%sparse != NULL) *%sparse = %ssize;\n", prefix, prefix, prefix);
        c_outi("if (%scode != NULL) *%scode = %sdata;\n", prefix, prefix, prefix);
		c_outi("return %shit;\n", prefix);
	}
    else if (java())
        c_outi("return new %s(%shit, %sdata, %ssize, %sarg);\n", map_result, prefix, prefix, prefix, prefix);
	
    c_identlevel--;
    c_outi("}\n");
}
Пример #12
0
/* generate schema description for the map */
static void c_map_xsd(symbol_t* sp, list_t* stmts)
{
    c_outi("<xsd:element name=\"code\" type=\"flBit\"/>\n");

    if (sp->ptype->ident != CLASS_TYPE) {
        c_outi("<xsd:element name=\"value\"");
        if (sp->ptype->ident == CHAR) {
            if (sp->modifiers & M_UNSIGNED) 
                c_out(" type=\"flUChar\"");
            else 
                c_out(" type=\"flSChar\"");
        }
        else {
            if (sp->ptype->ident <= INT) {
                if (sp->modifiers & M_UNSIGNED)
                    c_out(" type=\"flUInt\"");
                else 
                    c_out(" type=\"flSInt\"");
            }
            else if (sp->ptype->ident == FLOAT) 
                c_out(" type=\"flFloat\"");
            else if (sp->ptype->ident == DOUBLE)
                c_out(" type=\"flDouble\"");
            else
                fatal("Internal error CM%d: Expected simple type", __LINE__);
        }
        c_out("/>\n");
    }
    else {
        c_outi("<xsd:element name=\"value\">\n");
        c_identlevel++;
        c_outi("<xsd:complexType>\n");
        c_identlevel++;
        c_outi("<xsd:sequence>\n");
        c_identlevel++;

        c_map_xsd_assign_class(sp);

        c_identlevel--;
        c_outi("</xsd:sequence>\n");
        c_identlevel--;
        c_outi("</xsd:complexType>\n");
        c_identlevel--;
        c_outi("</xsd:element>\n");
    }
}
Пример #13
0
/* put the parsing of a variable with simple parse expr as an XML element */
void c_xml_var_simple(symbol_t* sp, node_t *align, int dims, node_t **dim)
{
    c_outi("if (bAttr) {\n");
    c_identlevel++;    

    if (cpp())
        c_outi("%s(\"<%s", xml_func3, sp->name);
    else if (java())
        c_outi("XML.%s(\"<%s", xml_func3, sp->name);
 
    /* bit values are accessed as integer values */
    if (sp->ptype->ident == CHAR) {
        if (sp->modifiers & M_UNSIGNED) 
            c_out(" type=\\\"flUChar\\\"");
        else 
            c_out(" type=\\\"flSChar\\\"");
    }
    else if (sp->ptype->ident <= INT) {
        if (sp->modifiers & M_UNSIGNED) 
            c_out(" type=\\\"flUInt\\\"");
        else 
            c_out(" type=\\\"flSInt\\\"");
    }
    else if (sp->ptype->ident == FLOAT) 
        c_out(" type=\\\"flFloat\\\"");
    else if (sp->ptype->ident == DOUBLE)
        c_out(" type=\\\"flDouble\\\"");
	else 
        fatal("Internal error CX%d: Expected simple type", __LINE__);

    c_xml_var_helper(sp, align, dims, dim);

    c_identlevel--;    
    c_outi("}\n");

    // !bAttr

    c_outi("else {\n");
    c_identlevel++; 

    if (cpp())
        c_outi("%s(\"<%s", xml_func3, sp->name);
    else if (java())
        c_outi("XML.%s(\"<%s", xml_func3, sp->name);

    c_xml_var_helper(sp, align, dims, dim);

    c_identlevel--;    
    c_outi("}\n");
}
Пример #14
0
/* get an escape value */
static void c_map_get_assign_esc(list_t *entry)
{
    node_t *esc_type = entry->e2;
    unsigned mod = entry->e1->left.ival;

    /* no map cascades at this time */
    if (entry->type == ESC_MAP) 
        fatal("Internal error CM%d: Map cascading not supported", __LINE__);
    
    /* explicit casting is needed for Java */
	if (java()) 
        if (esc_type->ptype->ident != BIT && esc_type->ptype->ident != INT) 
            c_out("(%s) ", esc_type->ptype->name);

    /* parse length should be a literal */
    if (!is_literal(entry->e3->op)) {
        c_out("0"); /* error already reported - just assign 0 */
        return;
    }

    c_out("%sbs.%s%sget", prefix, 
	      (mod & M_LITTLE ? "little_" : ""),
	      (mod & M_UNSIGNED || esc_type->ptype->ident > INT ? "" : "s"));

    if (esc_type->ptype->ident <= INT) {
        if (java() && esc_type->ptype->modifiers & M_LONG)
            c_out("long(%sesc_bits)", prefix);
        else 
            c_out("bits(%sesc_bits)", prefix);
    }
    else if (esc_type->ptype->ident == FLOAT) 
        c_out("float()");
    else if (esc_type->ptype->ident == DOUBLE && (esc_type->ptype->modifiers & M_LONG)) 
        c_out("ldouble()");
    else 
        c_out("double()");    
}
Пример #15
0
static void c_map_xsd_assign_class(symbol_t *sp)
{
    /* 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:
            c_outi("<xsd:element name=\"%s\"", stmts->sp->name);
            if (stmts->sp->ptype->ident == CHAR) {
                if (sp->modifiers & M_UNSIGNED) 
                    c_out(" type=\"flUChar\"/>\n");
                else 
                    c_out(" type=\"flSChar\"/>\n");
            }
            else if (stmts->sp->ptype->ident <= INT) {
                if (stmts->sp->modifiers & M_UNSIGNED) 
                    c_out(" type=\"flUInt\"/>\n");
                else 
                    c_out(" type=\"flSInt\"/>\n");
            }
            else if (stmts->sp->ptype->ident == FLOAT) 
                c_out(" type=\"flFloat\"/>\n");
            else if (stmts->sp->ptype->ident == DOUBLE)
                c_out(" type=\"flDouble\"/>\n");
	        else 
                fatal("Internal error CM%d: Expected simple type", __LINE__);

        default:
            break;
        }
        stmts = stmts->next;
    }
}
Пример #16
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));
    }
}
Пример #17
0
/* generate map definition */
void map_decl(symbol_t *sp, list_t *stmts)
{
    FILE *tmp;

    if (sp == NULL) return;
    if (sp->ptype == NULL) 
        fatal("Internal error CM%d: Map without type information", __LINE__);
	
    if (cpp())
        c_out("\nclass %s {\n", sp->name);
    else if (java())
        c_out("\npublic class %s {\n", sp->name); 
    else if (xsd()) {
        c_out("\n<xsd:complexType name=\"%s\">\n", sp->name);
    	c_identlevel++;
		c_outi("<xsd:sequence>\n");
    }
    
    c_identlevel++;

    /* if doing C++, declare nextvlc()/getvlc()/putvlc() and switch output files */
    if (cpp()) {
        /* nextvlc(), getvlc() */
        if (gen_get) {
            c_outi("public: static int nextvlc(%s &%sbs, %s%s *%sarg, int *%sparse=NULL, int *%scode=NULL);\n",
                   bitstream_class, prefix, 
                   ((sp->modifiers & M_UNSIGNED) ? "unsigned " : ""),
                   sp->ptype->name, prefix, prefix, prefix);
            c_outi("public: static int getvlc(%s &%sbs, %s%s *%sarg, int *%sparse=NULL, int *%scode=NULL);\n",
                   bitstream_class, prefix, 
                   ((sp->modifiers & M_UNSIGNED) ? "unsigned " : ""),
                   sp->ptype->name, prefix, prefix, prefix);
        }
        /* putvlc() */
        if (gen_put) {
			if (sp->ptype->ident == CLASS_TYPE)
				/* if CLASS_TYPE pass a pointer to argument */
				c_outi("public: static int putvlc(%s &%sbs, %s%s *%sarg, int *%sparse=NULL, int *%scode=NULL);\n",
                       bitstream_class, prefix, 
                       ((sp->modifiers & M_UNSIGNED) ? "unsigned " : ""),
                       sp->ptype->name, prefix, prefix, prefix);
			else
				/* otherwise, just value */
				c_outi("public: static int putvlc(%s &%sbs, %s%s %sarg, int *%sparse=NULL, int *%scode=NULL);\n",
                       bitstream_class, prefix, 
                       ((sp->modifiers & M_UNSIGNED) ? "unsigned " : ""),
                       sp->ptype->name, prefix, prefix, prefix);

        }
        /* putxml() */
        if (gen_putxml) {
            c_outi("public: static int putxml(%s &%sbs, short int bAttr, %s%s *%sarg, int *%sparse=NULL, int *%scode=NULL);\n",
                   bitstream_class, prefix, 
                   ((sp->modifiers & M_UNSIGNED) ? "unsigned " : ""),
                   sp->ptype->name, prefix, prefix, prefix);
        }
        c_identlevel = 0;
        tmp = ofp;
        ofp = ofp2;
    }

    if (cpp() || java()) {
	    /* generate getvlc function; no next, if the map uses escape */
	    if (gen_get && !sp->escape) 
            c_map_next(sp, stmts);
        /* generate getvlc function */
        if (gen_get) 
            c_map_get(sp, stmts);
        /* generate putvlc function */
        if (gen_put) 
            c_map_put(sp, stmts);
        /* generate putxml function */
        if (gen_putxml) 
            c_map_putxml(sp, stmts);
    }
	else if (xsd()) 
        c_map_xsd(sp, stmts);

    /* switch back to .h file */
    if (cpp()) {
        c_identlevel = 1;
        ofp = tmp;
    }

    c_identlevel--;

    if (cpp()) 
        c_out("};\n");
    else if (java())
        c_out("}\n");
    else if (xsd()) {
		c_outi("</xsd:sequence>\n");
		c_identlevel--;
        c_out("</xsd:complexType>\n");
    }
}
Пример #18
0
/* Core code for putxml - checks for a match against the map codes.  The routine uses 
 * two variables: _data and _size, that contain the matched code.  If no match is found, then 
 * the last code entry is used.  If we get a hit, the _hit variable is assigned 1, otherwise 
 * it is left untouched (previously set to 0).
 */
static void c_map_putxml_core(symbol_t *sp, list_t *stmts)
{
    list_t *lp = stmts;
    int size;

    /* sanity check */
    if (lp->e1 == NULL || lp->e1->op != BIT_LITERAL || lp->e1->left.bit == NULL)
        fatal("Internal error CM%d: Expected code entry with bit literal", __LINE__);
    
    size = lp->e1->left.bit->len;
    
    /* get data */
    c_outi("%sdata = %sbs.nextbits(%d);\n", prefix, prefix, size);
    c_outi("switch (%sdata) {\n", prefix);
    while (lp != NULL) {
        /* sanity check */
        if (lp->e1 == NULL || lp->e1->op != BIT_LITERAL || lp->e1->left.bit == NULL)
            fatal("Internal error CM%d: Expected code entry with bit literal", __LINE__);

        /* did the size change? */
        if (lp->e1->left.bit->len != size) {
            c_outi("default:\n");
            c_identlevel++;
            c_map_putxml_core(sp, lp);
            c_identlevel--;
            break;
        }

        /* check for match */
        c_outi("case %d:\n", lp->e1->left.bit->val);
        c_identlevel++;

        /* skip bits, if we are doing get - must be done here so that escapes read correctly */
        c_outi("%sbs.skipbits(%d);\n", prefix, size);

        /* output code element for the XML document */
        c_outi("if (bAttr) {\n");
        c_identlevel++; 
        
        if (cpp())
            c_outi("%s(", xml_func3);
        else if (java())
            c_outi("XML.%s(", xml_func3);
        c_out("\"<code type=\\\"flBit\\\" bitLen=\\\"%d\\\">%d</code>\");\n", lp->e1->left.bit->len, lp->e1->left.bit->val);
        
        c_identlevel--; 
        c_outi("}\n");
        c_outi("else {\n");
        c_identlevel++; 

        if (cpp())
            c_outi("%s(", xml_func3);
        else if (java())
            c_outi("XML.%s(", xml_func3);
        c_out("\"<code bitLen=\\\"%d\\\">%d</code>\");\n", lp->e1->left.bit->len, lp->e1->left.bit->val);
  
        c_identlevel--; 
        c_outi("}\n");

        /* output assignment code */
        c_map_putxml_assign(sp, lp);
        
        /* save size */
        c_outi("%ssize = %d;\n", prefix, lp->e1->left.bit->len);

        c_outi("break;\n");
        c_identlevel--;

        /* if at the end, set hit to 0 and use last entry */
        if (lp->next == NULL) {
            c_outi("default:\n");
            c_identlevel++;
            if (cpp())
                c_outi("%shit = 0;\n", prefix);
			else if (java())
                c_outi("%shit = false;\n", prefix);
            c_identlevel--;
        }
        /* next code */
        lp = lp->next;
    }
    /* close switch statement */
    c_outi("}\n");
}
Пример #19
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");
}
Пример #20
0
/* Core code for putvlc - checks for a match against the map codes.  The routine uses 
 * two variables: _data and _size, that contain the matched code.  If no match is found, then 
 * the last code entry is used.  If we get a hit, the _hit variable is assigned 1, otherwise 
 * it is left untouched (previously set to 0).
 */
static void c_map_put_core(symbol_t *sp, list_t *stmts)
{
    list_t *lp = stmts;
    list_t *last = NULL;
	int size;    
     
    /* put data */
    while (lp != NULL) {
        /* sanity check */
        if (lp->e1 == NULL || lp->e1->op != BIT_LITERAL || lp->e1->left.bit == NULL)
            fatal("Internal error CM%d: Expected code entry with bit literal", __LINE__);
		
        if (lp->sub1->type == ESC_FTYPE || lp->sub1->type == ESC_MAP) {
            /* save one and only escape code for last */
            last = lp;
            lp = lp->next;
            continue;
        }

		/* get bit length */
		size = lp->e1->left.bit->len;
		
        /* check for match */
        c_outi("if (");
        c_map_put_compare(sp, lp->sub1);
        c_out(") {\n");
        c_identlevel++;

		/* put bits */
        if (!lp->sp) {
            if (java() && sp->ptype->modifiers & M_LONG) 
                c_outi("%sbs.putlong(%d,%d);\n", prefix, lp->e1->left.bit->val, size);
            else
                c_outi("%sbs.putbits(%d,%d);\n", prefix, lp->e1->left.bit->val, size);
        }
        else {
            if (java() && sp->ptype->modifiers & M_LONG) 
                c_outi("%sbs.%sputlong(%d,%d);\n", prefix, 
			           (sp->ptype->id->modifiers & M_LITTLE ? "little_" : ""), lp->e1->left.bit->val, size);
            else
                c_outi("%sbs.%sputbits(%d,%d);\n", prefix, 
			           (sp->ptype->id->modifiers & M_LITTLE ? "little_" : ""), lp->e1->left.bit->val, size);
        }

        /* save size */
        c_outi("%ssize = %d;\n", prefix, lp->e1->left.bit->len);
        /* save data */
		c_outi("%sdata = %d;\n", prefix, lp->e1->left.bit->val);
       
        /* return code and size, if requested */
        if (cpp()) {
            c_outi("if (%sparse != NULL) *%sparse = %ssize;\n", prefix, prefix, prefix);
            c_outi("if (%scode != NULL) *%scode = %sdata;\n", prefix, prefix, prefix);
		    c_outi("return %shit;\n", prefix);
	    }
        else if (java()) 
            c_outi("return new %s(%shit, %sdata, %ssize, %sarg);\n", map_result, prefix, prefix, prefix, prefix);

        c_identlevel--;
        c_outi("}\n");
	    
        /* next code */
        lp = lp->next;
    }
    /* no escape code */
    if (last == NULL) {
        if (cpp()) {
            c_outi("%shit = 0;\n", prefix);
            c_outi("if (%sparse != NULL) *%sparse = %ssize;\n", prefix, prefix, prefix);
            c_outi("if (%scode != NULL) *%scode = %sdata;\n", prefix, prefix, prefix);
		    c_outi("return %shit;\n", prefix);
		}
        else if (java()) {
            c_outi("%shit = false;\n", prefix);
            c_outi("return new %s(%shit, %sdata, %ssize, %sarg);\n", map_result, prefix, prefix, prefix, prefix);
        }
    }
    else {
		/* get bit length */
		size = last->e1->left.bit->len;

		/* put bits */
        if (!last->sp) {
            if (java() && sp->ptype->modifiers & M_LONG) 
                c_outi("%sbs.putlong(%d,%d);\n", prefix, last->e1->left.bit->val, size);
            else
                c_outi("%sbs.putbits(%d,%d);\n", prefix, last->e1->left.bit->val, size);
        }
        else {
            if (java() && sp->ptype->modifiers & M_LONG) 
                c_outi("%sbs.%sputlong(%d,%d);\n", prefix, 
			           (sp->ptype->id->modifiers & M_LITTLE ? "little_" : ""), last->e1->left.bit->val, size);
            else
                c_outi("%sbs.%sputbits(%d,%d);\n", prefix, 
			           (sp->ptype->id->modifiers & M_LITTLE ? "little_" : ""), last->e1->left.bit->val, size);
        }

        /* save size */
        c_outi("%ssize = %d;\n", prefix, last->e1->left.bit->len);
        /* save data */
		c_outi("%sdata = %d;\n", prefix, last->e1->left.bit->val);

        if (sp->ptype->ident != CLASS_TYPE)
            c_map_put_esc_simple(sp, last->sub1);
        else
            c_map_put_esc_class(sp, last->sub1);

        if (cpp()) {
            c_outi("if (%sparse != NULL) *%sparse = %ssize;\n", prefix, prefix, prefix);
            c_outi("if (%scode != NULL) *%scode = %sdata;\n", prefix, prefix, prefix);
		    c_outi("return %shit;\n", prefix);
		}
        else if (java()) {
            c_outi("return new %s(%shit, %sdata, %ssize, %sarg);\n", map_result, prefix, prefix, prefix, prefix);
        }
    }
}
Пример #21
0
/* helper function called by the function below */
static void c_xml_var_helper(symbol_t* sp, node_t *align, int dims, node_t **dim)
{
    if (align != NULL) {
        c_out(" aligned=\\\"");
        c_expression(align, 0);
        c_out("\\\"");
    }

    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__);

        c_out("</%s>\", %sparse, %s", sp->name, prefix, sp->name);
        if (dims > 0)
            c_array_proper(sp, dims);
        c_out(");\n");
    }
    else if (java()) {
        c_out(" bitLen=\\\"");
        c_out("\" + %sparse + \"\\\">", prefix);
        /* output the content (between the element tags) in the correct format */
        c_out("\" + %s", sp->name);
		if (dims > 0) 
            c_array_proper(sp, dims);
		c_out(" + \"</%s>\");\n", sp->name);
    }
}