ecere: Fixed strict aliasing warnings
authorJerome St-Louis <jerome@ecere.com>
Thu, 3 Jul 2014 08:35:01 +0000 (04:35 -0400)
committerJerome St-Louis <jerome@ecere.com>
Thu, 3 Jul 2014 08:35:01 +0000 (04:35 -0400)
compiler/bootstrap/ecere/bootstrap/Map.c
ecere/src/com/containers/Map.ec
ecere/src/gfx/Display.ec
ecere/src/gfx/drivers/Direct3D8DisplayDriver.ec
ecere/src/gfx/drivers/Direct3D9DisplayDriver.ec
ecere/src/gfx/drivers/OpenGLDisplayDriver.ec
ecere/src/sys/JSON.ec

index 5092ff5..779019e 100644 (file)
@@ -687,7 +687,7 @@ unsigned int size = sizeof(struct __ecereNameSpace__ecere__com__MapNode);
 if(((struct __ecereNameSpace__ecere__com__Instance *)(char *)this)->_class->templateArgs[5].__anon1.__anon1.dataTypeClass->type == 1)
 size += ((struct __ecereNameSpace__ecere__com__Instance *)(char *)this)->_class->templateArgs[5].__anon1.__anon1.dataTypeClass->typeSize - sizeof node->key;
 if(((struct __ecereNameSpace__ecere__com__Instance *)(char *)this)->_class->templateArgs[6].__anon1.__anon1.dataTypeClass->type == 1)
-size += ((struct __ecereNameSpace__ecere__com__Instance *)(char *)this)->_class->templateArgs[6].__anon1.__anon1.dataTypeClass->typeSize - sizeof (((((((struct __ecereNameSpace__ecere__com__Instance * )(char * )this)->_class->templateArgs[6].__anon1.__anon1.dataTypeClass->type == 1) ? ((uint64)(uintptr_t)&node->value) : ((((struct __ecereNameSpace__ecere__com__Instance * )(char * )this)->_class->templateArgs[6].__anon1.__anon1.dataTypeClass->typeSize == 1) ? *((unsigned char *)&node->value) : ((((struct __ecereNameSpace__ecere__com__Instance * )(char * )this)->_class->templateArgs[6].__anon1.__anon1.dataTypeClass->typeSize == 2) ? *((unsigned short *)&node->value) : ((((struct __ecereNameSpace__ecere__com__Instance * )(char * )this)->_class->templateArgs[6].__anon1.__anon1.dataTypeClass->typeSize == 4) ? *((unsigned int *)&node->value) : *(&node->value))))))));
+size += ((struct __ecereNameSpace__ecere__com__Instance *)(char *)this)->_class->templateArgs[6].__anon1.__anon1.dataTypeClass->typeSize - sizeof(uint64);
 node = (struct __ecereNameSpace__ecere__com__MapNode *)__ecereNameSpace__ecere__com__eSystem_New0(sizeof(unsigned char) * (size));
 }
 else
index 8d247e3..aac77b8 100644 (file)
@@ -183,7 +183,8 @@ public class Map<class MT, class V> : CustomAVLTree<MapNode<MT, V>, I = MT, D =
             uint size = sizeof(class MapNode<MT, V>);
 
             if(class(MT).type == structClass) size += class(MT).typeSize - sizeof(node.AVLNode::key);
-            if(class(V).type == structClass) size += class(V).typeSize - sizeof(*&node.value);
+            if(class(V).type == structClass)
+               size += class(V).typeSize - sizeof(uint64); //sizeof(*&node.value);  // TODO: Simplify code generation for this sizeof
             node = (MapNode<MT, V>)new0 byte[size];
          }
          else
index 7705ba9..8ac831d 100644 (file)
@@ -33,6 +33,8 @@ import "Vector3D"
 
 public enum RenderState { fillMode = 1, depthTest, depthWrite, fogDensity, fogColor, blend, ambient, alphaWrite, antiAlias, vSync };
 
+public union RenderStateFloat { float f; uint ui; };
+
 public enum FillModeValue { solid, wireframe };
 
 public class DisplayFlags
