buildsystem, epj2make, ide: support Emscripten compiler.
[sdk] / ide / src / project / Workspace.ec
index 12f0242..6f126a0 100644 (file)
@@ -26,12 +26,12 @@ enum ValgrindLeakCheck
 {
    no, summary, yes, full;
 
-   property char *
+   property const char *
    {
       get { return OnGetString(null, null, null); }
    }
 
-   char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+   const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
    {
       if(this >= no && this <= full)
       {
@@ -108,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; }
@@ -143,7 +143,7 @@ public:
       }
    };
 
-   property char * workspaceFile
+   property const char * workspaceFile
    {
       set
       {
@@ -157,7 +157,7 @@ public:
       get { return workspaceFile; }
    }
 
-   property char * projectDir
+   property const char * projectDir
    {
       get
       {
@@ -358,7 +358,7 @@ public:
       }
    }
 
-   char * GetAbsolutePathFromRelative(char * relative)
+   char * CopyAbsolutePathFromRelative(const char * relative)
    {
       char name[MAX_LOCATION];
       char absolute[MAX_LOCATION];
@@ -368,7 +368,7 @@ public:
       GetLastDirectory(relative, name);
       for(p : projects)
       {
-         if(node = p.topNode.Find(name, false))
+         if((node = p.topNode.Find(name, false)))
          {
             prj = p;
             break;
@@ -412,7 +412,7 @@ public:
       return null;
    }
 
-   char * GetPathWorkspaceRelativeOrAbsolute(char * path)
+   char * CopyUnixPathWorkspaceRelativeOrAbsolute(const char * path)
    {
       if(IsPathInsideOf(path, workspaceDir))
       {
@@ -424,7 +424,32 @@ public:
          return CopyUnixPath(path);
    }
 
-   Array<ProjectNode> GetAllProjectNodes(char *fullPath, bool skipExcluded)
+   char * MakeRelativePath(char * buffer, const char * path)
+   {
+      char * result = null;
+      if(buffer && path)
+      {
+         MakePathRelative(path, workspaceDir, buffer);
+         MakeSlashPath(buffer);
+         result = buffer;
+      }
+      return result;
+   }
+
+   char * GetRelativePathForProject(char * buffer, Project project)
+   {
+      char * result = null;
+      if(buffer && project && project.topNode.path)
+      {
+         MakePathRelative(project.topNode.path, workspaceDir, buffer);
+         MakeSlashPath(buffer);
+         PathCatSlash(buffer, project.topNode.name);
+         result = buffer;
+      }
+      return result;
+   }
+
+   Array<ProjectNode> GetAllProjectNodes(const char *fullPath, bool skipExcluded)
    {
       Array<ProjectNode> nodes = null;
       for(project : projects)
@@ -442,7 +467,82 @@ public:
       return nodes;
    }
 
-   OpenedFileInfo UpdateOpenedFileInfo(char * fileName, OpenedFileState state)
+   Project GetFileOwner(const char * absolutePath, const char * objectFileExt)
+   {
+      Project owner = null;
+      for(prj : projects)
+      {
+         if(prj.topNode.FindByFullPath(absolutePath, false))
+         {
+            owner = prj;
+            break;
+         }
+      }
+      if(!owner)
+         GetObjectFileNode(absolutePath, &owner, null, objectFileExt);
+      return owner;
+   }
+
+   void GetRelativePath(const char * absolutePath, char * relativePath, Project * owner, const char * objectFileExt)
+   {
+      Project prj = GetFileOwner(absolutePath, objectFileExt);
+      if(owner)
+         *owner = prj;
+      if(!prj)
+         prj = projects.firstIterator.data;
+      if(prj)
+      {
+         MakePathRelative(absolutePath, prj.topNode.path, relativePath);
+         MakeSlashPath(relativePath);
+      }
+      else
+         relativePath[0] = '\0';
+   }
+
+   ProjectNode GetObjectFileNode(const char * filePath, Project * project, char * fullPath, const char * objectFileExt)
+   {
+      ProjectNode node = null;
+      char ext[MAX_EXTENSION];
+      GetExtension(filePath, ext);
+      if(ext[0])
+      {
+         IntermediateFileType type = IntermediateFileType::FromExtension(ext);
+         if(type)
+         {
+            char fileName[MAX_FILENAME];
+            GetLastDirectory(filePath, fileName);
+            if(fileName[0])
+            {
+               DotMain dotMain = DotMain::FromFileName(fileName);
+               for(prj : ide.workspace.projects)
+               {
+                  if((node = prj.FindNodeByObjectFileName(fileName, type, dotMain, null, objectFileExt)))
+                  {
+                     if(project)
+                        *project = prj;
+                     if(fullPath)
+                     {
+                        const char * cfgName = prj.config ? prj.config.name : "";
+                        char name[MAX_FILENAME];
+                        CompilerConfig compiler = ideSettings.GetCompilerConfig(prj.lastBuildCompilerName);
+                        DirExpression objDir = prj.GetObjDir(compiler, prj.config, bitDepth);
+                        strcpy(fullPath, prj.topNode.path);
+                        PathCatSlash(fullPath, objDir.dir);
+                        node.GetObjectFileName(name, prj.configsNameCollisions[cfgName], type, dotMain, objectFileExt);
+                        PathCatSlash(fullPath, name);
+                        delete objDir;
+                        delete compiler;
+                     }
+                     break;
+                  }
+               }
+            }
+         }
+      }
+      return node;
+   }
+
+   OpenedFileInfo UpdateOpenedFileInfo(const char * fileName, OpenedFileState state)
    {
       char filePath[MAX_LOCATION];
       OpenedFileInfo ofi = null;
@@ -479,9 +579,6 @@ public:
 
    void UpdateSourceDirsArray(Array<String> dirs)
    {
-      byte * tokens[256];
-      int c, numTokens;
-
       sourceDirs.Free();
 
       for(s : dirs)
@@ -508,7 +605,7 @@ public:
       delete project;
    }
 
-   void SelectActiveConfig(char * configName)
+   void SelectActiveConfig(const char * configName)
    {
       bool change = false;
       for(prj : ide.workspace.projects)
@@ -530,9 +627,10 @@ public:
          ide.projectView.Update(null);
          Save();
       }
+      ide.AdjustDebugMenus();
    }
 
-   bool FindPath(ProjectNode node, char * path)
+   bool FindPath(ProjectNode node, const char * path)
    {
       if(node.type == file)
       {
@@ -556,9 +654,9 @@ 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.CopyUserLocationString();
@@ -593,7 +691,7 @@ public:
 
    void ChangeBreakpointIgnore(DataRow row, int ignore)
    {
-      Breakpoint bp = (Breakpoint)row.tag;
+      Breakpoint bp = (Breakpoint)(intptr)row.tag;
       if(bp)
       {
          bp.ignore = ignore;
@@ -603,7 +701,7 @@ public:
 
    void ChangeBreakpointLevel(DataRow row, int level)
    {
-      Breakpoint bp = (Breakpoint)row.tag;
+      Breakpoint bp = (Breakpoint)(intptr)row.tag;
       if(bp)
       {
          bp.level = level;
@@ -611,9 +709,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)
@@ -652,11 +750,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))
                {
@@ -687,7 +785,7 @@ public:
       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)
@@ -793,7 +891,7 @@ public:
 
 }
 
-Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
+Workspace LoadWorkspace(const char * filePath, const char * fromProjectFile)
 {
    File file;
    Workspace workspace = null;
@@ -813,10 +911,9 @@ Workspace LoadWorkspace(char * filePath, char * fromProjectFile)
       {
          char buffer[65536];
          char * equal;
-         int len;
 
          Watch wh;
-         Breakpoint bp;
+         Breakpoint bp = null;
 
          file.GetLine(buffer, 65536 - 1);
          TrimLSpaces(buffer, buffer);
@@ -1278,8 +1375,7 @@ 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);