ide/designer/Property Sheet: Fixed uninitialized variable
[sdk] / ide / src / designer / Sheet.ec
index 0fc943f..395cba0 100644 (file)
@@ -2,10 +2,10 @@ import "ide"
 
 import "CodeObject"
 
-static void UnusedFunction()
+static __attribute__((unused)) void UnusedFunction()
 {
-   int a;
-   Module b;
+   int a = 0;
+   Module b = 0;
    a.OnGetString(0,0,0);
    a.OnFree();
    a.OnCopy(null);
@@ -72,6 +72,7 @@ void SetPropValue(Property prop, void * object, any_object value)
    }
 }
 
+/*
 any_object GetPropValue(Property prop, Instance object)
 {
    if(object)
@@ -89,11 +90,13 @@ any_object GetPropValue(Property prop, Instance object)
       // TOFIX: How to swiftly handle classes with base data type?
       else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
       {
+         // NOTE: must return double by reference
          double d = ((double(*)(void *))(void *)prop.Get)(object);
          return d;
       }
       else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
       {
+         // NOTE: must return float by reference
          float f =((float(*)(void *))(void *)prop.Get)(object);
          return f;
       }
@@ -121,7 +124,7 @@ any_object GetPropValue(Property prop, Instance object)
    else
       return 0;
 }
-
+*/
 void CopyProperty(Property prop, Instance dest, Instance src)
 {
    Class type = prop.dataTypeClass;
@@ -182,7 +185,7 @@ void GetProperty(Property prop, Instance object, DataValue value)
 #ifdef _DEBUG
          if(prop._class.module.application == __thisModule &&
             prop.dataTypeClass.module.application == ((Designer)GetActiveDesigner()).codeEditor.privateModule)
-            printf($"Warning");
+            printf("Warning");
 #endif
       }
 
@@ -301,7 +304,7 @@ class Sheet : Window
 
       bool NotifySelect(DropBox control, DataRow row, Modifiers keyFlags)
       {
-         ObjectInfo selected = (ObjectInfo)(row ? row.tag : null);
+         ObjectInfo selected = (ObjectInfo)(row ? (void *)(intptr)row.tag : null);
          ToolBox toolBox = ((IDEWorkSpace)parent).toolBox;
 
          if(codeEditor && selected)
@@ -326,7 +329,6 @@ class Sheet : Window
          if(selected && selected.instance && codeEditor)
          {
             Class _class;
-            int c = 0;
             int rowHeight = methods.rowHeight;
 
             propertyValue.userData = (void *)selected.instance;
@@ -507,7 +509,6 @@ class Sheet : Window
          CodeObject object = control.GetData(methodName);
          Menu menu { };
          PopupMenu popupMenu;
-         MenuItem item;
          if(object.overriden == 0)
          {
             MenuItem { menu, $"Override", o, enter, bold = true, NotifySelect = OverrideMethodSelected };
@@ -518,7 +519,7 @@ class Sheet : Window
                for(compatible = object.compatible.first; compatible; compatible = compatible.next)
                {
                   ClassFunction function = compatible.data;
-                  MenuItem { attachMenu, function.declarator.symbol.string, id = (int64)function, NotifySelect = AttachMethodSelected };
+                  MenuItem { attachMenu, function.declarator.symbol.string, id = (int64)(intptr)function, NotifySelect = AttachMethodSelected };
                }
             }
          }
@@ -541,7 +542,7 @@ class Sheet : Window
                   ClassFunction function = compatible.data;
                   if(function != object.function)
                   {
-                     MenuItem { attachMenu, function.declarator.symbol.string, id = (int64)function, NotifySelect = ReattachMethodSelected };
+                     MenuItem { attachMenu, function.declarator.symbol.string, id = (int64)(intptr)function, NotifySelect = ReattachMethodSelected };
                   }
                }
             }
