const proc: process_cpy_declaration (in type: object_type,
inout expr_type: c_expr) is forward;
const proc: process_cpy_call (in type: object_type,
in string: param_a, in string: param_b, inout string: expr) is forward;
const proc: process_arr_cpy_declaration (in type: object_type,
inout expr_type: c_expr) is func
local
var string: diagnosticLine is "";
var string: select_value is "";
var integer: arraySize is 0;
begin
if object_type in typeData.copyFunction then
diagnosticLine := diagnosticLine(typeData.copyFunction[object_type]);
end if;
select_value := select_value_from_rtlObjectStruct(typeData.array_element[object_type]);
process_create_declaration(typeData.array_element[object_type], c_expr);
process_destr_declaration(typeData.array_element[object_type], c_expr);
process_cpy_declaration(typeData.array_element[object_type], c_expr);
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "static void cpy_";
c_expr.expr &:= str(typeNumber(object_type));
c_expr.expr &:= " (";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= " *a, ";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= " b)\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "{\n";
if object_type not in typeData.array_minIdx or
object_type not in typeData.array_maxIdx then
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "memSizeType size_a = (uintType)((*a)->max_position - (*a)->min_position + 1);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "memSizeType size_b = (uintType)(b->max_position - b->min_position + 1);\n";
c_expr.expr &:= diagnosticLine;
if typeData.array_element[object_type] in typeData.typeCategory and
typeData.typeCategory[typeData.array_element[object_type]] in simpleValueType then
c_expr.expr &:= "if (size_a < size_b) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "arrFree(*a);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "*a=(";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= ")arrMalloc(b->min_position, b->max_position);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "memcpy((*a)->arr, b->arr, size_b * sizeof(genericType));\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "} else /* size_a >= size_b */ {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "(*a)->min_position = b->min_position;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "(*a)->max_position = b->max_position;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "memmove((*a)->arr, b->arr, size_b * sizeof(genericType));\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "if (size_a != size_b) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "*a=(";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= ")arrRealloc((arrayType)(*a), size_a, size_b);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
else
c_expr.expr &:= "memSizeType i;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "(*a)->min_position = b->min_position;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "(*a)->max_position = b->max_position;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "if (size_a < size_b) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "*a=(";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= ")arrRealloc((arrayType)(*a), size_a, size_b);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "for (i = size_a; i < size_b; i++) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "(*a)->arr[i]";
c_expr.expr &:= select_value;
c_expr.expr &:= "=";
process_create_call(typeData.array_element[object_type],
"b->arr[i]" & select_value, c_expr.expr);
c_expr.expr &:= ";\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "while (size_a != 0) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "size_a--;\n";
c_expr.expr &:= diagnosticLine;
process_cpy_call(typeData.array_element[object_type],
"(*a)->arr[size_a]" & select_value,
"b->arr[size_a]" & select_value, c_expr.expr);
c_expr.expr &:= ";\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "} else /* size_a >= size_b */ {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "for (i = 0; i < size_b; i++) {\n";
c_expr.expr &:= diagnosticLine;
process_cpy_call(typeData.array_element[object_type],
"(*a)->arr[i]" & select_value,
"b->arr[i]" & select_value, c_expr.expr);
c_expr.expr &:= ";\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "if (size_a > size_b) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "for (i = size_b; i < size_a; i++) {\n";
c_expr.expr &:= diagnosticLine;
process_destr_call(typeData.array_element[object_type],
"(*a)->arr[i]" & select_value, c_expr.expr);
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "*a=(";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= ")arrRealloc((arrayType)(*a), size_a, size_b);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
end if;
else
arraySize := succ(typeData.array_maxIdx[object_type] -
typeData.array_minIdx[object_type]);
if typeData.array_element[object_type] in typeData.typeCategory and
typeData.typeCategory[typeData.array_element[object_type]] in simpleValueType then
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "memmove((*a)->arr, b->arr, (uintType) ";
c_expr.expr &:= integerLiteral(arraySize);
c_expr.expr &:= " * sizeof(genericType));\n";
else
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "memSizeType index = (uintType) ";
c_expr.expr &:= integerLiteral(arraySize);
c_expr.expr &:= ";\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "while (index != 0) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "index--;\n";
c_expr.expr &:= diagnosticLine;
process_cpy_call(typeData.array_element[object_type],
"(*a)->arr[index]" & select_value,
"b->arr[index]" & select_value, c_expr.expr);
c_expr.expr &:= ";\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
end if;
end if;
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= noDiagnosticLine;
c_expr.expr &:= "\n";
typeData.cpy_declared @:= [object_type] TRUE;
end func;
const proc: process_sct_cpy_declaration (in type: object_type,
inout expr_type: c_expr) is func
local
var string: diagnosticLine is "";
var integer: structSize is 0;
var integer: elementIndex is 0;
var string: select_value is "";
begin
if object_type in typeData.copyFunction then
diagnosticLine := diagnosticLine(typeData.copyFunction[object_type]);
end if;
if object_type in typeData.struct_size then
structSize := typeData.struct_size[object_type];
end if;
for elementIndex range 0 to pred(structSize) do
process_cpy_declaration(typeData.struct_element_type[object_type][elementIndex], c_expr);
end for;
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "static void cpy_";
c_expr.expr &:= str(typeNumber(object_type));
c_expr.expr &:= " (";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= " a, ";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= " b)\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "{\n";
for elementIndex range 0 to pred(structSize) do
select_value := select_value_from_rtlObjectStruct(typeData.struct_element_type[object_type][elementIndex]);
c_expr.expr &:= diagnosticLine;
process_cpy_call(typeData.struct_element_type[object_type][elementIndex],
"a->stru[" & str(elementIndex) & "]" & select_value,
"b->stru[" & str(elementIndex) & "]" & select_value, c_expr.expr);
c_expr.expr &:= ";\n";
end for;
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= noDiagnosticLine;
c_expr.expr &:= "\n";
typeData.cpy_declared @:= [object_type] TRUE;
end func;
const proc: process_hsh_cpy_declaration (in type: object_type,
inout expr_type: c_expr) is func
local
var string: diagnosticLine is "";
begin
if object_type in typeData.copyFunction then
diagnosticLine := diagnosticLine(typeData.copyFunction[object_type]);
end if;
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "static void cpy_";
c_expr.expr &:= str(typeNumber(object_type));
c_expr.expr &:= " (";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= " *a, ";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= " b)\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "{\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "hshCpy(a, b";
c_expr.expr &:= typeData.parametersOfHshCpy[object_type];
c_expr.expr &:= ");\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= noDiagnosticLine;
c_expr.expr &:= "\n";
typeData.cpy_declared @:= [object_type] TRUE;
end func;
const proc: process_itf_cpy_declaration (in type: object_type,
inout expr_type: c_expr) is func
local
var string: diagnosticLine is "";
begin
if object_type in typeData.copyFunction then
diagnosticLine := diagnosticLine(typeData.copyFunction[object_type]);
end if;
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "static void cpy_";
c_expr.expr &:= str(typeNumber(object_type));
c_expr.expr &:= " (";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= " *a, ";
c_expr.expr &:= type_name(object_type);
c_expr.expr &:= " b)\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "{\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "interfaceType old_value = *a;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "*a=b;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "if ((*a)->usage_count != 0) { (*a)->usage_count++; }\n";
process_destr_declaration(object_type, global_c_expr);
c_expr.expr &:= diagnosticLine;
process_destr_call(object_type, "old_value", c_expr.expr);
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= noDiagnosticLine;
c_expr.expr &:= "\n";
typeData.cpy_declared @:= [object_type] TRUE;
end func;
const proc: process_cpy_declaration (in type: object_type,
inout expr_type: c_expr) is func
begin
if object_type not in typeData.cpy_declared then
if object_type in typeData.typeCategory then
case typeData.typeCategory[object_type] of
when {ARRAYOBJECT}:
process_arr_cpy_declaration(object_type, c_expr);
when {STRUCTOBJECT}:
process_sct_cpy_declaration(object_type, c_expr);
when {HASHOBJECT}:
process_hsh_cpy_declaration(object_type, c_expr);
when {INTERFACEOBJECT}:
process_itf_cpy_declaration(object_type, c_expr);
otherwise:
typeData.cpy_declared @:= [object_type] TRUE;
end case;
else
c_expr.expr &:= "/* cpy_";
c_expr.expr &:= str(typeNumber(object_type));
c_expr.expr &:= " declaration for type ";
c_expr.expr &:= type_name2(object_type);
c_expr.expr &:= " */\n\n";
end if;
end if;
end func;
const proc: process_cpy_call (in type: object_type,
in string: param_a, in string: param_b, inout string: expr) is func
begin
if object_type in typeData.typeCategory then
case typeData.typeCategory[object_type] of
when simpleValueType: expr &:= param_a & "=" & param_b;
when {BIGINTOBJECT}: expr &:= "bigCpy(&(" & param_a & "), " & param_b & ")";
when {STRIOBJECT}: expr &:= "strCopy(&(" & param_a & "), " & param_b & ")";
when {BSTRIOBJECT}: expr &:= "bstCpy(&(" & param_a & "), " & param_b & ")";
when {FILEOBJECT}: expr &:= "filCpy(&(" & param_a & "), " & param_b & ")";
when {SOCKETOBJECT}: expr &:= "socCpy(&(" & param_a & "), " & param_b & ")";
when {SETOBJECT}: expr &:= "setCpy(&(" & param_a & "), " & param_b & ")";
when {POLLOBJECT}: expr &:= "polCpy(" & param_a & ", " & param_b & ")";
when {REFLISTOBJECT}: expr &:= "rflCpy(&(" & param_a & "), " & param_b & ")";
when {WINOBJECT}: expr &:= "drwCpy(&(" & param_a & "), " & param_b & ")";
when {POINTLISTOBJECT}: expr &:= "bstCpy(&(" & param_a & "), " & param_b & ")";
when {PROCESSOBJECT}: expr &:= "pcsCpy(&(" & param_a & "), " & param_b & ")";
when {PROGOBJECT}: expr &:= "prgCpy(&(" & param_a & "), " & param_b & ")";
when {DATABASEOBJECT}: expr &:= "sqlCpyDb(&(" & param_a & "), " & param_b & ")";
when {SQLSTMTOBJECT}: expr &:= "sqlCpyStmt(&(" & param_a & "), " & param_b & ")";
when {ARRAYOBJECT, HASHOBJECT, INTERFACEOBJECT}:
expr &:= "cpy_";
expr &:= str(typeNumber(object_type));
expr &:= "((";
expr &:= type_name(object_type);
expr &:= " *)(&(";
expr &:= param_a;
expr &:= ")), (";
expr &:= type_name(object_type);
expr &:= ")(";
expr &:= param_b;
expr &:= "))";
when {STRUCTOBJECT}:
expr &:= "cpy_";
expr &:= str(typeNumber(object_type));
expr &:= "((";
expr &:= type_name(object_type);
expr &:= ")(";
expr &:= param_a;
expr &:= "), (";
expr &:= type_name(object_type);
expr &:= ")(";
expr &:= param_b;
expr &:= "))";
end case;
else
expr &:= param_b & " /* cpy_";
expr &:= str(typeNumber(object_type));
expr &:= " for type ";
expr &:= type_name2(object_type);
expr &:= " */";
end if;
end func;
const proc: process_arr_poscpy_declaration (in type: elementType,
inout expr_type: c_expr) is func
local
var string: diagnosticLine is "";
begin
if elementType in typeData.typeCategory and
typeData.typeCategory[elementType] not in simpleValueType then
if elementType not in typeData.posCpyFunction then
typeData.posCpyFunction @:= [elementType] TRUE;
process_cpy_declaration(elementType, c_expr);
process_destr_declaration(elementType, c_expr);
if elementType in typeData.posCpyDiagnosticLine then
diagnosticLine := typeData.posCpyDiagnosticLine[elementType];
else
diagnosticLine := noDiagnosticLine;
end if;
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "static void poscpy_";
c_expr.expr &:= str(typeNumber(elementType));
c_expr.expr &:= " (arrayType a, intType position, arrayType b)\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "{\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " memSizeType i;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " memSizeType j;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " memSizeType size_b = (uintType)(b->max_position - b->min_position + 1);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " if (size_b == 0) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " if (idxChk(position < a->min_position ||\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " (a->max_position != MAX_MEM_INDEX &&\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " position > a->max_position + 1))) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " raiseError(INDEX_ERROR);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " }\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " } else if (idxChk(position < a->min_position ||\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " position > a->max_position ||\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " size_b - 1 > (uintType) (a->max_position - position))) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " raiseError(INDEX_ERROR);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " } else {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " j = position - a->min_position;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " if (&a->arr[j] < b->arr) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " for (i = 0; i < size_b; i++, j++) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " ";
process_cpy_call(elementType,
"a->arr[j]" & select_value_from_rtlObjectStruct(elementType),
"b->arr[i]" & select_value_from_rtlObjectStruct(elementType),
c_expr.expr);
c_expr.expr &:= ";\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " }\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " } else if (&a->arr[j] > b->arr) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " j += size_b;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " while (size_b > 0) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " j--;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " size_b--;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " ";
process_cpy_call(elementType,
"a->arr[j]" & select_value_from_rtlObjectStruct(elementType),
"b->arr[size_b]" & select_value_from_rtlObjectStruct(elementType),
c_expr.expr);
c_expr.expr &:= ";\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " }\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " }\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " }\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= noDiagnosticLine;
c_expr.expr &:= "\n";
end if;
end if;
end func;
const proc: process_arr_poscpy_temp_declaration (in type: elementType,
inout expr_type: c_expr) is func
local
var string: diagnosticLine is "";
begin
if elementType in typeData.typeCategory and
typeData.typeCategory[elementType] not in simpleValueType then
if elementType not in typeData.posCpyTempFunction then
typeData.posCpyTempFunction @:= [elementType] TRUE;
process_cpy_declaration(elementType, c_expr);
process_destr_declaration(elementType, c_expr);
if elementType in typeData.posCpyDiagnosticLine then
diagnosticLine := typeData.posCpyDiagnosticLine[elementType];
else
diagnosticLine := noDiagnosticLine;
end if;
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "static void poscpy_temp_";
c_expr.expr &:= str(typeNumber(elementType));
c_expr.expr &:= " (arrayType a, intType position, arrayType b)\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "{\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " memSizeType i;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " memSizeType max;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " memSizeType size_b = (uintType)(b->max_position - b->min_position + 1);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " if (size_b == 0) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " if (idxChk(position < a->min_position ||\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " (a->max_position != MAX_MEM_INDEX &&\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " position > a->max_position + 1))) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " raiseError(INDEX_ERROR);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " }\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " } else if (idxChk(position < a->min_position ||\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " position > a->max_position ||\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " size_b - 1 > (uintType) (a->max_position - position))) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " raiseError(INDEX_ERROR);\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " } else {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " max = position - a->min_position + size_b;\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " for (i = position - a->min_position; i < max; i++) {\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " ";
process_destr_call(elementType,
"a->arr[i]" & select_value_from_rtlObjectStruct(elementType),
c_expr.expr);
c_expr.expr &:= ";\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " }\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " memcpy(&a->arr[position - a->min_position], b->arr, size_b * sizeof(rtlObjectType));\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " arrFree((arrayType)(b));\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= " }\n";
c_expr.expr &:= diagnosticLine;
c_expr.expr &:= "}\n";
c_expr.expr &:= noDiagnosticLine;
c_expr.expr &:= "\n";
end if;
end if;
end func;