for (; members; members = members->next)
{ if (strcmp(members->name, str) == 0)
{ if (next == NULL)
{ /* found the end */ switch (members->type->type)
{ case ECPGt_array: return new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(members->type->u.element->type, members->type->u.element->size, members->type->u.element->counter), members->type->size), brace_level); case ECPGt_struct: case ECPGt_union: return new_variable(name, ECPGmake_struct_type(members->type->u.members, members->type->type, members->type->type_name, members->type->struct_sizeof), brace_level); default: return new_variable(name, ECPGmake_simple_type(members->type->type, members->type->size, members->type->counter), brace_level);
}
} else
{
*next = c; if (c == '[')
{ int count;
/* *Wedon'tcareaboutwhat'sinsidethearraybracketsso *justeatupthecharacter
*/ for (count = 1, end = next + 1; count; end++)
{ switch (*end)
{ case'[':
count++; break; case']':
count--; break; default: break;
}
}
} else
end = next;
switch (*end)
{ case'\0': /* found the end, but this time it has to be
* an array element */ if (members->type->type != ECPGt_array)
mmfatal(PARSE_ERROR, "incorrectly formed variable \"%s\"", name);
/* first get the mother structure entry */
*next = '\0';
p = find_variable(name);
if (c == '-')
{ if (p->type->type != ECPGt_array)
mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer", name);
if (p->type->u.element->type != ECPGt_struct && p->type->u.element->type != ECPGt_union)
mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer to a structure or a union", name);
/* restore the name, we will need it later */
*next = c;
return find_struct_member(name, ++end, p->type->u.element->u.members, p->brace_level);
} else
{ if (next == end)
{ if (p->type->type != ECPGt_struct && p->type->type != ECPGt_union)
mmfatal(PARSE_ERROR, "variable \"%s\" is neither a structure nor a union", name);
/* restore the name, we will need it later */
*next = c;
return find_struct_member(name, end, p->type->u.members, p->brace_level);
} else
{ if (p->type->type != ECPGt_array)
mmfatal(PARSE_ERROR, "variable \"%s\" is not an array", name);
if (p->type->u.element->type != ECPGt_struct && p->type->u.element->type != ECPGt_union)
mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer to a structure or a union", name);
/* restore the name, we will need it later */
*next = c;
for (p = allvariables; p; p = p->next)
{ if (strcmp(p->name, name) == 0) return p;
}
return NULL;
}
/* Note that this function will end the program in case of an unknown */ /* variable */ struct variable *
find_variable(constchar *name)
{ char *next,
*end; struct variable *p; int count;
next = (char *) strpbrk(name, ".[-"); if (next)
{ if (*next == '[')
{ /* *Wedon'tcareaboutwhat'sinsidethearraybracketssojust *eatupthecharacters
*/ for (count = 1, end = next + 1; count; end++)
{ switch (*end)
{ case'[':
count++; break; case']':
count--; break; case'\0':
mmfatal(PARSE_ERROR, "unmatched bracket in variable \"%s\"", name); break; default: break;
}
} if (*end == '.')
p = find_struct(name, next, end); else
{ char c = *next;
*next = '\0';
p = find_simple(name); if (p == NULL)
mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name); if (p->type->type != ECPGt_array)
mmfatal(PARSE_ERROR, "variable \"%s\" is not a pointer", name);
*next = c; switch (p->type->u.element->type)
{ case ECPGt_array: return new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(p->type->u.element->u.element->type, p->type->u.element->u.element->size, p->type->u.element->u.element->counter), p->type->u.element->size), p->brace_level); case ECPGt_struct: case ECPGt_union: return new_variable(name, ECPGmake_struct_type(p->type->u.element->u.members, p->type->u.element->type, p->type->u.element->type_name, p->type->u.element->struct_sizeof), p->brace_level); default: return new_variable(name, ECPGmake_simple_type(p->type->u.element->type, p->type->u.element->size, p->type->u.element->counter), p->brace_level);
}
}
} else
p = find_struct(name, next, next);
} else
p = find_simple(name);
if (p == NULL)
mmfatal(PARSE_ERROR, "variable \"%s\" is not declared", name);
for (p = allvariables, prev = NULL; p; p = next)
{
next = p->next; if (p->brace_level >= brace_level)
{ /* remove it, but first remove any references from cursors */ struct cursor *ptr;
for (p = argsinsert; p; p = next)
{
next = p->next;
free(p);
}
argsinsert = NULL; for (p = argsresult; p; p = next)
{
next = p->next;
free(p);
}
argsresult = NULL;
}
/* Insert a new variable into our request list. *Note:Thelistisdumpedfromtheend,
* so we have to add new entries at the beginning */ void
add_variable_to_head(struct arguments **list, struct variable *var, struct variable *ind)
{ struct arguments *p = (struct arguments *) mm_alloc(sizeof(struct arguments));
for (p = *list; p; p = p->next)
{ if (p->variable == var)
{
found = true; break;
}
prev = p;
} if (found)
{ if (prev)
prev->next = p->next; else
*list = p->next;
free(p);
}
}
/* Dump out a list of all the variable on this list. Thisisarecursivefunctionthatworksfromtheendofthelistand deletesthelistaswegoon.
*/ void
dump_variables(struct arguments *list, int mode)
{ char *str_zero;
/* Then the current element and its indicator */
ECPGdump_a_type(base_yyout, list->variable->name, list->variable->type, list->variable->brace_level,
list->indicator->name, list->indicator->type, list->indicator->brace_level,
NULL, NULL, str_zero, NULL, NULL);
/* Then release the list element. */ if (mode != 0)
free(list);
free(str_zero);
}
void
check_indicator(struct ECPGtype *var)
{ /* make sure this is a valid indicator variable */ switch (var->type)
{ struct ECPGstruct_member *p;
case ECPGt_short: case ECPGt_int: case ECPGt_long: case ECPGt_long_long: case ECPGt_unsigned_short: case ECPGt_unsigned_int: case ECPGt_unsigned_long: case ECPGt_unsigned_long_long: break;
case ECPGt_struct: case ECPGt_union: for (p = var->u.members; p; p = p->next)
check_indicator(p->type); break;
case ECPGt_array:
check_indicator(var->u.element); break; default:
mmerror(PARSE_ERROR, ET_ERROR, "indicator variable must have an integer type"); break;
}
}
for (this = types; this != NULL; this = this->next)
{ if (strcmp(this->name, name) == 0) returnthis;
}
if (!noerror)
mmfatal(PARSE_ERROR, "unrecognized data type name \"%s\"", name);
return NULL;
}
void
adjust_array(enum ECPGttype type_enum, constchar **dimension, constchar **length, constchar *type_dimension, constchar *type_index, int pointer_len, bool type_definition)
{ if (atoi(type_index) >= 0)
{ if (atoi(*length) >= 0)
mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
*length = type_index;
}
if (atoi(type_dimension) >= 0)
{ if (atoi(*dimension) >= 0 && atoi(*length) >= 0)
mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
if (atoi(*dimension) >= 0)
*length = *dimension;
*dimension = type_dimension;
}
if (pointer_len > 2)
mmfatal(PARSE_ERROR, ngettext("multilevel pointers (more than 2 levels) are not supported; found %d level", "multilevel pointers (more than 2 levels) are not supported; found %d levels", pointer_len),
pointer_len);
if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char && type_enum != ECPGt_string)
mmfatal(PARSE_ERROR, "pointer to pointer is not supported for this data type");
if (pointer_len > 1 && (atoi(*length) >= 0 || atoi(*dimension) >= 0))
mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
if (atoi(*length) >= 0 && atoi(*dimension) >= 0 && pointer_len)
mmfatal(PARSE_ERROR, "multidimensional arrays are not supported");
switch (type_enum)
{ case ECPGt_struct: case ECPGt_union: /* pointer has to get dimension 0 */ if (pointer_len)
{
*length = *dimension;
*dimension = "0";
}
if (atoi(*length) >= 0)
mmfatal(PARSE_ERROR, "multidimensional arrays for structures are not supported");
break; case ECPGt_varchar: case ECPGt_bytea: /* pointer has to get dimension 0 */ if (pointer_len)
*dimension = "0";
/* one index is the string length */ if (atoi(*length) < 0)
{
*length = *dimension;
*dimension = "-1";
}
break; case ECPGt_char: case ECPGt_unsigned_char: case ECPGt_string: /* char ** */ if (pointer_len == 2)
{
*length = *dimension = "0"; break;
}
/* pointer has to get length 0 */ if (pointer_len == 1)
*length = "0";
/* one index is the string length */ if (atoi(*length) < 0)
{ /* *makesurewereturnlength=-1forarrayswithoutgiven *bounds
*/ if (atoi(*dimension) < 0 && !type_definition)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.