@@ -720,7 +721,7 @@ class Sheet : Window
    void ListProperties(bool clear)
    {
       DataRow row = dropBox.currentRow;
-      ObjectInfo selected = row ? (ObjectInfo)row.tag : null;
+      ObjectInfo selected = row ? (ObjectInfo)(intptr)row.tag : null;
 
       //int scroll = 0;
       bool categorized = this.categorized.checked;
@@ -769,7 +770,6 @@ class Sheet : Window
          // Fill up the properties
          while(_class != selected.instance._class)
          {
-            BitMember bitMember = null;
             Class lastClass = _class;
             Property propIt;
 
@@ -824,13 +824,13 @@ class Sheet : Window
 
                         if(clear)
                         {
-                           row = categorized ? category.row.FindRow((int64)prop) : properties.FindRow((int64)prop);
+                           row = categorized ? category.row.FindRow((int64)(intptr)prop) : properties.FindRow((int64)(intptr)prop);
                            if(!row)
                               row = categorized ? category.row.AddRow() : properties.AddRow();
-                           row.tag = (int64)prop;
+                           row.tag = (int64)(intptr)prop;
                         }
                         else
-                           row = categorized ? category.row.FindRow((int64)prop) : properties.FindRow((int64)prop);
+                           row = categorized ? category.row.FindRow((int64)(intptr)prop) : properties.FindRow((int64)(intptr)prop);
 
                         row.SetData(propertyName, prop.name);
                         row.SetData(propertyValue, info);
@@ -858,10 +858,10 @@ class Sheet : Window
                                     if(clear)
                                     {
                                        subRow = row.AddRow();
-                                       subRow.tag = (int64)subProp;
+                                       subRow.tag = (int64)(intptr)subProp;
                                     }
                                     else
-                                       subRow = row.FindRow((int64)subProp);
+                                       subRow = row.FindRow((int64)(intptr)subProp);
 
                                     subRow.SetData(propertyName, subProp.name);
                                     subRow.SetData(propertyValue, info);
@@ -874,10 +874,10 @@ class Sheet : Window
                                  if(clear)
                                  {
                                     subRow = row.AddRow();
-                                    subRow.tag = (int64)member;
+                                    subRow.tag = (int64)(intptr)member;
                                  }
                                  else
-                                    subRow = row.FindRow((int64)member);
+                                    subRow = row.FindRow((int64)(intptr)member);
 
                                  subRow.SetData(propertyName, member.name);
                                  subRow.SetData(propertyValue, info);
@@ -892,10 +892,10 @@ class Sheet : Window
                                     if(clear)
                                     {
                                        subRow = row.AddRow();
-                                       subRow.tag = (int64)subMember;
+                                       subRow.tag = (int64)(intptr)subMember;
                                     }
                                     else
-                                       subRow = row.FindRow((int64)subMember);
+                                       subRow = row.FindRow((int64)(intptr)subMember);
 
                                     subRow.SetData(propertyName, subMember.name);
                                     subRow.SetData(propertyValue, info);
@@ -930,7 +930,7 @@ class Sheet : Window
                            DataRow row;
                            const char * name = prop.category ? prop.category : $"Misc";
                            Category category = categories.FindName(name, false);
-                           row = category ? (categorized ? category.row.FindRow((int64)prop) : properties.FindRow((int64)prop)) : null;
+                           row = category ? (categorized ? category.row.FindRow((int64)(intptr)prop) : properties.FindRow((int64)(intptr)prop)) : null;
                            properties.currentRow = row;
                            found = true;
                            break;
@@ -972,7 +972,7 @@ class Sheet : Window
 
       row = (DataRow)dropBox.AddRowAfter(after);
 
-      row.tag = (int64)object;
+      row.tag = (int64)(intptr)object;
 
       codeObject =
       {
@@ -983,7 +983,7 @@ class Sheet : Window
       };
 
       if(type != typeClass)
-         bitmap = (char *)eClass_GetProperty(object.instance._class, "icon");
+         bitmap = (char *)(intptr)eClass_GetProperty(object.instance._class, "icon");
       if(bitmap)
       {
          codeObject.bitmap = { bitmap };
@@ -1002,7 +1002,7 @@ class Sheet : Window
 
    void DeleteObject(ObjectInfo object)
    {
-      DataRow row = dropBox.FindRow((int64)object);
+      DataRow row = dropBox.FindRow((int64)(intptr)object);
       if(row)
       {
          CodeObject codeObject = row.GetData(null);
@@ -1017,7 +1017,7 @@ class Sheet : Window
    {
       if(this)
       {
-         DataRow row = dropBox.FindRow((int64)object);
+         DataRow row = dropBox.FindRow((int64)(intptr)object);
          this.object = object ? object.instance : null;
          propertyValue.userData = object ? (void *)object.instance : null;
          dropBox.SelectRow(row);
@@ -1026,7 +1026,7 @@ class Sheet : Window
 
    void RenameObject(ObjectInfo object, const char * name)
    {
-      DataRow row = dropBox.FindRow((int64)object);
+      DataRow row = dropBox.FindRow((int64)(intptr)object);
       CodeObject codeObject = row.GetData(null);
       // Isn't this useless? Shouldn't it be after?
       codeObject.name = name;
@@ -1079,7 +1079,7 @@ class Sheet : Window
                      BitMember bitMember = (BitMember) member;
                      if(subDataType)
                      {
-                        DataValue value { 0 };
+                        DataValue value { 0 };
                         value.ui = ((uint (*)(void *))(void *)prop.Get)(object);
                         value.ui &= ~ (uint)bitMember.mask;
                         value.ui |= *(uint32 *)setValue << bitMember.pos;
@@ -1191,22 +1191,20 @@ class Sheet : Window
 
    bool AttachMethodSelected(MenuItem selection, Modifiers mods)
    {
-      ClassFunction function = (ClassFunction)selection.id;
+      ClassFunction function = (ClassFunction)(intptr)selection.id;
       codeEditor.AttachMethod(attachMethod, function);
       return true;
    }
 
    bool ReattachMethodSelected(MenuItem selection, Modifiers mods)
    {
-      ClassFunction function = (ClassFunction)selection.id;
-      CodeObject object = methods.GetData(methodName);
+      ClassFunction function = (ClassFunction)(intptr)selection.id;
       codeEditor.ReAttachMethod(attachMethod, function);
       return true;
    }
 
    bool OverrideMethodSelected(MenuItem selection, Modifiers mods)
    {
-      ClassFunction function = (ClassFunction)selection.id;
       CodeObject object = methods.GetData(methodName);
       if(object)
          codeEditor.AddMethod(object.method);
@@ -1215,7 +1213,6 @@ class Sheet : Window
 
    bool GotoMethodSelected(MenuItem selection, Modifiers mods)
    {
-      ClassFunction function = (ClassFunction)selection.id;
       CodeObject object = methods.GetData(methodName);
       if(object)
          codeEditor.GoToMethod(object.method.name);
@@ -1224,7 +1221,6 @@ class Sheet : Window
 
    bool DetachMethodSelected(MenuItem selection, Modifiers mods)
    {
-      ClassFunction function = (ClassFunction)selection.id;
       CodeObject object = methods.GetData(methodName);
       if(object)
          codeEditor.DetachMethod(object.method, object.function, object.overriden);
@@ -1233,7 +1229,6 @@ class Sheet : Window
 
    bool DeleteMethodSelected(MenuItem selection, Modifiers mods)
    {
-      ClassFunction function = (ClassFunction)selection.id;
       CodeObject object = methods.GetData(methodName);
       if(object)
          object.deleteBtn.NotifyClicked(this, object.deleteBtn, 0,0,0);
@@ -1242,7 +1237,7 @@ class Sheet : Window
 
    bool AddMethodClicked(Button button, int x, int y, Modifiers mods)
    {
-      DataRow row = (DataRow)button.id;
+      DataRow row = (DataRow)(intptr)button.id;
       CodeObject object = row.GetData(methodName);
       codeEditor.AddMethod(object.method);
       return true;
@@ -1250,8 +1245,6 @@ class Sheet : Window
 
    void CreateButtons(CodeObject codeObject, int y, int h, DataRow row)
    {
-      BitmapResource bitmap;
-
       if(codeObject.overriden)
       {
          if(codeObject.overriden == 1)
@@ -1263,11 +1256,11 @@ class Sheet : Window
                bitmap = { ":actions/delete.png", alphaBlend = true },
                anchor = { right = 16, top = y },
                size = { 16, h },
-               id = (int64)row;
+               id = (int64)(intptr)row;
 
                bool NotifyClicked(Button button, int x, int y, Modifiers mods)
                {
-                  CodeObject codeObject = ((DataRow)button.id).GetData(null);
+                  CodeObject codeObject = ((DataRow)(intptr)button.id).GetData(null);
                   bool confirmation = !Code_IsFunctionEmpty(codeObject.function, codeObject.method, codeEditor.selected);
 
                   if(confirmation)
@@ -1316,11 +1309,11 @@ class Sheet : Window
                bitmap = { ":actions/detach.png" },
                anchor = { right = 0, top = y },
                size = { 16, h },
-               id = (int64)row;
+               id = (int64)(intptr)row;
 
                bool NotifyClicked(Button button, int x, int y, Modifiers mods)
                {
-                  DataRow row = (DataRow)button.id;
+                  DataRow row = (DataRow)(intptr)button.id;
                   CodeObject object = row.GetData(methodName);
 
                   codeEditor.DetachMethod(object.method, object.function, object.overriden);
@@ -1342,12 +1335,12 @@ class Sheet : Window
                bitmap = { ":actions/attach.png" },
                anchor = { right = 0, top = y },
                size = { 16, h },
-               id = (int64)row;
+               id = (int64)(intptr)row;
 
                bool NotifyPushed(Button button, int x, int y, Modifiers mods)
                {
                   // Create menu
-                  DataRow row = (DataRow)button.id;
+                  DataRow row = (DataRow)(intptr)button.id;
                   CodeObject object = row.GetData(methodName);
                   OldLink compatible;
                   PopupMenu popupMenu;
@@ -1357,7 +1350,7 @@ class Sheet : Window
                   for(compatible = object.compatible.first; compatible; compatible = compatible.next)
                   {
                      ClassFunction function = compatible.data;
-                     MenuItem { menu, function.declarator.symbol.string, id = (int64)function, NotifySelect = AttachMethodSelected };
+                     MenuItem { menu, function.declarator.symbol.string, id = (int64)(intptr)function, NotifySelect = AttachMethodSelected };
                   }
                   attachMethod = object.method;
 
@@ -1494,7 +1487,8 @@ public:
                   if(dataType.type == bitClass)
                   {
                      BitMember bitMember = (BitMember)member;
-                     bitValue = (valueData.i & bitMember.mask) >> bitMember.pos;
+                     bitValue = (valueData.ui64 & bitMember.mask) >> bitMember.pos;
+                     // TOCHECK: endian safe?
                      dataPtr = &bitValue;
                   }
                   else
@@ -1568,7 +1562,7 @@ public:
             }
             else
             {
-               bool freeDataForm = false, freeDataTest = false;
+               //bool freeDataForm = false, freeDataTest = false;
                // Because contents property is broken for mutiline EditBox at the moment
                if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox") && ((EditBox)object).multiLine)
                {
@@ -1599,7 +1593,8 @@ public:
                   if(dataType.type == bitClass)
                   {
                      BitMember bitMember = (BitMember)member;
-                     bitValue = (valueData.i & bitMember.mask) >> bitMember.pos;
+                     bitValue = (valueData.ui64 & bitMember.mask) >> bitMember.pos;
+                     // TOCHECK: endian safe?
                      dataPtr = &bitValue;
                   }
                   else
@@ -1735,8 +1730,9 @@ public:
          bool result = false;
          void * dataPtr, * data = null, * subData = null;
          void * propObject = null;
-         DataValue valueData = { 0 }, valueSubData = { 0 };
-         uint bitValue;
+         DataValue valueData { 0 };
+         DataValue valueSubData { 0 };
+         uint64 bitValue;
 
          if(!mainDataType)
             mainDataType = prop.dataTypeClass = eSystem_FindClass(((Designer)GetActiveDesigner()).codeEditor.privateModule, prop.dataTypeString);
@@ -1761,7 +1757,6 @@ public:
 
             if(this.subMember || this.subProperty)
             {
-               Class _class;
                Instance current = (Instance)((void *(*)(void *))(void *)prop.Get)(object);
                propObject = valueData.p = eInstance_New(dataType);
                CopyInstanceData(dataType, propObject, current);
@@ -1787,7 +1782,12 @@ public:
             if(subDataType)
             {
                if(dataType.type == bitClass)
+               {
+                  BitMember bitMember = (BitMember)member;
+                  bitValue = (valueData.ui64 & bitMember.mask) >> bitMember.pos;
+                  // TOCHECK: endian safe?
                   dataPtr = &bitValue;
+               }
                else
                   dataPtr = (byte *)dataPtr + member.offset + this.extraOffset;
             }
@@ -1822,8 +1822,8 @@ public:
                if(mainDataType.type == bitClass && this.subMember)
                {
                   BitMember bitMember = (BitMember)this.subMember;
-                  valueData.ui &= ~ (uint)bitMember.mask;
-                  valueData.ui |= bitValue << bitMember.pos;
+                  valueData.ui64 &= ~bitMember.mask;
+                  valueData.ui64 |= bitValue << bitMember.pos;
                }
                if(this.subProperty)
                {