Various fixes for Android
[sdk] / ide / src / project / Workspace.ec
index 145ed3e..bf868e4 100644 (file)
@@ -22,6 +22,29 @@ import "ide"
 }*/
 
 enum OpenedFileState { unknown, opened, closed };
+enum ValgrindLeakCheck
+{
+   no, summary, yes, full;
+
+   property const char *
+   {
+      get { return OnGetString(null, null, null); }
+   }
+
+   const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+   {
+      if(this >= no && this <= full)
+      {
+         if(tempString)
+            strcpy(tempString, valgrindLeakCheckNames[this]);
+         return valgrindLeakCheckNames[this];
+      }
+      if(tempString && tempString[0])
+         tempString[0] = '\0';
+      return null;
+   }
+};
+static const char * valgrindLeakCheckNames[ValgrindLeakCheck] = { "no", "summary", "yes", "full" };
 
 class OpenedFileInfo
 {
@@ -58,7 +81,7 @@ class OpenedFileInfo
          ide.workspace.modified = true;
       }
    }
-   
+
    void Activate()
    {
       if(trackingAllowed)
@@ -69,7 +92,7 @@ class OpenedFileInfo
          {
             files.Move(it.pointer, files.GetPrev(files.GetLast()));
             ide.workspace.modified = true;
-         } 
+         }
       }
    }
    ~OpenedFileInfo()
@@ -85,13 +108,13 @@ public:
    char * workspaceFile;
    char * workspaceDir;
    char * commandLineArgs;
-   property char * commandLineArgs { set { delete commandLineArgs; if(value) commandLineArgs = CopyString(value); } }
+   property const char * commandLineArgs { set { delete commandLineArgs; if(value) commandLineArgs = CopyString(value); } }
    char * debugDir;
-   property char * debugDir { set { delete debugDir; if(value) debugDir = CopyString(value); } }
+   property const char * debugDir { set { delete debugDir; if(value) debugDir = CopyString(value); } }
 
    int bpCount;
 
-   property char * compiler
+   property const char * compiler
    {
       set { delete compiler; if(value && value[0]) compiler = CopyString(value); }
       get { return compiler && compiler[0] ? compiler : null; }
@@ -120,7 +143,7 @@ public:
       }
    };
 
