Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[photran-dev] CDT-Photran integration patch

I attached a patch to Bugzilla 115935 which is basically equivalent to what I proposed at the CDT Developers' Summit last fall. Some identifiers have changed--it extends Doug's ILanguage and LanguageManager now--but is otherwise the same.

Essentially, this allows us to supply our own model builder and have its elements show up in the Outline and Make Projects views.

Photran's corresponding ILanguage will just return null for all of the getTranslationUnit methods in ILanguage; so far that doesn't seem to be a problem. Maybe later we'll have time to *actually* integrate those kinds of things...

Looking forward to discussing this and hopefully getting it integrated in the near future. Sorry for taking so long to get around to this.

(For the photran-dev post, I attached a patch with the corresponding changes to Photran.)

Jeff
### Eclipse Workspace Patch 1.0
#P org.eclipse.photran.refactoring
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.refactoring/META-INF/MANIFEST.MF,v
retrieving revision 1.8
diff -u -r1.8 MANIFEST.MF
--- META-INF/MANIFEST.MF	9 Mar 2006 08:21:56 -0000	1.8
+++ META-INF/MANIFEST.MF	10 Mar 2006 07:24:29 -0000
@@ -26,5 +26,4 @@
  org.eclipse.photran.internal.core.refactoring,
  org.eclipse.photran.internal.core.refactoring.preconditions,
  org.eclipse.photran.internal.core.util,
- org.eclipse.photran.refactoring,
  org.eclipse.photran.refactoring.ui
#P org.eclipse.photran.core
Index: model/org/eclipse/photran/internal/core/model/FortranElementInfo.java
===================================================================
RCS file: model/org/eclipse/photran/internal/core/model/FortranElementInfo.java
diff -N model/org/eclipse/photran/internal/core/model/FortranElementInfo.java
--- model/org/eclipse/photran/internal/core/model/FortranElementInfo.java	29 Sep 2005 19:04:55 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,169 +0,0 @@
-package org.eclipse.photran.internal.core.model;
-
-import org.eclipse.cdt.core.model.CModelException;
-import org.eclipse.cdt.core.model.IBuffer;
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.IMember;
-import org.eclipse.cdt.core.model.ISourceRange;
-import org.eclipse.cdt.core.model.ISourceReference;
-import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.internal.core.model.CElement;
-import org.eclipse.cdt.internal.core.model.CElementInfo;
-import org.eclipse.cdt.internal.core.model.SourceRange;
-
-/**
- * Our own version of <code>CElementInfo</code>, which is basically identical to
- * <code>SourceManipulationInfo</code> except that we don't support
- * <code>SourceManipulation</code>
- * 
- * @see CElementInfo
- * 
- * @author joverbey
- */
-public class FortranElementInfo extends CElementInfo
-{
-    // --------------------------------------------------------------------
-    // Methods copied from SourceManipulationInfo
-    // --------------------------------------------------------------------
-
-    protected int fStartPos;
-
-    protected int fLength;
-
-    protected int fIdStartPos;
-
-    protected int fIdLength;
-
-    protected int fStartLine;
-
-    protected int fEndLine;
-
-    int modifiers;
-
-    public FortranElementInfo(CElement element)
-    {
-        super(element);
-        setIsStructureKnown(true);
-        modifiers = 0;
-    }
-
-    public void setPos(int startPos, int length)
-    {
-        fStartPos = startPos;
-        fLength = length;
-    }
-
-    public int getStartPos()
-    {
-        return fStartPos;
-    }
-
-    public int getLength()
-    {
-        return fLength;
-    }
-
-    public void setIdPos(int startPos, int length)
-    {
-        fIdStartPos = startPos;
-        fIdLength = length;
-    }
-
-    public int getIdStartPos()
-    {
-        return fIdStartPos;
-    }
-
-    public int getIdLength()
-    {
-        return fIdLength;
-    }
-
-    public int getStartLine()
-    {
-        return fStartLine;
-    }
-
-    public int getEndLine()
-    {
-        return fEndLine;
-    }
-
-    public void setLines(int startLine, int endLine)
-    {
-        fStartLine = startLine;
-        fEndLine = endLine;
-    }
-
-    public ISourceRange getSourceRange()
-    {
-        return new SourceRange(fStartPos, fLength, fIdStartPos, fIdLength, fStartLine, fEndLine);
-    }
-
-    /**
-     * @see ISourceReference
-     */
-    public String getSource() throws CModelException
-    {
-        ITranslationUnit unit = getTranslationUnit();
-        IBuffer buffer = unit.getBuffer();
-        if (buffer == null) { return null; }
-        int offset = fStartPos;
-        int length = fLength;
-        if (offset == -1 || length == 0) { return null; }
-        try
-        {
-            return buffer.getText(offset, length);
-        }
-        catch (RuntimeException e)
-        {
-            return null;
-        }
-
-//		ITranslationUnit tu = getTranslationUnit();
-//		if (tu != null) {
-//			try {
-//				IResource res = tu.getResource();
-//				if (res != null && res instanceof IFile) {
-//					StringBuffer buffer = Util.getContent((IFile)res);
-//					return  buffer.substring(getElement().getStartPos(),
-//							getElement().getStartPos() + getElement().getLength());
-//				}
-//			} catch (IOException e) {
-//				throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION);
-//			} catch (StringIndexOutOfBoundsException bound) {
-//				// This is not good we screwed up the offset some how
-//				throw new CModelException(bound, ICModelStatusConstants.INDEX_OUT_OF_BOUNDS);
-//			}
-//		}
-//		return ""; //$NON-NLS-1$
-	}
-
-	/**
-     * @see IMember
-     */
-    public ITranslationUnit getTranslationUnit()
-    {
-        ICElement celem = getElement();
-        for (; celem != null; celem = celem.getParent())
-        {
-            if (celem instanceof ITranslationUnit) return (ITranslationUnit)celem;
-        }
-        return null;
-    }
-	
-//	/**
-//	 * return the element modifiers
-//	 * @return int
-//	 */
-//	public int getModifiers(){
-//		return modifiers;
-//	}
-//	
-//	/**
-//	 *  subclasses  should override
-//	 */
-//	public boolean hasSameContentsAs( FortranElementInfo otherInfo){
-//		return (this.element.fType == otherInfo.element.fType);
-//	}
-}
Index: model/org/eclipse/photran/internal/core/model/FortranModelBuilder.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.core/model/org/eclipse/photran/internal/core/model/FortranModelBuilder.java,v
retrieving revision 1.5
diff -u -r1.5 FortranModelBuilder.java
--- model/org/eclipse/photran/internal/core/model/FortranModelBuilder.java	25 Jan 2006 21:57:26 -0000	1.5
+++ model/org/eclipse/photran/internal/core/model/FortranModelBuilder.java	10 Mar 2006 07:24:33 -0000
@@ -6,9 +6,9 @@
 import java.util.Iterator;
 import java.util.Map;
 