@@ -1101,7 +1103,7 @@ public:
    property FillModeValue fillMode { set { displaySystem.driver.SetRenderState(this, fillMode, value); } };
    property bool depthTest    { set { displaySystem.driver.SetRenderState(this, depthTest, value); } };
    property bool depthWrite   { set { displaySystem.driver.SetRenderState(this, depthWrite, value); } };
-   property float fogDensity  { set { displaySystem.driver.SetRenderState(this, fogDensity, *(uint *)(void *)&value); } };
+   property float fogDensity  { set { displaySystem.driver.SetRenderState(this, fogDensity, RenderStateFloat { value }.ui); } };
    property Color fogColor    { set { displaySystem.driver.SetRenderState(this, fogColor, value); } };
    property bool blend        { set { displaySystem.driver.SetRenderState(this, blend, value); } };
    property Color ambient     { set { displaySystem.driver.SetRenderState(this, ambient, value); } };
index e4ccc6e..83de7fb 100644 (file)
@@ -523,7 +523,7 @@ class Direct3D8DisplayDriver : DisplayDriver
             IDirect3DDevice8_SetRenderState(d3dDevice, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
             IDirect3DDevice8_SetRenderState(d3dDevice, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
             IDirect3DDevice8_SetRenderState(d3dDevice, D3DRS_FOGTABLEMODE, D3DFOG_EXP);
-            IDirect3DDevice8_SetRenderState(d3dDevice, D3DRS_FOGDENSITY, *(uint *)(void *)&fogDensity);
+            IDirect3DDevice8_SetRenderState(d3dDevice, D3DRS_FOGDENSITY, RenderStateFloat { fogDensity }.ui);
             display.ambient = Color { 50,50,50 };
             IDirect3DDevice8_SetRenderState(d3dDevice, D3DRS_NORMALIZENORMALS, TRUE);
             IDirect3DDevice8_SetRenderState(d3dSystem.d3dDevice, D3DRS_MULTISAMPLEANTIALIAS, FALSE);
@@ -1086,8 +1086,8 @@ class Direct3D8DisplayDriver : DisplayDriver
             break;
          case fogDensity:
          {
-            float fogDensity = *(float *)(void *)&value;
-            IDirect3DDevice8_SetRenderState(d3dSystem.d3dDevice, D3DRS_FOGDENSITY, *(uint *)(void *)&fogDensity);
+            float fogDensity = RenderStateFloat { ui = value }.f;
+            IDirect3DDevice8_SetRenderState(d3dSystem.d3dDevice, D3DRS_FOGDENSITY, RenderStateFloat { fogDensity }.ui);
             break;
          }
          case blend:
@@ -1114,10 +1114,12 @@ class Direct3D8DisplayDriver : DisplayDriver
             { light.specular.r, light.specular.g, light.specular.b, 1.0f },
             { light.ambient.r, light.ambient.g, light.ambient.b,    1.0f }
          };
+         Vector3Df * lightDirection;
          Vector3Df vector {0,0,1};
          Vector3Df vectorPI {0,0,-1};
          Vector3Df direction;
          Matrix mat;
+         lightDirection = (Vector3Df *)&d3dLight.Direction;
 
          mat.RotationQuaternion(light.orientation);
 
@@ -1129,9 +1131,7 @@ class Direct3D8DisplayDriver : DisplayDriver
             d3dLight.Direction.z =-direction.z;
          }
          else
-         {
-            ((Vector3Df *)&d3dLight.Direction)->MultMatrix(direction, d3dDisplay.worldMatrix);
-         }
+            lightDirection->MultMatrix(direction, d3dDisplay.worldMatrix);
 
          d3dDisplay.lights[id] = d3dLight;
 
@@ -1139,7 +1139,7 @@ class Direct3D8DisplayDriver : DisplayDriver
          IDirect3DDevice8_SetLight(d3dSystem.d3dDevice, id, &d3dDisplay.lights[id]);
 
          direction.MultMatrix(vectorPI, mat);
-         ((Vector3Df *)&d3dLight.Direction)->MultMatrix(direction, d3dDisplay.worldMatrix);
+         lightDirection->MultMatrix(direction, d3dDisplay.worldMatrix);
 
          d3dDisplay.lightsPI[id] = d3dLight;
       }