-   property char * workspaceFile
+   property const char * workspaceFile
    {
       set
       {
@@ -134,7 +157,7 @@ public:
       get { return workspaceFile; }
    }
 
-   property char * projectDir
+   property const char * projectDir
    {
       get
       {
@@ -159,7 +182,7 @@ public:
          if(project)
          {
             projectDir = CopyString(project.topNode.path);
-            
+
             if(!project.config && activeConfig && activeConfig[0])
             {
                ProjectConfig cfg;
@@ -177,13 +200,22 @@ public:
 
 private:
    String compiler;
+   int bitDepth;
+   // TODO: save these new settings when json format is ready
+   bool useValgrind;
+   ValgrindLeakCheck vgLeakCheck;
+   bool vgTrackOrigins;
+   int vgRedzoneSize;
+
+   vgRedzoneSize = -1;
+   vgLeakCheck = summary;
 
 public:
    void Save()
    {
       bool bkpts = false;
       File file;
-      
+
       file = FileOpen(workspaceFile, write);
       if(file)
       {
@@ -198,16 +230,16 @@ public:
                   file.Printf("Breakpoint=0,%d,%s,%s\n", bp.line, bp.absoluteFilePath, bp.relativeFilePath);
             }
          }
-         
+
          for(wh : watches)
             file.Printf("Watch=%s\n", wh.expression);
-         
+
          for(dir : sourceDirs)
             file.Printf("SourceDir=%s\n", dir);
 
          if(debugDir && debugDir[0])
             file.Printf("DebugDir=%s\n", debugDir);
-         
+
          if(commandLineArgs && commandLineArgs[0])
             file.Printf("CommandLineArgs=%s\n", commandLineArgs);
          */
@@ -220,7 +252,8 @@ public:
          file.Printf("\nVersion 0.02\n");
          file.Printf("\nWorkspace\n");
          file.Printf("\n   Active Compiler = %s\n", compiler ? compiler : defaultCompilerName);
-         
+         file.Printf("\n   Active Bit Depth = %d\n", bitDepth);
+
          if(projects.first)
          {
             file.Printf("\n   Projects\n\n");
@@ -233,7 +266,7 @@ public:
                //strcat(location, ".epj");
 
                file.Printf("    %s %s\n", "-", location);
-               
+
                if(prj.config)
                   file.Printf("         Active Configuration = %s\n", prj.config.name);
                for(cfg : prj.configurations)
@@ -245,7 +278,7 @@ public:
                }
             }
          }
-         
+
          file.Printf("\n   Execution Data\n");
          if(commandLineArgs && commandLineArgs[0])
          {
@@ -325,16 +358,17 @@ public:
       }
    }
 
-   char * GetAbsolutePathFromRelative(char * relative)
+   char * GetAbsolutePathFromRelative(const char * relative)
    {
       char name[MAX_LOCATION];
       char absolute[MAX_LOCATION];
       Project prj = null;
+      ProjectNode node = null;
 
       GetLastDirectory(relative, name);
       for(p : projects)
       {
-         if(p.topNode.Find(name, false))
+         if((node = p.topNode.Find(name, false)))
          {
             prj = p;
             break;
@@ -342,8 +376,7 @@ public:
       }
       if(prj)
       {
-         strcpy(absolute, prj.topNode.path);
-         PathCatSlash(absolute, relative);
+         node.GetFullFilePath(absolute);
          return CopyString(absolute);
       }
 
@@ -375,11 +408,11 @@ public:
                return CopyString(absolute);
          }
       }
-      
+
       return null;
    }
 
-   char * GetPathWorkspaceRelativeOrAbsolute(char * path)
+   char * GetPathWorkspaceRelativeOrAbsolute(const char * path)
    {
       if(IsPathInsideOf(path, workspaceDir))
       {
@@ -391,7 +424,25 @@ public:
          return CopyUnixPath(path);
    }
 
-   OpenedFileInfo UpdateOpenedFileInfo(char * fileName, OpenedFileState state)
+   Array<ProjectNode> GetAllProjectNodes(const char *fullPath, bool skipExcluded)
+   {
+      Array<ProjectNode> nodes = null;
+      for(project : projects)
+      {
+         ProjectNode node;
+         if((node = project.topNode.FindByFullPath(fullPath, false)))
+         {
+            if(!skipExcluded || !node.GetIsExcluded(project.config))
+            {
+               if(!nodes) nodes = { };
+               nodes.Add(node);
+            }
+         }
+      }
+      return nodes;
+   }
+
+   OpenedFileInfo UpdateOpenedFileInfo(const char * fileName, OpenedFileState state)
    {
       char filePath[MAX_LOCATION];
       OpenedFileInfo ofi = null;
@@ -428,34 +479,58 @@ public:
 
    void UpdateSourceDirsArray(Array<String> dirs)
    {
-      byte * tokens[256];
-      int c, numTokens;
-
       sourceDirs.Free();
-      
+
       for(s : dirs)
          sourceDirs.Add(CopyString(s));
-      
-      DropInvalidBreakpoints();
+
+      DropInvalidBreakpoints(null);
 
       delete dirs;
    }
-   
+
    void RemoveProject(Project project)
    {
       Iterator<Project> it { projects };
       if(it.Find(project))
          it.Remove();
 
-      DropInvalidBreakpoints();
+      for(bp : breakpoints)
+      DropInvalidBreakpoints(project);
       modified = true;
       ide.findInFilesDialog.RemoveProjectItem(project);
+      ide.UpdateToolBarActiveConfigs(false);
       Save();
 
       delete project;
    }
 
-   bool FindPath(ProjectNode node, char * path)
+   void SelectActiveConfig(const char * configName)
+   {
+      bool change = false;
+      for(prj : ide.workspace.projects)
+      {
+         for(cfg : prj.configurations)
+         {
+            if(cfg.name && !strcmp(cfg.name, configName))
+            {
+               prj.config = cfg;
+               change = true;
+               break;
+            }
+         }
+      }
+      if(change)
+      {
+         modified = true;
+         ide.UpdateToolBarActiveConfigs(true);
+         ide.projectView.Update(null);
+         Save();
+      }
+      ide.AdjustDebugMenus();
+   }
+
+   bool FindPath(ProjectNode node, const char * path)
    {
       if(node.type == file)
       {
@@ -479,18 +554,23 @@ public:
       return false;
    }
 
-   void ChangeBreakpoint(DataRow row, char * location)
+   void ChangeBreakpoint(DataRow row, const char * location)
    {
-      Breakpoint bp = (Breakpoint)row.tag;
+      Breakpoint bp = (Breakpoint)(intptr)row.tag;
       if(bp)
       {
-         char * currentLoc = bp.LocationToString();
+         char * currentLoc = bp.CopyUserLocationString();
          if(strcmp(location, currentLoc))
          {
-            // todo, parse location
-            //  if good, make changes to breakpoint, according to execution state delete and place breakpoint
-            ide.breakpointsView.UpdateBreakpoint(row); // this is the else
-            //Save();
+            char * newLoc;
+            bp.location = location;
+            bp.ParseLocation();
+            newLoc = bp.CopyUserLocationString();
+            if(strcmp(newLoc, currentLoc))
+            {
+               ide.breakpointsView.UpdateBreakpoint(row);
+               Save();
+            }
          }
          delete currentLoc;
       }
@@ -502,7 +582,7 @@ public:
          //  else
          //     ...
          //bp = Breakpoint { };
-         //row.tag = (int)bp;
+         //row.tag = (int64)bp;
          //breakpoints.Add(bp);
          //bp.row = row;
          Save();
@@ -511,7 +591,7 @@ public:
 
    void ChangeBreakpointIgnore(DataRow row, int ignore)
    {
-      Breakpoint bp = (Breakpoint)row.tag;
+      Breakpoint bp = (Breakpoint)(intptr)row.tag;
       if(bp)
       {
          bp.ignore = ignore;
@@ -521,7 +601,7 @@ public:
 
    void ChangeBreakpointLevel(DataRow row, int level)
    {
-      Breakpoint bp = (Breakpoint)row.tag;
+      Breakpoint bp = (Breakpoint)(intptr)row.tag;
       if(bp)
       {
          bp.level = level;
@@ -529,9 +609,9 @@ public:
       }
    }
 
-   void ChangeBreakpointCondition(DataRow row, char * condition)
+   void ChangeBreakpointCondition(DataRow row, const char * condition)
    {
-      Breakpoint bp = (Breakpoint)row.tag;
+      Breakpoint bp = (Breakpoint)(intptr)row.tag;
       if(bp && !(!bp.condition && !(condition && condition[0])))
       {
          if(!bp.condition)
@@ -570,11 +650,11 @@ public:
          Window document;
          for(document = ide.firstChild; document; document = document.next)
          {
-            char * fileName = document.fileName;
+            const char * fileName = document.fileName;
             if(document.isDocument && fileName && document.created)
             {
                char winFilePath[MAX_LOCATION];
-               char * slashPath = GetSlashPathBuffer(winFilePath, fileName);
+               const char * slashPath = GetSlashPathBuffer(winFilePath, fileName);
 
                if(!fstrcmp(slashPath, bp.absoluteFilePath))
                {
@@ -591,53 +671,76 @@ public:
       delete bp;
    }
 
-   void DropInvalidBreakpoints()
+   void ParseLoadedBreakpoints()
+   {
+      for(bp : breakpoints; bp.location)
+      {
+         bp.ParseLocation();
+         ide.breakpointsView.UpdateBreakpoint(bp.row);
+      }
+   }
+
+   void DropInvalidBreakpoints(Project removedProject)
    {
       Link bpLink, next;
       for(bpLink = breakpoints.first; bpLink; bpLink = next)
       {
-         Breakpoint bp = (Breakpoint)bpLink.data;
+         Breakpoint bp = (Breakpoint)(intptr)bpLink.data;
          next = bpLink.next;
 
          if(bp.type == user)
          {
-            Project project = null;
-            for(p : projects)
+            if(removedProject)
             {
-               if(FindPath(p.topNode, bp.absoluteFilePath))
-               {
-                  project = p;
-                  break;
-               }
-               // Handle symbol loader modules:
+               if(bp.project == removedProject)
                {
-                  char moduleName[MAX_FILENAME];
-                  char * sl;
-                  GetLastDirectory(bp.absoluteFilePath, moduleName);
-                  // Tweak for automatically resolving symbol loader modules
-                  sl = strstr(moduleName, ".main.ec");
-                  if(sl && (*sl = 0, !strcmpi(moduleName, p.name)))
-                  {
-                     project = p;
-                     break;
-                  }
+                  ide.breakpointsView.RemoveBreakpoint(bp);
+                  RemoveBreakpoint(bp);
                }
             }
-            if(!project)
+            else
             {
-               bool found = false;
-               for(dir : sourceDirs)
+               Project project = bp.project;
+               if(!project)
                {
-                  if(IsPathInsideOf(bp.absoluteFilePath, dir))
+                  for(p : projects)
                   {
-                     found = true;
-                     break;
+                     if(FindPath(p.topNode, bp.absoluteFilePath))
+                     {
+                        project = p;
+                        break;
+                     }
+                     // Handle symbol loader modules:
+                     {
+                        char moduleName[MAX_FILENAME];
+                        char * sl;
+                        GetLastDirectory(bp.absoluteFilePath, moduleName);
+                        // Tweak for automatically resolving symbol loader modules
+                        sl = strstr(moduleName, ".main.ec");
+                        if(sl && (*sl = 0, !strcmpi(moduleName, p.name)))
+                        {
+                           project = p;
+                           break;
+                        }
+                     }
                   }
                }
-               if(!found)
+               if(!project)
                {
-                  ide.breakpointsView.RemoveBreakpoint(bp);
-                  RemoveBreakpoint(bp);
+                  bool found = false;
+                  for(dir : sourceDirs)
+                  {
+                     if(IsPathInsideOf(bp.absoluteFilePath, dir))
+                     {
+                        found = true;
+                        break;
+                     }
+                  }
+                  if(!found)
+                  {
+                     ide.breakpointsView.RemoveBreakpoint(bp);
+                     RemoveBreakpoint(bp);
+                  }
                }
             }
          }
@@ -651,7 +754,7 @@ public:
       delete workspaceDir;
       delete commandLineArgs;
       delete debugDir;
-      
+
       //project = null;
 
       projects.Free();
@@ -669,7 +772,7 @@ public:
       ide.breakpointsView.Clear();
 
       property::debugDir = "";
-      
+
       SetSourceDirs(sourceDirs);
    }
 
@@ -688,7 +791,7 @@ public:
 
 }
 
-Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
+Workspace LoadWorkspace(const char * filePath, const char * fromProjectFile)
 {
    File file;
    Workspace workspace = null;
@@ -697,6 +800,9 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
    if(file)
    {
       OldList openedFilesNotFound { };
+      double version = 0;
+      char section[128];
+      char subSection[128];
 
       workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = filePath };
 
@@ -704,16 +810,11 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
       while(!file.Eof())
       {
          char buffer[65536];
-         char section[128];
-         char subSection[128];
-         //char version[16];
-         float version;
          char * equal;
-         int len;
-         
+
          Watch wh;
-         Breakpoint bp;
-         
+         Breakpoint bp = null;
+
          file.GetLine(buffer, 65536 - 1);
          TrimLSpaces(buffer, buffer);
          TrimRSpaces(buffer, buffer);
@@ -764,7 +865,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                   char * strLevel = null;
                   char * strLine = null;
                   char * strFile = null;
-                  
+
                   strEnabled = equal;
                   if(strEnabled && strEnabled[0])
                   {
@@ -790,7 +891,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                      strFile[0] = '\0';
                      strFile++;
                   }
-                  if(strEnabled && strEnabled[0] && strIgnore && strIgnore[0] && 
+                  if(strEnabled && strEnabled[0] && strIgnore && strIgnore[0] &&
                         strLevel && strLevel[0] && strLine && strLine[0] && strFile && strFile[0])
                   {
                      bool enabled;
@@ -816,10 +917,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
 
                      bp = { type = user, enabled = enabled, ignore = ignore, level = level, line = line };
                      workspace.breakpoints.Add(bp);
-                     bp.relativeFilePath = CopyString(strFile);
-                     bp.absoluteFilePath = workspace.GetAbsolutePathFromRelative(strFile);
-                     if(!bp.absoluteFilePath)
-                        bp.absoluteFilePath = CopyString("");
+                     bp.location = strFile;
                   }
                }
             }
@@ -838,7 +936,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                   Point scroll { };
                   char absolutePath[MAX_LOCATION];
                   strcpy(absolutePath, workspace.workspaceDir);
-                  if(version == 0.01f)
+                  if(version == 0.01)
                   {
                      char * comma = strchr(equal, ',');
                      if(comma)
@@ -848,7 +946,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                         equal = comma + 1;
                      }
                   }
-                  else if(version >= 0.02f)
+                  else if(version >= 0.02)
                   {
                      char * column = strchr(equal, ':');
                      if(column)
@@ -893,7 +991,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                      }
                   }
                   PathCatSlash(absolutePath, equal);
-                     
+
                   if(state == closed || FileExists(absolutePath))
                      workspace.openedFiles.Add(OpenedFileInfo { path = CopyString(absolutePath), state = state, lineNumber = lineNumber, position = position, scroll = scroll });
                   else
@@ -925,7 +1023,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
             }
             else if(!strcmpi(buffer, "ECERE Workspace File"));
             else if(!strcmpi(buffer, "Version 0a"))
-               version = 0.0f;
+               version = 0;
             else if(!strncmp(buffer, "Version ", 8))
                version = atof(&buffer[8]);
             else if(!strcmpi(buffer, "Workspace"))
@@ -968,6 +1066,14 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                            workspace.compiler = equal;
                         delete compiler;
                      }
+                     if(!strcmpi(buffer, "Active Bit Depth"))
+                     {
+                        int bitDepth = atoi(equal);
+                        if(!(bitDepth == 32 || bitDepth == 64))
+                           bitDepth = 0;
+                        workspace.bitDepth = bitDepth;
+                        ide.toolBar.activeBitDepth.SelectRow(ide.toolBar.activeBitDepth.FindRow(bitDepth));
+                     }
                   }
                   else if(!strcmpi(section, "Execution Data"))
                   {
@@ -980,6 +1086,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
 
                      if(!strcmpi(buffer, "Environment Variables"))
                      {
+                        workspace.environmentVars.Free();
                         delete workspace.environmentVars;
                         workspace.environmentVars = { };
                      }
@@ -1068,10 +1175,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                                           bp = { type = user, enabled = enabled, level = -1 };
                                           workspace.breakpoints.Add(bp);
                                           bp.line = atoi(lineNum);
-                                          bp.relativeFilePath = CopyString(relPath);
-                                          bp.absoluteFilePath = workspace.GetAbsolutePathFromRelative(relPath);
-                                          if(!bp.absoluteFilePath)
-                                             bp.absoluteFilePath = CopyString("");
+                                          bp.location = relPath;
                                        }
                                     }
                                  }
@@ -1142,7 +1246,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
             item = openedFilesNotFound.first;
             if(item.next)
                strcpy(s, "s");
-            
+
             for(item = openedFilesNotFound.first; item; item = item.next)
             {
                c++;
@@ -1157,7 +1261,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
 
             sprintf(title, $"File%s not found", s);
             sprintf(msg, $"The following file%s could not be re-opened.%s", s, files);
-            
+
             MessageBox { type = ok, master = ide, contents = msg, text = title }.Modal();
 
             delete files;
@@ -1171,10 +1275,9 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
    else if(fromProjectFile)
    {
       //MessageBox { type = Ok, master = ide, contents = "Worspace load file failed", text = "Worspace Load File Error" }.Modal();
-      
-      char projectFile[MAX_LOCATION];
+      //char projectFile[MAX_LOCATION];
       Project newProject;
-      
+
       //strcpy(projectFile, filePath);
       //ChangeExtension(projectFile, ProjectExtension, projectFile);
       newProject = LoadProject(fromProjectFile /*projectFile*/, null);
@@ -1188,7 +1291,7 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
          workspace.Save();
       }
    }
-   
+
    if(workspace)
    {
       ide.ChangeFileDialogsDirectory(workspace.workspaceDir, false);
@@ -1196,6 +1299,5 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
       if(!workspace.compiler || !workspace.compiler[0])
          workspace.compiler = defaultCompilerName;
    }
-
    return workspace;
 }