-import org.eclipse.cdt.core.addl_langs.IModelBuilder;
 import org.eclipse.cdt.core.model.CModelException;
 import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.addl_langs.IContributedModelBuilder;
 import org.eclipse.cdt.internal.core.model.Parent;
 import org.eclipse.photran.core.FortranCorePlugin;
 import org.eclipse.photran.internal.core.f95modelparser.FortranProcessor;
@@ -27,11 +27,11 @@
  * filename extension and the user's workspace preferences).
  * 
  * All CDT extension languages are expected to supply a model builder.
- * @see IModelBuilder
+ * @see IContributedModelBuilder
  * 
  * @author joverbey
  */
-public final class FortranModelBuilder implements IModelBuilder
+public final class FortranModelBuilder implements IContributedModelBuilder
 {
     private org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
 
@@ -50,71 +50,7 @@
         this.newElements = new HashMap();
     }
 
-//    public Map parse(boolean quickParseMode) throws Exception
-//    {
-//        String input = translationUnit.getBuffer().getContents();
-//        InputStream inputStream = new ByteArrayInputStream(input.getBytes());
-//        String filename = translationUnit.getFile().getName();
-//        boolean wasSuccessful = true;
-//
-//        try
-//        {
-//            FortranProcessor processor = new FortranProcessor();
-//
-//            ParseTreeNode parseTree;
-//            if (formatAssociations.containsKey(filename))
-//                parseTree = processor.parse(inputStream, filename, ((Boolean)formatAssociations.get(filename)).booleanValue());
-//            else
-//                parseTree = processor.parse(inputStream, filename);
-//
-//            FortranElement note = new FortranElement.UnknownNode(translationUnit, processor
-//                .lastParseWasFixedForm() ? "<Fixed Form Source>" : "<Free Form Source>");
-//            this.addF90Element(note);
-//
-//            // Build a model (for our purposes, it's just to populate the Outline view)
-//            if (isParseTreeModelEnabled())
-//            {
-//                // Show full parse tree rather than Outline view
-//                parseTree.visitUsing(new FortranParseTreeModelBuildingVisitor(translationUnit, this));
-//            }
-//            else
-//            {
-//                // Show normal Outline view
-//                parseTree.visitUsing(new FortranModelBuildingVisitor(translationUnit, this));
-//            }
-//
-//            // If parser debugging is enabled, try creating a symbol table
-//            if (FortranProcessor.isParserDebuggingEnabled())
-//            {
-//                try
-//                {
-//                    // processor.createSymbolTableFromParseTree(parseTree);
-//                }
-//                catch (SemanticError e)
-//                {
-//                    createSemanticFailureNode(translationUnit, e);
-//                    wasSuccessful = false;
-//                }
-//            }
-//        }
-//        catch (SyntaxError e)
-//        {
-//            createParseFailureNode(translationUnit, e.getErrorToken());
-//            wasSuccessful = false;
-//        }
-//        catch (Exception e)
-//        {
-//            createParseFailureNode(translationUnit, e.getMessage());
-//            wasSuccessful = false;
-//        }
-//
-//        // From CDT: important to know if the unit has parse errors or not
-//        translationUnit.getElementInfo().setIsStructureKnown(wasSuccessful);
-//
-//        return this.newElements;
-//    }
-
-    public Map parse(boolean quickParseMode) throws Exception
+    public void parse(boolean quickParseMode) throws Exception
     {
         String input = translationUnit.getBuffer().getContents();
         InputStream inputStream = new ByteArrayInputStream(input.getBytes());
@@ -152,9 +88,7 @@
         }
 
         // From CDT: important to know if the unit has parse errors or not