index b614776..1ad34c4 100644 (file)
@@ -517,7 +517,7 @@ class Direct3D9DisplayDriver : DisplayDriver
             IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
             IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
             IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_FOGTABLEMODE, D3DFOG_EXP);
-            IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_FOGDENSITY, *(uint *)(void *)&fogDensity);
+            IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_FOGDENSITY, RenderStateFloat { fogDensity }.ui);
             display.ambient = Color { 50,50,50 };
             IDirect3DDevice9_SetRenderState(d3dDevice, D3DRS_NORMALIZENORMALS, TRUE);
             IDirect3DDevice9_SetRenderState(d3dSystem.d3dDevice, D3DRS_MULTISAMPLEANTIALIAS, FALSE);
@@ -1099,8 +1099,8 @@ class Direct3D9DisplayDriver : DisplayDriver
             break;
          case fogDensity:
          {
-            float fogDensity = *(float *)(void *)&value;
-            IDirect3DDevice9_SetRenderState(d3dSystem.d3dDevice, D3DRS_FOGDENSITY, *(uint *)(void *)&fogDensity);
+            float fogDensity = RenderStateFloat { ui = value }.f;
+            IDirect3DDevice9_SetRenderState(d3dSystem.d3dDevice, D3DRS_FOGDENSITY, RenderStateFloat { fogDensity }.ui);
             break;
          }
          case blend:
@@ -1140,6 +1140,7 @@ class Direct3D9DisplayDriver : DisplayDriver
          Vector3Df vectorPI {0,0,-1};
          Vector3Df direction;
          Matrix mat;
+         Vector3Df * lightDirection = (Vector3Df *)&d3dLight.Direction;
 
          mat.RotationQuaternion(light.orientation);
 
@@ -1151,10 +1152,7 @@ class Direct3D9DisplayDriver : DisplayDriver
             d3dLight.Direction.z =-direction.z;
          }
          else
-         {
-            // TODO: Precomp problem without the { }
-            ((Vector3Df *)&d3dLight.Direction)->MultMatrix(direction, d3dDisplay.worldMatrix);
-         }
+            lightDirection->MultMatrix(direction, d3dDisplay.worldMatrix);
 
          d3dDisplay.lights[id] = d3dLight;
 
@@ -1162,7 +1160,7 @@ class Direct3D9DisplayDriver : DisplayDriver
          IDirect3DDevice9_SetLight(d3dSystem.d3dDevice, id, &d3dDisplay.lights[id] /*d3dLight*/);
 
          direction.MultMatrix(vectorPI, mat);
-         ((Vector3Df *)&d3dLight.Direction)->MultMatrix(direction, d3dDisplay.worldMatrix);
+         lightDirection->MultMatrix(direction, d3dDisplay.worldMatrix);
 
          d3dDisplay.lightsPI[id] = d3dLight;
       }
index ff7c27b..53a3b35 100644 (file)
@@ -3190,8 +3190,7 @@ class OpenGLDisplayDriver : DisplayDriver
             break;
          }
          case fogDensity:
-            value *= nearPlane;
-            glFogf(GL_FOG_DENSITY, *(float *)(void *)&value);
+            glFogf(GL_FOG_DENSITY, (float)(RenderStateFloat { value }.f * nearPlane));
             break;
          case blend:
             if(value) glEnable(GL_BLEND); else glDisable(GL_BLEND);
index 5388f9b..70b86e1 100644 (file)
@@ -210,11 +210,11 @@ public:
                }
                else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
                {
-                  t = *(uint64 *)&value.d;
+                  t = value.ui64; //*(uint64 *)&value.d;
                }
                else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
                {
-                  t = *(uint *)&value.f;
+                  t = value.ui; //f*(uint *)&value.f;
                }
                else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
                   !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))
@@ -720,11 +720,13 @@ bool WriteArray(File f, Class type, Container array, int indent)
          }
          else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
          {
-            value.d = *(double *)&t;
+            value.ui64 = t;
+            //value.d = *(double *)&t;
          }
          else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
          {
-            value.f = *(float *)&t;
+            value.ui = (uint)t;
+            //value.f = *(float *)&t;
          }
          else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
             !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))