[Datadraw-user] 42 makes me improve datadraw
Brought to you by:
smilindog2000
|
From: Richard P. <rdp...@gm...> - 2009-01-17 22:52:30
|
Index: src/dvgenc.c
===================================================================
--- src/dvgenc.c (revision 542)
+++ src/dvgenc.c (working copy)
@@ -17,62 +18,53 @@
dvKey key,
bool useParamName)
{
- dvProperty property = dvKeyGetProperty(key);
+ dvProperty property = dvKeypropertyGetProperty(dvKeyGetLastKeyproperty(key));
dvClass childClass = dvPropertyGetClass(property);
dvClass pointerClass;
dvPropertyType type = dvPropertyGetType(property);
- char *accessMacro, *lengthMacro;
+ char *param = utSprintf("_%s",
+ dvClassGetName(dvPropertyGetClass(dvKeypropertyGetProperty(dvKeyGetFirstKeyproperty(key)))));
- if(useParamName) {
- accessMacro = dvPropertyGetName(property);
- if(!dvPropertyFixedSize(property)) {
- lengthMacro = utSprintf("%sLength", accessMacro);
- } else {
- lengthMacro = utSprintf("(%s)", dvPropertyGetIndex(property));
- }
- } else {
- if(!dvPropertyArray(property) && (type == PROP_BOOL || type == PROP_BIT)) {
- accessMacro = utSprintf("%s%s%s(_%s)", dvPrefix, dvClassGetName(childClass),
- dvPropertyGetName(property), dvClassGetName(childClass));
- } else {
- accessMacro = utSprintf("%s%sGet%s(_%s)", dvPrefix, dvClassGetName(childClass),
- dvPropertyGetName(property), dvClassGetName(childClass));
- }
- if(!dvPropertyFixedSize(property)) {
- lengthMacro = utSprintf("%s%sGetNum%s(_%s)", dvPrefix, dvClassGetName(childClass),
- dvPropertyGetName(property), dvClassGetName(childClass));
- } else {
- lengthMacro = utSprintf("(%s)", dvPropertyGetIndex(property));
- }
- }
if(dvPropertyArray(property)) {
- dvWrtemp(dvFile, "utHashData(%0, sizeof(%1)*%2)", accessMacro, dvPropertyGetTypeName(property), lengthMacro);
+ dvWrtemp(dvFile, "utHashData(%0, sizeof(%1)*%2)",
+ dvKeyGetAccessMacro(key, useParamName, param),
+ dvPropertyGetTypeName(property),
+ dvKeyGetLengthMacro(key, useParamName, param));
return;
}
switch(type) {
case PROP_UINT: case PROP_INT: case PROP_CHAR: case PROP_ENUM: case PROP_BOOL: case PROP_BIT:
- dvWrtemp(dvFile, "(uint32)%0", accessMacro);
+ dvWrtemp(dvFile, "(uint32)%0", dvKeyGetAccessMacro(key, useParamName, param));
break;
case PROP_FLOAT:
- dvWrtemp(dvFile, "utHashFloat(%0)", accessMacro);
+ dvWrtemp(dvFile, "utHashFloat(%0)", dvKeyGetAccessMacro(key, useParamName, param));
break;
case PROP_DOUBLE:
- dvWrtemp(dvFile, "utHashDouble(%0)", accessMacro);
+ dvWrtemp(dvFile, "utHashDouble(%0)", dvKeyGetAccessMacro(key, useParamName, param));
break;
case PROP_SYM:
- dvWrtemp(dvFile, "utSymGetHashValue(%0)", accessMacro);
+ dvWrtemp(dvFile, "utSymGetHashValue(%0)", dvKeyGetAccessMacro(key, useParamName, param));
break;
case PROP_TYPEDEF:
if(useParamName) {
- dvWrtemp(dvFile, "utHashData(&%0, sizeof(%1))", accessMacro, dvPropertyGetTypeName(property));
+ dvWrtemp(dvFile, "utHashData(&%0, sizeof(%1))",
+ dvKeyGetAccessMacro(key, useParamName, param),
+ dvPropertyGetTypeName(property));
} else {
- dvWrtemp(dvFile, "utHashData(%0%1s.%2 + %4%12Index(_%1), sizeof(%3))", dvPrefix, dvClassGetName(childClass),
- dvPropertyGetName(property), dvPropertyGetTypeName(property), dvClassGetPrefix(childClass));
+ dvWrtemp(dvFile, "utHashData(%0%1s.%2 + %4%12Index(_%1), sizeof(%3))",
+ dvPrefix,
+ dvClassGetName(childClass),
+ dvPropertyGetName(property),
+ dvPropertyGetTypeName(property),
+ dvClassGetPrefix(childClass));
}
break;
case PROP_POINTER:
pointerClass = dvPropertyGetClassProp(property);
- dvWrtemp(dvFile, "%1%22Index(%0)", accessMacro, dvClassGetPrefix(pointerClass), dvClassGetName(pointerClass));
+ dvWrtemp(dvFile, "%1%22Index(%0)",
+ dvKeyGetAccessMacro(key, useParamName, param),
+ dvClassGetPrefix(pointerClass),
+ dvClassGetName(pointerClass));
break;
default:
utExit("Unexpected key type");
@@ -252,7 +244,7 @@
dvKey key;
dvForeachRelationshipKey(relationship, key) {
- property = dvKeyGetProperty(key);
+ property = dvKeypropertyGetProperty(dvKeyGetLastKeyproperty(key));
if(!dvPropertyArray(property)) {
dvWrtemp(dvFile, ",\n %0 %1", dvPropertyGetTypeName(property), dvPropertyGetName(property));
} else if(!dvPropertyFixedSize(property)) {
@@ -271,29 +263,33 @@
dvRelationship relationship)
{
dvClass childClass = dvRelationshipGetChildClass(relationship);
+ dvKeyproperty keyproperty;
dvProperty property;
- dvPropertyType type;
dvKey key;
bool isFirst = true;
- char *getString;
dvForeachRelationshipKey(relationship, key) {
if(!isFirst) {
dvWrtemp(dvFile, " && ");
}
isFirst = false;
- property = dvKeyGetProperty(key);
- type = dvPropertyGetType(property);
+ keyproperty = dvKeyGetLastKeyproperty(key);
+ property = dvKeypropertyGetProperty(keyproperty);
if(!dvPropertyArray(property)) {
- getString = type == PROP_BIT || type == PROP_BOOL? "" : "Get";
- dvWrtemp(dvFile, "%0%1%3%2(_%1) == %2",
- dvPrefix, dvClassGetName(childClass), dvPropertyGetName(property), getString);
+ dvWrtemp(dvFile, "%0 == %1",
+ dvKeyGetAccessMacro(key,false,utSprintf("_%s", dvClassGetName(childClass))),
+ dvPropertyGetName(property));
} else if(!dvPropertyFixedSize(property)) {
- dvWrtemp(dvFile, "%0%1GetNum%2(_%1) == %2Length && !memcmp(%0%1Get%2(_%1), %2, sizeof(%3)*%2Length)",
- dvPrefix, dvClassGetName(childClass), dvPropertyGetName(property), dvPropertyGetTypeName(property));
+ dvWrtemp(dvFile, "%0 == %2Length && !memcmp(%1, %2, sizeof(%3)*%2Length)",
+ dvKeyGetLengthMacro(key, false, utSprintf("_%s", dvClassGetName(childClass))),
+ dvKeyGetAccessMacro(key, false, utSprintf("_%s", dvClassGetName(childClass))),
+ dvPropertyGetName(property),
+ dvPropertyGetTypeName(property));
} else {
- dvWrtemp(dvFile, "!memcmp(%0%1Get%2(_%1), %2, sizeof(%3)*(%4))",
- dvPrefix, dvClassGetName(childClass), dvPropertyGetName(property), dvPropertyGetTypeName(property),
+ dvWrtemp(dvFile, "!memcmp(%0, %1, sizeof(%2)*(%3))",
+ dvKeyGetAccessMacro(key, false, utSprintf("_%s", dvClassGetName(childClass))),
+ dvPropertyGetName(property),
+ dvPropertyGetTypeName(property),
dvPropertyGetIndex(property));
}
} dvEndRelationshipKey;
@@ -929,6 +925,12 @@
char *propName = dvPropertyGetName(prop);
char *fieldName;
+ if(dvPropertyView(prop)) {
+ dvWrtemp(dvFile, "%1 /* property initialisation for %0 is user provided */\n",
+ propName, indent);
+ return;
+ }
+
if(strcmp(initValue, "0") || cache != dvCacheNull) {
if(theUnion != dvUnionNull) {
fieldName = utSprintf("%s[x%s].%s", dvUnionGetFieldName(theUnion), name, propName);
@@ -968,7 +970,11 @@
dvForeachClassProperty(theClass, prop) {
if(dvPropertyGetUnion(prop) == dvUnionNull && dvPropertyGetCache(prop) == dvCacheNull &&
!dvPropertySparse(prop)) {
- if(!dvPropertyArray(prop)) {
+ if(dvPropertyView(prop)) {
+ dvWrtemp(dvFile, " /* allocation for %0 is user provided */\n",
+ dvPropertyGetName(prop));
+ }
+ else if(!dvPropertyArray(prop)) {
dvWrtemp(dvFile,
" %0%1s.%2 = utNewA(%4, (%3Allocated%1()%5);\n",
dvPrefix, name, dvPropertyGetName(prop), dvClassGetPrefix(theClass),
@@ -1033,7 +1039,11 @@
char *shift, *multiplier;
dvForeachClassProperty(theClass, prop) {
- if((!dvPropertyArray(prop) || dvPropertyFixedSize(prop)) && dvPropertyGetUnion(prop) == dvUnionNull &&
+ if(dvPropertyView(prop)) {
+ dvWrtemp(dvFile, " /* reallocation for %0 is user provided */\n",
+ dvPropertyGetName(prop));
+ }
+ else if((!dvPropertyArray(prop) || dvPropertyFixedSize(prop)) && dvPropertyGetUnion(prop) == dvUnionNull &&
dvPropertyGetCache(prop) == dvCacheNull && !dvPropertySparse(prop)) {
shift = dvPropertyGetType(prop) == PROP_BIT? " + 7) >> 3" : ")";
multiplier = dvPropertyFixedSize(prop)? utSprintf("*(%s)", dvPropertyGetIndex(prop)) : "";
@@ -1094,7 +1104,11 @@
char *name = dvClassGetName(theClass);
dvForeachClassProperty(theClass, prop) {
- if(dvPropertyGetUnion(prop) == dvUnionNull && dvPropertyGetCache(prop) == dvCacheNull &&
+ if(dvPropertyView(prop)) {
+ dvWrtemp(dvFile, " /* free for %0 is user provided */\n",
+ dvPropertyGetName(prop));
+ }
+ else if(dvPropertyGetUnion(prop) == dvUnionNull && dvPropertyGetCache(prop) == dvCacheNull &&
!dvPropertySparse(prop)) {
dvWrtemp(dvFile,
" utFree(%0%1s.%2);\n",
@@ -1273,7 +1287,13 @@
dvModuleGetPrefix(dvClassGetModule(baseClass)), utSprintf("%u", dvClassGetNumber(baseClass)));
}
dvForeachClassProperty(theClass, property) {
- if(dvPropertyGetUnion(property) == dvUnionNull && dvPropertyGetCache(property) == dvCacheNull &&
+ if(dvPropertyView(property)) {
+ dvWrtemp(dvFile,
+ " /* %0.%1 not managed by this database */\n",
+ dvClassGetName(theClass),
+ dvPropertyGetName(property));
+ }
+ else if(dvPropertyGetUnion(property) == dvUnionNull && dvPropertyGetCache(property) == dvCacheNull &&
!dvPropertySparse(property)) {
dvWrtemp(dvFile,
" utRegisterField(\"%2\", &%0%1s.%2, sizeof(%3), %4,",
@@ -1439,6 +1459,12 @@
{
dvClass theClass = dvPropertyGetClass(property);
+ if(dvPropertyView(property)) {
+ dvWrtemp(dvFile, "/* compact function for %0 is user provided */\n",
+ dvPropertyGetName(property));
+ return;
+ }
+
dvWrtemp(dvFile,
"/*----------------------------------------------------------------------------------------\n"
" Compact the %1.%2 heap to free memory.\n"
@@ -1497,6 +1523,12 @@
{
dvClass theClass = dvPropertyGetClass(property);
+ if(dvPropertyView(property)) {
+ dvWrtemp(dvFile, "/* compact and/or allocate more space function for %0 is user provided */\n",
+ dvPropertyGetName(property));
+ return;
+ }
+
dvWrtemp(dvFile,
"/*----------------------------------------------------------------------------------------\n"
" Allocate more memory for the %1.%2 heap.\n"
@@ -1545,6 +1577,12 @@
{
dvClass theClass = dvPropertyGetClass(property);
+ if(dvPropertyView(property)) {
+ dvWrtemp(dvFile, "/* allocate more space function for %0 is user provided */\n",
+ dvPropertyGetName(property));
+ return;
+ }
+
dvWrtemp(dvFile,
"/*----------------------------------------------------------------------------------------\n"
" Allocate memory for a new %1.%2 array.\n"
@@ -1663,6 +1701,12 @@
{
dvClass theClass = dvPropertyGetClass(property);
+ if(dvPropertyView(property)) {
+ dvWrtemp(dvFile, "/* free space function for %0 is user provided */\n",
+ dvPropertyGetName(property));
+ return;
+ }
+
dvWrtemp(dvFile,
"/*----------------------------------------------------------------------------------------\n"
" Free memory used by the %1.%2 array.\n"
@@ -1712,6 +1756,12 @@
{
dvClass theClass = dvPropertyGetClass(property);
+ if(dvPropertyView(property)) {
+ dvWrtemp(dvFile, "/* reallocate space function for %0 is user provided */\n",
+ dvPropertyGetName(property));
+ return;
+ }
+
dvWrtemp(dvFile,
"/*----------------------------------------------------------------------------------------\n"
" Resize the %1.%2 array.\n"
@@ -1998,31 +2048,33 @@
static void writeOrderedListComparisons(
dvRelationship relationship)
{
- dvClass child = dvRelationshipGetChildClass(relationship);
dvProperty property;
dvKey key;
- dvPropertyType type;
- char *getString, *compareString;
bool firstTime = true;
+ char *compareString;
dvForeachRelationshipKey(relationship, key) {
- property = dvKeyGetProperty(key);
+ property = dvKeypropertyGetProperty(dvKeyGetLastKeyproperty(key));
if(!dvPropertyArray(property)) {
- type = dvPropertyGetType(property);
- getString = type == PROP_BIT || type == PROP_BOOL? "" : "Get";
- compareString = dvSwrtemp("%2 - %0%1%3%2(node)",
- dvPropertyGetPrefix(property), dvClassGetName(child), dvPropertyGetName(property), getString);
+ compareString = dvSwrtemp("%0 - %1",
+ dvPropertyGetName(property),
+ dvKeyGetAccessMacro(key, false, "node"));
writeOrderedListComparison(compareString, firstTime);
} else if(!dvPropertyFixedSize(property)) {
- compareString = dvSwrtemp("%2Length - %0%1GetNum%2(node)",
- dvPropertyGetPrefix(property), dvClassGetName(child), dvPropertyGetName(property), dvPropertyGetTypeName(property));
+ compareString = dvSwrtemp("%0Length - %1",
+ dvPropertyGetName(property),
+ dvKeyGetLengthMacro(key, false, "node"));
writeOrderedListComparison(compareString, firstTime);
- compareString = dvSwrtemp("memcmp(%0%1Get%2(node), %2, sizeof(%3)*%2Length)",
- dvPropertyGetPrefix(property), dvClassGetName(child), dvPropertyGetName(property), dvPropertyGetTypeName(property));
+ compareString = dvSwrtemp("memcmp(%0, %1, sizeof(%2)*%1Length)",
+ dvKeyGetAccessMacro(key, false, "node"),
+ dvPropertyGetName(property),
+ dvPropertyGetTypeName(property));
writeOrderedListComparison(compareString, false);
} else {
- compareString = dvSwrtemp("memcmp(%0%1Get%2(node), %2, sizeof(%3)*(%4))",
- dvPropertyGetPrefix(property), dvClassGetName(child), dvPropertyGetName(property), dvPropertyGetTypeName(property),
+ compareString = dvSwrtemp("memcmp(%0, %1, sizeof(%2)*(%3))",
+ dvKeyGetAccessMacro(key, false, "node"),
+ dvPropertyGetName(property),
+ dvPropertyGetTypeName(property),
dvPropertyGetIndex(property));
writeOrderedListComparison(compareString, firstTime);
}
@@ -3072,7 +3124,11 @@
dvForeachClassProperty(theClass, prop) {
name = dvClassGetName(theClass);
propName = dvPropertyGetName(prop);
- if(propIsClassProp(prop)) {
+ if(dvPropertyView(prop)) {
+ dvWrtemp(dvFile, " /* copy for %0 is irrelevant */\n",
+ dvPropertyGetName(prop));
+ }
+ else if(propIsClassProp(prop)) {
theUnion = dvPropertyGetUnion(prop);
propType = dvPropertyGetType(prop);
if(theUnion == dvUnionNull && propType != PROP_POINTER) {
@@ -3095,7 +3151,7 @@
{
dvProperty prop;
dvForeachClassProperty(theClass, prop) {
- if(dvPropertyGetType(prop) == PROP_BIT) {
+ if(dvPropertyGetType(prop) == PROP_BIT && !dvPropertyView(prop)) {
return true;
}
} dvEndClassProperty;
@@ -3131,7 +3187,7 @@
" uint32 bitfield = 0;\n"
" uint8 xLevel = 0;\n\n", dvPrefix, name, prefix);
dvForeachClassProperty(theClass, prop) {
- if(propIsClassProp(prop) && dvPropertyGetType(prop) == PROP_BIT) {
+ if(propIsClassProp(prop) && dvPropertyGetType(prop) == PROP_BIT && !dvPropertyView(prop)) {
name = dvClassGetName(theClass);
propName = dvPropertyGetName(prop);
theUnion = dvPropertyGetUnion(prop);
@@ -3150,7 +3206,7 @@
" uint32 bitfield)\n"
"{\n", dvPrefix, name, prefix);
dvForeachClassProperty(theClass, prop) {
- if(propIsClassProp(prop) && dvPropertyGetType(prop) == PROP_BIT) {
+ if(propIsClassProp(prop) && dvPropertyGetType(prop) == PROP_BIT && !dvPropertyView(prop)) {
name = dvClassGetName(theClass);
propName = dvPropertyGetName(prop);
theUnion = dvPropertyGetUnion(prop);
@@ -3446,7 +3502,11 @@
dvClass theClass = dvPropertyGetClass(property);
dvPropertyType type = dvPropertyGetType(property);
dvSparsegroup sparsegroup = dvPropertyGetSparsegroup(property);
-
+ if(dvPropertyView(property)) {
+ dvWrtemp(dvFile, "/* Getting and setting %0.%1 field is user provided */\n",
+ dvClassGetName(theClass), dvPropertyGetName(property));
+ return;
+ }
dvWrtemp(dvFile,
"/*----------------------------------------------------------------------------------------\n"
" Get the %1.%2 field.\n"
Index: src/dvutil.c
===================================================================
--- src/dvutil.c (revision 542)
+++ src/dvutil.c (working copy)
@@ -545,11 +545,15 @@
{
dvProperty property;
dvKey key = dvRelationshipGetFirstKey(relationship);
+ dvKeyproperty keyproperty = dvKeyGetFirstKeyproperty(key);
if(dvKeyGetNextRelationshipKey(key) != dvKeyNull) {
return false;
}
- property = dvKeyGetProperty(key);
+ if(dvKeypropertyGetNextKeyKeyproperty(keyproperty) != dvKeypropertyNull) {
+ return false;
+ }
+ property = dvKeypropertyGetProperty(key);
if(strcmp(dvPropertyGetName(property), utSprintf("%sSym", dvRelationshipGetChildLabel(relationship)))) {
return false;
}
@@ -600,3 +604,105 @@
} while(theClass != dvClassNull);
return dvPropertyNull;
}
+
+/*--------------------------------------------------------------------------------------------------
+ Format a access function for just this property.
+--------------------------------------------------------------------------------------------------*/
+char *dvPropertyGetAccessMacro(
+ dvProperty property,
+ bool useParamName,
+ char * param)
+{
+ dvClass childClass = dvPropertyGetClass(property);
+ dvPropertyType type = dvPropertyGetType(property);
+ char *accessMacro;
+ if(useParamName) {
+ accessMacro = dvPropertyGetName(property);
+ } else {
+ if(!dvPropertyArray(property) && (type == PROP_BOOL || type == PROP_BIT)) {
+ accessMacro = utSprintf("%s%s%s(%s)", dvPropertyGetPrefix(property), dvClassGetName(childClass),
+ dvPropertyGetName(property), param);
+ } else {
+ accessMacro = utSprintf("%s%sGet%s(%s)", dvPropertyGetPrefix(property), dvClassGetName(childClass),
+ dvPropertyGetName(property), param);
+ }
+ }
+ return accessMacro;
+}
+
+
+/*--------------------------------------------------------------------------------------------------
+ Format a length function for just this property.
+--------------------------------------------------------------------------------------------------*/
+char *dvPropertyGetLengthMacro(
+ dvProperty property,
+ bool useParamName,
+ char * param)
+{
+ dvClass childClass = dvPropertyGetClass(property);
+ char *lengthMacro;
+ if(useParamName) {
+ if(!dvPropertyFixedSize(property)) {
+ lengthMacro = utSprintf("%sLength", dvPropertyGetName(property));
+ } else {
+ lengthMacro = utSprintf("(%s)", dvPropertyGetIndex(property));
+ }
+ } else {
+ if(!dvPropertyFixedSize(property)) {
+ lengthMacro = utSprintf("%s%sGetNum%s(%s)", dvPropertyGetPrefix(property), dvClassGetName(childClass),
+ dvPropertyGetName(property), param);
+ } else {
+ lengthMacro = utSprintf("(%s)", dvPropertyGetIndex(property));
+ }
+ }
+ return lengthMacro;
+}
+
+/*--------------------------------------------------------------------------------------------------
+ Format a access function for just this key.
+--------------------------------------------------------------------------------------------------*/
+char *dvKeyGetAccessMacro(
+ dvKey key,
+ bool useParamName,
+ char * param)
+{
+ dvKeyproperty keyproperty = dvKeyGetLastKeyproperty(key);
+ dvProperty property = dvKeypropertyGetProperty(keyproperty);
+
+ char *accessMacro = param;
+
+ dvForeachKeyKeyproperty(key, keyproperty) {
+ property = dvKeypropertyGetProperty(keyproperty);
+ accessMacro = dvPropertyGetAccessMacro(property, useParamName, accessMacro);
+ } dvEndKeyKeyproperty;
+
+ return accessMacro;
+}
+
+/*--------------------------------------------------------------------------------------------------
+ Format a length function for just this key.
+--------------------------------------------------------------------------------------------------*/
+char *dvKeyGetLengthMacro(
+ dvKey key,
+ bool useParamName,
+ char *param)
+{
+ dvKeyproperty keyproperty = dvKeyGetLastKeyproperty(key);
+ dvProperty property = dvKeypropertyGetProperty(keyproperty);
+
+ char *lengthMacro = param;
+
+ dvForeachKeyKeyproperty(key, keyproperty) {
+ property = dvKeypropertyGetProperty(keyproperty);
+ if(dvKeypropertyGetNextKeyKeyproperty(keyproperty) != dvKeypropertyNull) {
+ lengthMacro = dvPropertyGetAccessMacro(property, useParamName, lengthMacro);
+ }
+ else {
+ lengthMacro = dvPropertyGetLengthMacro(property, useParamName, lengthMacro);
+ }
+ } dvEndKeyKeyproperty;
+
+ return lengthMacro;
+}
+
+
Index: src/Database.dd
===================================================================
--- src/Database.dd (revision 542)
+++ src/Database.dd (working copy)
@@ -75,6 +75,7 @@
bit Array
bit Cascade
bit Sparse
+ bit View
bit expanded // So that we only generate relationship fields once
uint32 fieldNumber // Used in persistent databases
Property firstElementProp // Used only for arrays
@@ -107,9 +108,11 @@
bit Unordered
class Key
- sym PropertySym // For unbound keys
uint32 lineNum // For reporting errors during binding
+class Keyproperty
+ sym PropertySym // For unbound keys
+
class Union
sym propertySym
Property typeProperty
@@ -160,7 +163,8 @@
relationship Entry Case tail_linked mandatory
relationship Property Case tail_linked mandatory
relationship Relationship Key tail_linked mandatory
-relationship Property Key tail_linked mandatory
+relationship Key Keyproperty tail_linked mandatory
+relationship Property Keyproperty tail_linked mandatory
relationship Relationship Sparsegroup:Parent
relationship Relationship Sparsegroup:Child
Index: src/dvgenh.c
===================================================================
--- src/dvgenh.c (revision 542)
+++ src/dvgenh.c (working copy)
@@ -78,7 +78,7 @@
dvProperty prop;
dvForeachClassProperty(theClass, prop) {
- if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop)) {
+ if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop) && !dvPropertyView(prop)) {
dvWrtemp(dvFile,
" uint32 used%0%1, allocated%0%1, free%0%1;\n",
name, dvPropertyGetName(prop));
@@ -169,7 +169,7 @@
char *preString, *postString;
dvForeachClassProperty(theClass, prop) {
- if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop)) {
+ if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop) && !dvPropertyView(prop)) {
dvWrtemp(dvFile,
"static utInlineC uint32 %0Used%1%2(void) {return %0RootData.used%1%2;}\n"
"static utInlineC uint32 %0Allocated%1%2(void) {return %0RootData.allocated%1%2;}\n"
@@ -312,8 +312,10 @@
dvProperty prop;
dvForeachClassProperty(theClass, prop) {
- if(!dvPropertySparse(prop) && dvPropertyGetUnion(prop) == dvUnionNull &&
- dvPropertyGetCache(prop) == dvCacheNull) {
+ if(!dvPropertySparse(prop) &&
+ dvPropertyGetUnion(prop) == dvUnionNull &&
+ dvPropertyGetCache(prop) == dvCacheNull &&
+ !dvPropertyView(prop)) {
dvWrtemp(dvFile, " %0 *%1;\n", dvPropertyGetTypeName(prop), dvPropertyGetName(prop));
}
} dvEndClassProperty;
@@ -409,7 +411,7 @@
dvProperty prop;
dvForeachClassProperty(theClass, prop) {
- if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop)) {
+ if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop) &&!dvPropertyView(prop)) {
dvWrtemp(dvFile,
"void %0%1Alloc%2s(%3%1 %1, uint32 num%2s);\n"
"void %0%1Resize%2s(%3%1 %1, uint32 num%2s);\n"
@@ -443,9 +445,8 @@
dvClass parent = dvRelationshipGetParentClass(relationship);
dvClass child = dvRelationshipGetChildClass(relationship);
dvKey key = dvRelationshipGetFirstKey(relationship);
- dvProperty property = dvKeyGetProperty(key);
- dvPropertyType type;
- char *getString, *compareString;
+ dvProperty property = dvKeypropertyGetProperty(dvKeyGetLastKeyproperty(key));
+ char *compareString;
uint32 numKeys = 0;
dvWrtemp(dvFile,
@@ -453,25 +454,29 @@
dvPrefix, dvClassGetName(parent), dvRelationshipGetChildLabel(relationship),
dvClassGetName(child), dvClassGetPrefix(parent), dvClassGetPrefix(child),
dvRelationshipGetParentLabel(relationship));
+
dvForeachRelationshipKey(relationship, key) {
numKeys++;
- property = dvKeyGetProperty(key);
+ property = dvKeypropertyGetProperty(dvKeyGetLastKeyproperty(key));
if(!dvPropertyArray(property)) {
- type = dvPropertyGetType(property);
- getString = type == PROP_BIT || type == PROP_BOOL? "" : "Get";
- compareString = dvSwrtemp("%0%1%3%2(right) - %0%1%3%2(left)",
- dvPropertyGetPrefix(property), dvClassGetName(child), dvPropertyGetName(property), getString);
+ compareString = dvSwrtemp("%0 - %1",
+ dvKeyGetAccessMacro(key, false, "right"), dvKeyGetAccessMacro(key, false, "left"));
writeComparison(compareString, dvKeyGetNextRelationshipKey(key) == dvKeyNull);
} else if(!dvPropertyFixedSize(property)) {
- compareString = dvSwrtemp("%0%1GetNum%2(right) - %0%1GetNum%2(left)",
- dvPropertyGetPrefix(property), dvClassGetName(child), dvPropertyGetName(property), dvPropertyGetTypeName(property));
+ compareString = dvSwrtemp("%0 - %1",
+ dvKeyGetLengthMacro(key, false, "right"), dvKeyGetLengthMacro(key, false, "left"));
writeComparison(compareString, false);
- compareString = dvSwrtemp("memcmp(%0%1Get%2(left), %0%1Get%2(right), sizeof(%3)*%0%1GetNum%2(left))",
- dvPropertyGetPrefix(property), dvClassGetName(child), dvPropertyGetName(property), dvPropertyGetTypeName(property));
+ compareString = dvSwrtemp("memcmp(%0, %1, sizeof(%2)*%3)",
+ dvKeyGetAccessMacro(key, false, "left"),
+ dvKeyGetAccessMacro(key, false, "right"),
+ dvPropertyGetTypeName(property),
+ dvKeyGetLengthMacro(key, false, "left"));
writeComparison(compareString, dvKeyGetNextRelationshipKey(key) == dvKeyNull);
} else {
- compareString = dvSwrtemp("memcmp(%0%1Get%2(left), %0%1Get%2(right), sizeof(%3)*(%4))",
- dvPropertyGetPrefix(property), dvClassGetName(child), dvPropertyGetName(property), dvPropertyGetTypeName(property),
+ compareString = dvSwrtemp("memcmp(%0, %1, sizeof(%2)*(%3))",
+ dvKeyGetAccessMacro(key, false, "left"),
+ dvKeyGetAccessMacro(key, false, "right"),
+ dvPropertyGetTypeName(property),
dvPropertyGetIndex(property));
writeComparison(compareString, dvKeyGetNextRelationshipKey(key) == dvKeyNull);
}
@@ -622,8 +627,34 @@
} else {
accessString = "Get";
}
- if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop)) {
+ if(dvPropertyView(prop) && dvPropertyArray(prop) && !dvPropertyFixedSize(prop)) {
+ /* view on variable size array */
dvWrtemp(dvFile,
+ "#ifndef %0%1Geti%2\n"
+ "extern %5 %0%1Geti%2(%4%1 %1, uint32 x);\n"
+ "#endif\n"
+ "#ifndef %0%1Get%2\n"
+ "extern %5 *%0%1Get%2(%4%1 %1);\n"
+ "#endif\n"
+ "#ifndef %0%1Get%2s\n"
+ "#define %0%1Get%2s %0%1Get%2\n"
+ "#endif\n",
+ dvPrefix, name, propName, dvClassGetReferenceTypeName(theClass),
+ dvClassGetPrefix(theClass), propTypeString);
+ dvWrtemp(dvFile,
+ "#ifndef %0%1Set%2\n"
+ "extern void %0%1Set%2(%6%1 %1, %3 *valuePtr, uint32 num%2);\n"
+ "#endif\n",
+ dvPrefix, name, propName, propTypeString, preString, postString, dvClassGetPrefix(theClass));
+ dvWrtemp(dvFile,
+ "#ifndef %0%1Seti%2\n"
+ "extern void %0%1Seti%2(%5%1 %1, uint32 x, %6 value);\n"
+ "#endif\n",
+ dvPrefix, name, propName, preString, postString, dvClassGetPrefix(theClass), propTypeString);
+ }
+ else if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop)) {
+ /* variable size array */
+ dvWrtemp(dvFile,
"#if defined(DD_DEBUG)\n"
"static utInlineC uint32 %0%1Check%2Index(%4%1 %1, uint32 x) {utAssert(x < %0%1GetNum%2(%1)); return x;}\n"
"#else\n"
@@ -656,6 +687,31 @@
"static utInlineC void %0%1Seti%2(%5%1 %1, uint32 x, %6 value) {\n"
"%3 %0%1s.%2[%0%1Get%2Index(%1) + %0%1Check%2Index(%1, (x))] = value;%4}\n",
dvPrefix, name, propName, preString, postString, dvClassGetPrefix(theClass), propTypeString);
+ } else if(dvPropertyArray(prop) && dvPropertyView(prop)) {
+ /* view on fixed sized arrays */
+ dvWrtemp(dvFile,
+ "#ifndef %0%1Geti%2\n"
+ "extern %6 %0%1Geti%2(%5%1 %1, uint32 x);\n"
+ "#endif\n"
+ "#ifndef %0%1Get%2\n"
+ "extern %6 *%0%1Get%2(%5%1 %1);\n"
+ "#endif\n"
+ "#ifndef %0%1Get%2s\n"
+ "#define %0%1Get%2s %0%1Get%2\n"
+ "#endif\n",
+ dvPrefix, name, propName, dvClassGetReferenceTypeName(theClass), dvPropertyGetIndex(prop),
+ dvClassGetPrefix(theClass), propTypeString);
+ dvWrtemp(dvFile,
+ "#ifndef %0%1Set%2\n"
+ "extern void %0%1Set%2(%6%1 %1, %3 *valuePtr, uint32 num%2);\n"
+ "#endif\n",
+ dvPrefix, name, propName, propTypeString, preString, postString, dvClassGetPrefix(theClass));
+ dvWrtemp(dvFile,
+ "#ifndef %0%1Seti%2\n"
+ "extern void %0%1Seti%2(%6%1 %1, uint32 x, %7 value);\n"
+ "#endif\n",
+ dvPrefix, name, propName, dvPropertyGetIndex(prop), preString, postString, dvClassGetPrefix(theClass),
+ propTypeString);
} else if(dvPropertyArray(prop)) {
/* Fixed sized arrays */
dvWrtemp(dvFile,
@@ -693,7 +749,7 @@
"%4 %0%1s.%2[%0%12Index(%1)*(%3) + %0%1Check%2Index(%1, x)] = value;%5}\n",
dvPrefix, name, propName, dvPropertyGetIndex(prop), preString, postString, dvClassGetPrefix(theClass),
propTypeString);
- } else if(dvPropertySparse(prop)) {
+ } else if(dvPropertySparse(prop) && !dvPropertyView(prop)) {
/* Access the data through the hash table */
dvWrtemp(dvFile,
"extern %5 %0%1%3%2(%4%1 %1);\n"
@@ -727,8 +783,18 @@
preString = "";
postString = "";
}
- if(dvPropertyGetType(prop) == PROP_BIT) {
+ if(dvPropertyView(prop)) {
dvWrtemp(dvFile,
+ "#ifndef %0%1%2\n"
+ "extern %4 %0%1%5%2(%3%1 %1);\n"
+ "#endif\n"
+ "#ifndef %0%1Set%2\n"
+ "extern void %0%1Set%2(%3%1 %1, %4 value);\n"
+ "#endif\n",
+ dvPrefix, name, propName, dvClassGetPrefix(theClass), propTypeString, accessString);
+ }
+ else if(dvPropertyGetType(prop) == PROP_BIT) {
+ dvWrtemp(dvFile,
"static utInlineC bool %0%1%2(%3%1 %1) {\n"
" return (%0%1s.%2[%3%12ValidIndex(%1) >> 3] >> (%3%12ValidIndex(%1) & 7)) & 1;}\n"
"static utInlineC void %0%1Set%2(%3%1 %1, bool value) {\n"
@@ -774,7 +840,7 @@
char *parameters = "";
dvForeachRelationshipKey(relationship, key) {
- property = dvKeyGetProperty(key);
+ property = dvKeypropertyGetProperty(dvKeyGetLastKeyproperty(key));
if(!dvPropertyArray(property)) {
parameters = utSprintf("%s, %s %s", parameters, dvPropertyGetTypeName(property), dvPropertyGetName(property));
} else if(!dvPropertyFixedSize(property)) {
@@ -911,13 +977,18 @@
char *nullObj;
dvForeachClassProperty(theClass, prop) {
- if(dvPropertyArray(prop)) {
+ if(dvPropertyView(prop)) {
+ dvWrtemp(dvFile,
+ " /* %0.%1 init is user responsability */\n",
+ dvClassGetName(theClass), dvPropertyGetName(prop));
+ }
+ else if(dvPropertyArray(prop)) {
if(!dvPropertyFixedSize(prop)) {
dvWrtemp(dvFile,
" %0%1SetNum%2(%1, 0);\n",
dvPrefix, dvClassGetName(theClass), dvPropertyGetName(prop));
} else {
- /* Todo: write this */
+ /* TODO: write this */
}
} else {
theUnion = dvPropertyGetUnion(prop);
@@ -1049,7 +1120,7 @@
dvPrefix, name, dvClassGetReferenceTypeName(theClass));
dvWrtemp(dvFile, "static utInlineC void %0%1FreeAll(void) {%0SetUsed%1(1);", dvPrefix, name);
dvForeachClassProperty(theClass, prop) {
- if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop)) {
+ if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop) && !dvPropertyView(prop)) {
dvWrtemp(dvFile, " %0SetUsed%1%2(0);" , dvPrefix, name,
dvPropertyGetName(prop));
}
@@ -1078,7 +1149,7 @@
"static utInlineC void %0%1Free(%0%1 %1) {\n",
dvPrefix, name);
dvForeachClassProperty(theClass, prop) {
- if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop)) {
+ if(dvPropertyArray(prop) && !dvPropertyFixedSize(prop) && !dvPropertyView(prop)) {
dvWrtemp(dvFile,
" %0%1Free%2s(%1);\n",
dvPrefix, name, dvPropertyGetName(prop));
Index: src/dv.h
===================================================================
--- src/dv.h (revision 542)
+++ src/dv.h (working copy)
@@ -47,6 +47,8 @@
dvCase dvCaseCreate(dvProperty property, dvEntry entry);
dvSparsegroup dvSparsegroupCreate(dvClass theClass, utSym sym);
dvCache dvCacheCreate(dvClass theClass);
+dvKeyproperty dvUnboundKeypropertyCreate(dvKey key, utSym sym);
+dvKey dvKeypropertyCreate(dvKey key, dvProperty property);
/* Utility functions */
void prUtilStart(void);
@@ -68,6 +70,10 @@
bool dvRelationshipHashedByName(dvRelationship relationship);
char *dvPropertyFindInitializer(dvProperty property);
dvProperty dvClassLookupProperty(dvClass theClass, utSym sym);
+char *dvKeyGetLengthMacro(dvKey key, bool useParamName, char *param);
+char *dvKeyGetAccessMacro(dvKey key, bool useParamName, char * param);
+char *dvPropertyGetLengthMacro(dvProperty property, bool useParamName, char * param);
+char *dvPropertyGetAccessMacro(dvProperty property, bool useParamName, char * param);
/* Some shortcut macros */
#define dvModuleGetPrefix(module) utSymGetName(dvModuleGetPrefixSym(module))
Index: src/dvgenerate.c
===================================================================
--- src/dvgenerate.c (revision 542)
+++ src/dvgenerate.c (working copy)
@@ -147,18 +147,20 @@
dvRelationship relationship)
{
dvProperty property;
+ dvKeyproperty keyproperty;
dvPropident propident;
dvKey key;
utSym propSym;
dvForeachRelationshipKey(relationship, key) {
- property = dvKeyGetProperty(key);
+ keyproperty = dvKeyGetLastKeyproperty(key);
+ property = dvKeypropertyGetProperty(keyproperty);
if(property != dvPropertyNull) {
if(dvPropertyGetCache(property) == dvCacheNull) {
dvCacheAppendProperty(cache, property);
}
} else {
- propSym = dvKeyGetPropertySym(key);
+ propSym = dvKeypropertyGetPropertySym(keyproperty);
if(propSym != utSymNull) {
propident = dvPropidentAlloc();
dvPropidentSetSym(propident, propSym);
@@ -560,22 +562,39 @@
static void bindKeysToProperties(
dvModule module)
{
- dvClass theClass;
+ dvClass theClass, keyClass;
dvRelationship relationship;
dvProperty property;
dvKey key;
+ dvKeyproperty keyproperty;
dvForeachModuleClass(module, theClass) {
dvForeachClassParentRelationship(theClass, relationship) {
dvForeachRelationshipKey(relationship, key) {
- if(dvKeyGetProperty(key) == dvPropertyNull) {
- property = dvClassLookupProperty(theClass, dvKeyGetPropertySym(key));
- if(property == dvPropertyNull) {
- utError("Line %u: key %s not found on class %s", dvKeyGetLineNum(key),
- utSymGetName(dvKeyGetPropertySym(key)), dvClassGetName(theClass));
+ keyClass = theClass;
+ dvForeachKeyKeyproperty(key, keyproperty) {
+ if((property = dvKeypropertyGetProperty(keyproperty)) == dvPropertyNull) {
+ property = dvClassLookupProperty(keyClass, dvKeypropertyGetPropertySym(keyproperty));
+ if(property == dvPropertyNull) {
+ utError("Line %u: key %s not found on class %s", dvKeyGetLineNum(key),
+ utSymGetName(dvKeypropertyGetPropertySym(key)), dvClassGetName(theClass));
+ }
+ dvPropertyAppendKeyproperty(property, keyproperty);
}
- dvPropertyAppendKey(property, key);
- }
+ /* check for requirements on key element in the chain */
+ if(dvKeypropertyGetNextKeyKeyproperty(keyproperty) != dvKeypropertyNull) {
+ if(dvPropertyFixedSize(property)) {
+ utError("Line %u: only last element of a key chain is supported as variable size, here %s",
+ dvKeyGetLineNum(key),
+ utSymGetName(dvKeypropertyGetPropertySym(key)));
+ }
+ if(dvPropertyGetType(property) != PROP_POINTER) {
+ utError("Line %u: key %s must be bound to a class", dvKeyGetLineNum(key),
+ utSymGetName(dvKeypropertyGetPropertySym(key)));
+ }
+ }
+ keyClass = dvPropertyGetClassProp(property);
+ } dvEndKeyKeyproperty;
} dvEndRelationshipKey;
} dvEndClassParentRelationship;
} dvEndModuleClass;
Index: src/dvscan.l
===================================================================
--- src/dvscan.l (revision 542)
+++ src/dvscan.l (working copy)
@@ -195,8 +195,10 @@
<INITIAL>"undo_redo" {myDebug("KWUNDO_REDO\n"); return KWUNDO_REDO;}
<INITIAL>"union" {myDebug("KWUNION\n"); return KWUNION;}
<INITIAL>"unordered" {myDebug("KWUNORDERED\n"); return KWUNORDERED;}
+<INITIAL>"view" {myDebug("KWVIEW\n"); return KWVIEW;}
<INITIAL>"volatile" {myDebug("KWVOLATILE\n"); return KWVOLATILE;}
+<INITIAL>"." { myDebug(".\n"); return '.'; }
<INITIAL>"+"\n { myDebug("Line continuation\n"); dvLineNum++; }
<INITIAL>\n { myDebug("newline\n"); dvLineNum++; return '\n'; }
<INITIAL>[0-9]+ { dvlval.intVal = atol(dvlextext);
Index: src/dvbuild.c
===================================================================
--- src/dvbuild.c (revision 542)
+++ src/dvbuild.c (working copy)
@@ -247,7 +247,7 @@
}
/*--------------------------------------------------------------------------------------------------
- Create a new key, which is part of a hashed relationship.
+ Create a new key, which is part of a complex relationship.
--------------------------------------------------------------------------------------------------*/
dvKey dvKeyCreate(
dvRelationship relationship,
@@ -256,13 +256,28 @@
dvKey key = dvKeyAlloc();
dvRelationshipAppendKey(relationship, key);
- dvPropertyAppendKey(property, key);
+ dvKeypropertyCreate(key, property);
return key;
}
/*--------------------------------------------------------------------------------------------------
- Create a new unbound key, which is part of a hashed relationship.
+ Create a new key, which is part of a complex relationship.
--------------------------------------------------------------------------------------------------*/
+dvKeyproperty dvKeypropertyCreate(
+ dvKey key,
+ dvProperty property)
+{
+ dvKeyproperty keyproperty = dvKeypropertyAlloc();
+
+ dvKeyAppendKeyproperty(key, keyproperty);
+ dvPropertyAppendKeyproperty(property, keyproperty);
+ return keyproperty;
+}
+
+
+/*--------------------------------------------------------------------------------------------------
+ Create a new unbound key, which is part of a complex relationship.
+--------------------------------------------------------------------------------------------------*/
dvKey dvUnboundKeyCreate(
dvRelationship relationship,
utSym propertySym,
@@ -271,12 +286,27 @@
dvKey key = dvKeyAlloc();
dvRelationshipAppendKey(relationship, key);
- dvKeySetPropertySym(key, propertySym);
+ dvUnboundKeypropertyCreate(key, propertySym);
dvKeySetLineNum(key, lineNum);
return key;
}
/*--------------------------------------------------------------------------------------------------
+ Create a new unbound keyproperty, which is part of a complex relationship.
+--------------------------------------------------------------------------------------------------*/
+dvKeyproperty dvUnboundKeypropertyCreate(
+ dvKey key,
+ utSym propertySym)
+{
+ dvKeyproperty keyproperty = dvKeypropertyAlloc();
+
+ dvKeyAppendKeyproperty(key, keyproperty);
+ dvKeypropertySetPropertySym(keyproperty, propertySym);
+ return keyproperty;
+}
+
+
+/*--------------------------------------------------------------------------------------------------
Create a new case object linking a property in a union to an entry.
--------------------------------------------------------------------------------------------------*/
dvCase dvCaseCreate(
Index: src/dvparse.y
===================================================================
--- src/dvparse.y (revision 542)
+++ src/dvparse.y (working copy)
@@ -27,6 +27,7 @@
static dvUnion dvCurrentUnion;
static dvProperty dvCurrentProperty;
static dvRelationship dvCurrentRelationship;
+static dvKey dvCurrentKey;
static dvCache dvCurrentCache;
static uint32 dvCacheNumber;
static uint32 dvCurrentEnumValue;
@@ -154,6 +155,7 @@
%token KWUNDO_REDO
%token KWUNION
%token KWUNORDERED
+%token KWVIEW
%token KWVOLATILE
%%
@@ -367,6 +369,10 @@
{
dvPropertySetCascade(dvCurrentProperty, true);
}
+| KWVIEW
+{
+ dvPropertySetView(dvCurrentProperty, true);
+}
| KWSPARSE
{
if(dvCurrentUnion != dvUnionNull) {
@@ -592,10 +598,17 @@
;
key: /* empty */
-| key upperIdent
+| key keyproperties
+;
+
+keyproperties : upperIdent
{
- dvUnboundKeyCreate(dvCurrentRelationship, $2, dvLineNum);
+ dvCurrentKey = dvUnboundKeyCreate(dvCurrentRelationship, $1, dvLineNum);
}
+| keyproperties '.' upperIdent
+{
+ dvUnboundKeypropertyCreate(dvCurrentKey, $3);
+}
;
relationshipOption: KWCASCADE |