-        translationUnit.getElementInfo().setIsStructureKnown(wasSuccessful);
-
-        return this.newElements;
+        translationUnit.setIsStructureKnown(wasSuccessful);
     }
 
     private boolean isParseTreeModelEnabled()
Index: model/org/eclipse/photran/internal/core/model/FortranElement.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.core/model/org/eclipse/photran/internal/core/model/FortranElement.java,v
retrieving revision 1.4
diff -u -r1.4 FortranElement.java
--- model/org/eclipse/photran/internal/core/model/FortranElement.java	25 Jan 2006 21:57:26 -0000	1.4
+++ model/org/eclipse/photran/internal/core/model/FortranElement.java	10 Mar 2006 07:24:33 -0000
@@ -1,9 +1,9 @@
 package org.eclipse.photran.internal.core.model;
 
-import org.eclipse.cdt.core.addl_langs.IAdditionalLanguageElement;
 import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.cdt.core.model.IParent;
 import org.eclipse.cdt.core.model.ISourceReference;
+import org.eclipse.cdt.core.model.addl_langs.IContributedCElement;
 import org.eclipse.cdt.internal.core.model.Parent;
 import org.eclipse.cdt.internal.core.model.SourceManipulation;
 import org.eclipse.photran.internal.core.f95modelparser.Token;
@@ -43,7 +43,7 @@
  * @see FortranElementInfo
  */
 public abstract class FortranElement extends SourceManipulation // Parent
-    implements ICElement, IParent, ISourceReference, IAdditionalLanguageElement
+    implements ICElement, IParent, ISourceReference, IContributedCElement
 {
     /**
      * Most elements in the <code>FortranElement</code> hierarchy have a name (functions,
Index: src/org/eclipse/photran/core/FortranLanguage.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.core/src/org/eclipse/photran/core/FortranLanguage.java,v
retrieving revision 1.2
diff -u -r1.2 FortranLanguage.java
--- src/org/eclipse/photran/core/FortranLanguage.java	11 Nov 2005 20:47:20 -0000	1.2
+++ src/org/eclipse/photran/core/FortranLanguage.java	10 Mar 2006 07:24:33 -0000
@@ -2,11 +2,16 @@
 
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Map;
 
-import org.eclipse.cdt.core.addl_langs.IAdditionalLanguage;
-import org.eclipse.cdt.core.addl_langs.IModelBuilder;
+import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.core.model.addl_langs.IContributedModelBuilder;
 import org.eclipse.cdt.internal.core.model.TranslationUnit;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IStorage;
 import org.eclipse.photran.internal.core.model.FortranModelBuilder;
 
 /**
@@ -14,21 +19,54 @@
  * 
  * @author joverbey
  */
-public class FortranLanguage implements IAdditionalLanguage
+public class FortranLanguage implements ILanguage
 {
-    public String getName()
-    {
-        return "Fortran";
-    }
-
+//    public String getName()
+//    {
+//        return "Fortran";
+//    }
+//
     public Collection getRegisteredContentTypeIds()
     {
         return Arrays.asList(new String[]{FortranCorePlugin.FIXED_FORM_CONTENT_TYPE, FortranCorePlugin.FREE_FORM_CONTENT_TYPE});
     }
+//
+//    public IModelBuilder createModelBuilder(TranslationUnit tu, Map newElements)
+//    {
+//        return new FortranModelBuilder(tu);
+//    }
 
-    public IModelBuilder createModelBuilder(TranslationUnit tu, Map newElements)
-    {
-        return new FortranModelBuilder(tu);
-    }
+	public String getId()
+	{
+		return FortranCorePlugin.LANGUAGE_ID;
+	}
+
+	public IASTTranslationUnit getTranslationUnit(IFile file, int style)
+	{
+		return null;
+	}
+
+	public IASTTranslationUnit getTranslationUnit(IStorage file, IProject project, int style)
+	{
+		return null;
+	}
+
+	public IASTTranslationUnit getTranslationUnit(IWorkingCopy workingCopy, int style)
+	{
+		return null;
+	}
+
+	public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset)
+	{
+		return null;
+	}
+
+	public Object getAdapter(Class adapter)
+	{
+		return null;
+	}
 
+	public IContributedModelBuilder createModelBuilder(TranslationUnit tu) {
+		return new FortranModelBuilder(tu);
+	}
 }
