ide;debugger; (#1003) fixed multiple issues.
[sdk] / ide / src / project / Workspace.ec
index fa148c4..e2ed155 100644 (file)
@@ -1,8 +1,6 @@
 import "ide"
 
-//bool eString_PathInsideOf(char * path, char * of);
-
-static void ParseListValue(List<String> list, char * equal)
+/*static void ParseListValue(List<String> list, char * equal)
 {
    char * start, * comma;
    char * string;
@@ -21,9 +19,32 @@ static void ParseListValue(List<String> list, char * equal)
       start = comma;
    }
    delete string;
-}
+}*/
 
 enum OpenedFileState { unknown, opened, closed };
+enum ValgrindLeakCheck
+{
+   no, summary, yes, full;
+
+   property char *
+   {
+      get { return OnGetString(null, null, null); }
+   }
+
+   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
 {
@@ -74,6 +95,10 @@ class OpenedFileInfo
          } 
       }
    }
+   ~OpenedFileInfo()
+   {
+      delete path;
+   }
 };
 
 class Workspace
@@ -175,6 +200,15 @@ 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()
@@ -218,6 +252,7 @@ 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)
          {
@@ -246,9 +281,27 @@ public:
          
          file.Printf("\n   Execution Data\n");
          if(commandLineArgs && commandLineArgs[0])
-            file.Printf("\n      Command Line Arguments = %s\n", commandLineArgs);
+         {
+            file.Printf("\n      Command Line Arguments = ");
+            file.Puts(commandLineArgs);
+            file.Printf("\n");
+         }
+
+         if(environmentVars.count)
+         {
+            file.Printf("\n      Environment Variables\n\n");
+            for(v : environmentVars)
+            {
+               file.Printf("       ~ ");
+               file.Puts(v.name);
+               file.Printf(" = ");
+               file.Puts(v.string);
+               file.Printf("\n");
+            }
+         }
 
          file.Printf("\n   Debugger Data\n");
+         // This really belonged in Execution Data...
          if(debugDir && debugDir[0])
             file.Printf("\n      Debug Working Directory = %s\n", debugDir);
          if(sourceDirs.count)
@@ -286,7 +339,7 @@ public:
                char * location;
                char chr[2];
                char relativePath[MAX_LOCATION];
-               if(eString_PathInsideOf(ofi.path, workspaceDir))
+               if(IsPathInsideOf(ofi.path, workspaceDir))
                {
                   MakePathRelative(ofi.path, workspaceDir, relativePath);
                   MakeSlashPath(relativePath);
@@ -310,11 +363,12 @@ public:
       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;
@@ -322,8 +376,7 @@ public:
       }
       if(prj)
       {
-         strcpy(absolute, prj.topNode.path);
-         PathCatSlash(absolute, relative);
+         node.GetFullFilePath(absolute);
          return CopyString(absolute);
       }
 
@@ -361,7 +414,7 @@ public:
 
    char * GetPathWorkspaceRelativeOrAbsolute(char * path)
    {
-      if(eString_PathInsideOf(path, workspaceDir))
+      if(IsPathInsideOf(path, workspaceDir))
       {
          char relativePath[MAX_LOCATION];
          MakePathRelative(path, workspaceDir, relativePath);
@@ -416,7 +469,7 @@ public:
       for(s : dirs)
          sourceDirs.Add(CopyString(s));
       
-      DropInvalidBreakpoints();
+      DropInvalidBreakpoints(null);
 
       delete dirs;
    }
@@ -427,14 +480,40 @@ public:
       if(it.Find(project))
          it.Remove();
 
-      DropInvalidBreakpoints();
+      for(bp : breakpoints)
+      DropInvalidBreakpoints(project);
       modified = true;
       ide.findInFilesDialog.RemoveProjectItem(project);
+      ide.UpdateToolBarActiveConfigs(false);
       Save();
 
       delete project;
    }
 
+   void SelectActiveConfig(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();
+      }
+   }
+
    bool FindPath(ProjectNode node, char * path)
    {
       if(node.type == file)
@@ -464,13 +543,18 @@ public:
       Breakpoint bp = (Breakpoint)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;
       }
@@ -482,7 +566,7 @@ public:
          //  else
          //     ...
          //bp = Breakpoint { };
-         //row.tag = (int)bp;
+         //row.tag = (int64)bp;
          //breakpoints.Add(bp);
          //bp.row = row;
          Save();
@@ -571,7 +655,16 @@ 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)
@@ -581,37 +674,64 @@ public:
 
          if(bp.type == user)
          {
-            Project project = null;
-            for(p : projects)
+            if(removedProject)
             {
-               if(FindPath(p.topNode, bp.absoluteFilePath))
+               if(bp.project == removedProject)
                {
-                  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(eString_PathInsideOf(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);
+                  }
                }
             }
          }
       }
       ide.breakpointsView.Update(null);
    }