Index: src/org/eclipse/photran/core/FortranCorePlugin.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.core/src/org/eclipse/photran/core/FortranCorePlugin.java,v
retrieving revision 1.2
diff -u -r1.2 FortranCorePlugin.java
--- src/org/eclipse/photran/core/FortranCorePlugin.java	11 Nov 2005 20:47:20 -0000	1.2
+++ src/org/eclipse/photran/core/FortranCorePlugin.java	10 Mar 2006 07:24:33 -0000
@@ -10,6 +10,8 @@
  */
 public class FortranCorePlugin extends Plugin
 {
+    public static final String LANGUAGE_ID = "org.eclipse.photran.core.fortran";
+    
     public static final String FIXED_FORM_CONTENT_TYPE = "org.eclipse.photran.core.fixedFormFortranSource";
     public static final String FREE_FORM_CONTENT_TYPE = "org.eclipse.photran.core.freeFormFortranSource";
     
Index: plugin.xml
===================================================================
RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.core/plugin.xml,v
retrieving revision 1.6
diff -u -r1.6 plugin.xml
--- plugin.xml	8 Mar 2006 09:39:40 -0000	1.6
+++ plugin.xml	10 Mar 2006 07:24:33 -0000
@@ -188,9 +188,19 @@
   </extension>
 
    <!-- JO -->
-   <extension point="org.eclipse.cdt.core.AdditionalLanguages">
+   <!--extension point="org.eclipse.cdt.core.AdditionalLanguages">
       <language
          class="org.eclipse.photran.core.FortranLanguage" />
+   </extension-->
+   <extension
+         point="org.eclipse.cdt.core.language">
+      <language
+            class="org.eclipse.photran.core.FortranLanguage"
+            id="fortran"
+            name="Fortran">
+         <contentType id="org.eclipse.photran.core.fixedFormFortranSource"/>
+         <contentType id="org.eclipse.photran.core.freeFormFortranSource"/>
+      </language>
    </extension>
 
 <!-- =================================================================================== -->
#P org.eclipse.photran.managedbuilder.core
Index: src/org/eclipse/photran/managedbuilder/core/makegen/DefaultFortranDependencyCalculator.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.managedbuilder.core/src/org/eclipse/photran/managedbuilder/core/makegen/DefaultFortranDependencyCalculator.java,v
retrieving revision 1.1
diff -u -r1.1 DefaultFortranDependencyCalculator.java
--- src/org/eclipse/photran/managedbuilder/core/makegen/DefaultFortranDependencyCalculator.java	27 Oct 2005 18:50:12 -0000	1.1
+++ src/org/eclipse/photran/managedbuilder/core/makegen/DefaultFortranDependencyCalculator.java	10 Mar 2006 07:24:35 -0000
@@ -10,25 +10,30 @@
  *******************************************************************************/
 package org.eclipse.photran.managedbuilder.core.makegen;
 
-import java.io.*;
-import java.lang.String;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StreamTokenizer;
 import java.util.ArrayList;
 import java.util.Collection;
 
 import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
 import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
 import org.eclipse.cdt.managedbuilder.core.IManagedOutputNameProvider;
-import org.eclipse.cdt.managedbuilder.core.IConfiguration;
 import org.eclipse.cdt.managedbuilder.core.ITool;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
 import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator;
-import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.content.IContentType;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
-
+import org.eclipse.core.runtime.content.IContentType;
 import org.eclipse.photran.core.FortranLanguage;
 
 // import org.eclipse.photran.internal.core.f95parser.FortranProcessor;

Back to the top