-
+   
    void Free()
    {
       delete workspaceFile;
@@ -664,6 +784,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 };
 
@@ -671,10 +794,6 @@ 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;
          
@@ -706,6 +825,18 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                      bp.condition = wh;
                   }
                }
+               else if(!strcmpi(section, "Execution Data") && !strcmpi(subSection, "Environment Variables"))
+               {
+                  String value = strchr(equal, '=');
+                  if(value)
+                  {
+                     *value = 0;
+                     value++;
+                     TrimRSpaces(equal, equal);
+                     TrimLSpaces(value, value);
+                     workspace.environmentVars.Add({ equal, value });
+                  }
+               }
             }
             else if(buffer[0] == '*')
             {
@@ -771,10 +902,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;
                   }
                }
             }
@@ -793,7 +921,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)
@@ -803,7 +931,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)
@@ -860,9 +988,12 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                   Project newProject;
                   strcpy(projectFilePath, workspace.workspaceDir);
                   PathCatSlash(projectFilePath, equal);
-                  newProject = LoadProject(projectFilePath);
+                  newProject = LoadProject(projectFilePath, null);
                   if(newProject)
+                  {
                      workspace.projects.Add(newProject);
+                     newProject.StartMonitoring();
+                  }
                   else if(workspace.projects.count == 0)
                   {
                      delete workspace;
@@ -877,7 +1008,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"))
@@ -894,6 +1025,8 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                strcpy(subSection, buffer);
             else if(!strcmpi(buffer, "Watches"))
                strcpy(subSection, buffer);
+            else if(!strcmpi(buffer, "Environment Variables"))
+               strcpy(subSection, buffer);
             else if(!strcmpi(buffer, "Opened Files"))
                strcpy(section, buffer);
             else if(!strcmpi(buffer, ""))      // | These two lines were commented out
@@ -918,6 +1051,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"))
                   {
@@ -927,6 +1068,14 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                      TrimLSpaces(equal, equal);
                      if(!strcmpi(buffer, "Command Line Arguments"))
                         workspace.commandLineArgs = equal;
+
+                     if(!strcmpi(buffer, "Environment Variables"))
+                     {
+                        workspace.environmentVars.Free();
+                        delete workspace.environmentVars;
+                        workspace.environmentVars = { };
+                     }
+
                   }
                   else if(!strcmpi(section, "Debugger Data"))
                   {
@@ -1011,10 +1160,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;
                                        }
                                     }
                                  }
@@ -1050,22 +1196,23 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
          {
             Project project;
             if(fromProjectFile)
-               project = LoadProject(fromProjectFile /*projectFilePath*/);
+               project = LoadProject(fromProjectFile /*projectFilePath*/, null);
             else
             {
                char projectFilePath[MAX_LOCATION];
                strcpy(projectFilePath, workspace.workspaceFile);
                ChangeExtension(projectFilePath, ProjectExtension, projectFilePath);
-               project = LoadProject(projectFilePath);
+               project = LoadProject(projectFilePath, null);
             }
             if(project)
             {
+               project.StartMonitoring();
                workspace.projects.Add(project);
                workspace.name = CopyString(project.name);
             }
             else
             {
-               MessageBox { type = ok, master = ide, contents = "Workspace load file failed", text = "Workspace Load File Error" }.Modal();
+               MessageBox { type = ok, master = ide, contents = $"Workspace load file failed", text = $"Workspace Load File Error" }.Modal();
                delete workspace;
                return null;
             }
@@ -1075,11 +1222,11 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
          {
             int c = 0;
             char s[2] = "";
-            char files[MAX_LOCATION * 16] = "\n";
+            String files = new char[MAX_LOCATION * 16];
             char title[512];
-            char msg[MAX_LOCATION * 16 + 2048];
-
+            String msg = new char[MAX_LOCATION * 16 + 2048];
             NamedItem item;
+            strcpy(files,"\n");
 
             item = openedFilesNotFound.first;
             if(item.next)
@@ -1097,10 +1244,13 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
                strcat(files, item.name);
             }
 
-            sprintf(title, "File%s not found", s);
-            sprintf(msg, "The following file%s could not be re-opened.%s", s, files);
+            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;
+            delete msg;
          }
          openedFilesNotFound.Free(OldLink::Free);
       }
@@ -1116,10 +1266,11 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
       
       //strcpy(projectFile, filePath);
       //ChangeExtension(projectFile, ProjectExtension, projectFile);
-      newProject = LoadProject(fromProjectFile /*projectFile*/);
+      newProject = LoadProject(fromProjectFile /*projectFile*/, null);
 
       if(newProject)
       {
+         newProject.StartMonitoring();
          workspace = Workspace { workspaceFile = filePath };
 
          workspace.projects.Add(newProject);
@@ -1134,6 +1285,5 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
       if(!workspace.compiler || !workspace.compiler[0])
          workspace.compiler = defaultCompilerName;
    }
-
    return workspace;
 }