View | Details | Raw Unified | Return to bug 373597
Collapse All | Expand All

(-)tools/pldt/org.eclipse.ptp.pldt.common/src/org/eclipse/ptp/pldt/common/ArtifactAnalysisBase.java (+49 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011, 2012 IBM Corporation, University of Illinois, and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Jeff Overbey (UIUC) - modified to use extension point
11
 *******************************************************************************/
12
package org.eclipse.ptp.pldt.common;
13
14
import org.eclipse.cdt.core.CCorePlugin;
15
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
16
import org.eclipse.cdt.core.index.IIndex;
17
import org.eclipse.cdt.core.model.ITranslationUnit;
18
import org.eclipse.core.runtime.IStatus;
19
20
/**
21
 * Base class for implementations of {@link IArtifactAnalysis} that handle C and
22
 * C++.
23
 * <p>
24
 * This class contains the {@link #getAST(ITranslationUnit)} utility method,
25
 * which returns an {@link IASTTranslationUnit} for an {@link ITranslationUnit}.
26
 * 
27
 * @author Beth Tibbitts
28
 * @author Jeff Overbey
29
 * 
30
 * @since 6.0
31
 */
32
public abstract class ArtifactAnalysisBase implements IArtifactAnalysis {
33
	/**
34
	 * Get AST from index, not full tu
35
	 * 
36
	 * @param tu
37
	 *            translation unit from which to get the AST
38
	 * @return {@link IASTTranslationUnit} or <code>null</code>
39
	 */
40
	protected IASTTranslationUnit getAST(ITranslationUnit tu) {
41
		try {
42
			IIndex index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
43
			return tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
44
		} catch (Exception e) {
45
			CommonPlugin.log(IStatus.ERROR, "RunAnalyseHandlerBase.getAST(): Error getting AST (from index) for project " + tu.getCProject() + " " + e.getMessage()); //$NON-NLS-1$
46
			return null;
47
		}
48
	}
49
}
(-)tools/pldt/org.eclipse.ptp.pldt.common/src/org/eclipse/ptp/pldt/common/IArtifactAnalysis.java (+25 lines)
Added Link Here
1
package org.eclipse.ptp.pldt.common;
2
3
import java.util.List;
4
5
import org.eclipse.cdt.core.model.ITranslationUnit;
6
7
/**
8
 * An artifact analysis for MPI, OpenMP, or OpenACC.
9
 * <p>
10
 * This interface is implemented by contributions to the following extension points:
11
 * <ul>
12
 * <li> org.eclipse.ptp.pldt.mpi.core.artifactAnalysis
13
 * <li> org.eclipse.ptp.pldt.openmp.core.artifactAnalysis
14
 * <li> org.eclipse.ptp.pldt.openacc.artifactAnalysis
15
 * </ul>
16
 * <p>
17
 * Implementations targeting C and C++ will typically subclass {@link ArtifactAnalysisBase}.
18
 * 
19
 * @since 6.0
20
 * 
21
 * @see ArtifactAnalysisBase
22
 */
23
public interface IArtifactAnalysis {
24
	ScanReturn runArtifactAnalysis(String languageID, ITranslationUnit tu, List<String> includes, boolean allowPrefixOnlyMatch);
25
}
(-)tools/pldt/org.eclipse.ptp.pldt.common/src/org/eclipse/ptp/pldt/common/actions/RunAnalyseHandlerBase.java (-31 / +41 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2011 IBM Corporation.
2
 * Copyright (c) 2005, 2011, 2012 IBM Corporation, University of Illinois, and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-23 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Jeff Overbey (UIUC) - modified to use extension point
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
package org.eclipse.ptp.pldt.common.actions;
12
package org.eclipse.ptp.pldt.common.actions;
13
13
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.Iterator;
15
import java.util.Iterator;
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.cdt.core.CCorePlugin;
19
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
20
import org.eclipse.cdt.core.index.IIndex;
21
import org.eclipse.cdt.core.model.ICContainer;
18
import org.eclipse.cdt.core.model.ICContainer;
22
import org.eclipse.cdt.core.model.ICElement;
19
import org.eclipse.cdt.core.model.ICElement;
23
import org.eclipse.cdt.core.model.ICProject;
20
import org.eclipse.cdt.core.model.ICProject;
Lines 31-38 import org.eclipse.core.resources.IProjectNature; Link Here
31
import org.eclipse.core.resources.IResource;
28
import org.eclipse.core.resources.IResource;
32
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.IAdaptable;
30
import org.eclipse.core.runtime.IAdaptable;
31
import org.eclipse.core.runtime.IConfigurationElement;
34
import org.eclipse.core.runtime.IProgressMonitor;
32
import org.eclipse.core.runtime.IProgressMonitor;
35
import org.eclipse.core.runtime.IStatus;
33
import org.eclipse.core.runtime.IStatus;
34
import org.eclipse.core.runtime.Platform;
36
import org.eclipse.core.runtime.Preferences;
35
import org.eclipse.core.runtime.Preferences;
37
import org.eclipse.jface.action.IAction;
36
import org.eclipse.jface.action.IAction;
38
import org.eclipse.jface.dialogs.MessageDialog;
37
import org.eclipse.jface.dialogs.MessageDialog;
Lines 43-48 import org.eclipse.jface.viewers.IStructuredSelection; Link Here
43
import org.eclipse.ptp.pldt.common.Artifact;
42
import org.eclipse.ptp.pldt.common.Artifact;
44
import org.eclipse.ptp.pldt.common.ArtifactMarkingVisitor;
43
import org.eclipse.ptp.pldt.common.ArtifactMarkingVisitor;
45
import org.eclipse.ptp.pldt.common.CommonPlugin;
44
import org.eclipse.ptp.pldt.common.CommonPlugin;
45
import org.eclipse.ptp.pldt.common.IArtifactAnalysis;
46
import org.eclipse.ptp.pldt.common.ScanReturn;
46
import org.eclipse.ptp.pldt.common.ScanReturn;
47
import org.eclipse.ptp.pldt.common.messages.Messages;
47
import org.eclipse.ptp.pldt.common.messages.Messages;
48
import org.eclipse.ptp.pldt.common.util.AnalysisUtil;
48
import org.eclipse.ptp.pldt.common.util.AnalysisUtil;
Lines 62-67 import org.eclipse.ui.actions.WorkspaceModifyOperation; Link Here
62
 * The analysis is done in the doArtifactAnalysis() method
62
 * The analysis is done in the doArtifactAnalysis() method
63
 * 
63
 * 
64
 * @author Beth Tibbitts
64
 * @author Beth Tibbitts
65
 * @author Jeff Overbey
65
 * 
66
 * 
66
 *         IObjectActionDelegate enables popup menu selection <br>
67
 *         IObjectActionDelegate enables popup menu selection <br>
67
 *         IWindowActionDelegate enables toolbar(or menu) selection
68
 *         IWindowActionDelegate enables toolbar(or menu) selection
Lines 220-225 public abstract class RunAnalyseHandlerBase extends RunAnalyseHandler { Link Here
220
	public abstract ScanReturn doArtifactAnalysis(final ITranslationUnit tu, final List<String> includes);
221
	public abstract ScanReturn doArtifactAnalysis(final ITranslationUnit tu, final List<String> includes);
221
222
222
	/**
223
	/**
224
	 * Runs an artifact analysis for the given file by searching the given extension point for an {@link IArtifactAnalysis} that matches its language ID.
225
	 * <p>
226
	 * This is a utility method generally invoked from {@link #doArtifactAnalysis(ITranslationUnit, List)}.
227
	 * <p>
228
	 * It is assumed that only one extension will be contributed per language ID.  If multiple extensions are found, it is unspecified which one will be run.
229
	 * 
230
	 * @param extensionPointID
231
	 * @param tu
232
	 * @param includes
233
	 * @param allowPrefixOnlyMatch
234
	 * @return {@link ScanReturn}
235
	 * 
236
	 * @since 6.0
237
	 */
238
	protected ScanReturn runArtifactAnalysisFromExtensionPoint(String extensionPointID, final ITranslationUnit tu, final List<String> includes, final boolean allowPrefixOnlyMatch) {
239
		try {
240
			final String languageID = tu.getLanguage().getId();
241
			for (IConfigurationElement config : Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointID)) {
242
				try {
243
					if (languageID.equals(config.getAttribute("languageID"))) {
244
						IArtifactAnalysis artifactAnalysis = (IArtifactAnalysis) config.createExecutableExtension("class"); //$NON-NLS-1$
245
						return artifactAnalysis.runArtifactAnalysis(languageID, tu, includes, allowPrefixOnlyMatch);
246
					}
247
				} catch (CoreException e) {
248
					CommonPlugin.log(e.getClass().getSimpleName() + ": " + e.getMessage());
249
				}
250
			}
251
		} catch (CoreException e) {
252
			e.printStackTrace();
253
			CommonPlugin.log(IStatus.ERROR, "RunAnalyseMPICommandHandler: Error setting up analysis for project " + tu.getCProject() + " error=" + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
254
		}
255
		return new ScanReturn();
256
	}
257
258
	/**
223
	 * Implemented for Handler; this replaces run() which is for actions.
259
	 * Implemented for Handler; this replaces run() which is for actions.
224
	 */
260
	 */
225
	public Object execute(ExecutionEvent event) throws ExecutionException {
261
	public Object execute(ExecutionEvent event) throws ExecutionException {
Lines 515-546 public abstract class RunAnalyseHandlerBase extends RunAnalyseHandler { Link Here
515
	}
551
	}
516
552
517
	/**
553
	/**
518
	 * Get AST from index, not full tu
519
	 * 
520
	 * @param tu
521
	 *            translation unit from which to get the AST
522
	 * @return
523
	 */
524
	protected IASTTranslationUnit getAST(ITranslationUnit tu) {
525
		IIndex index;
526
		try {
527
			index = CCorePlugin.getIndexManager().getIndex(tu.getCProject());
528
			IASTTranslationUnit ast = tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
529
			// IASTTranslationUnit ast = tu.getAST(index, 0);
530
			if (traceOn) {
531
				System.out.println("    getAST(index,AST_SKIP_ALL_HEADERS)"); //$NON-NLS-1$
532
			}
533
534
			return ast;
535
		} catch (Exception e) {
536
			String msg = "RunAnalyseHandlerBase.getAST(): Error getting AST (from index) for project " + tu.getCProject() + " " + e.getMessage();//$NON-NLS-1$
537
			CommonPlugin.log(IStatus.ERROR, msg);
538
			return null;
539
		}
540
541
	}
542
543
	/**
544
	 * Get the include path. Subclass should override this method.
554
	 * Get the include path. Subclass should override this method.
545
	 * 
555
	 * 
546
	 * @return
556
	 * @return
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.core/build.properties (-1 / +2 lines)
Lines 7-13 bin.includes = plugin.xml,\ Link Here
7
               .,\
7
               .,\
8
               templates/,\
8
               templates/,\
9
               plugin.properties,\
9
               plugin.properties,\
10
               about.html
10
               about.html,\
11
               schema/
11
src.includes = html/,\
12
src.includes = html/,\
12
               icons/,\
13
               icons/,\
13
               mpiref.xml,\
14
               mpiref.xml,\
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.core/plugin.xml (-2 / +17 lines)
Lines 119-128 Link Here
119
        
119
        
120
      </menuContribution>
120
      </menuContribution>
121
   </extension>
121
   </extension>
122
     <!-- Code templates -->
122
123
   <!-- Code templates -->
123
   <extension point="org.eclipse.ui.editors.templates">
124
   <extension point="org.eclipse.ui.editors.templates">
124
   <include file="templates/mpi_templates.xml" />
125
     <include file="templates/mpi_templates.xml" />
126
   </extension>
125
127
128
   <!-- Artifact analysis extension point -->
129
   <extension-point
130
      id="artifactAnalysis"
131
      name="MPI Artifact Analysis"
132
      schema="schema/artifactAnalysis.exsd"/>
133
   <!-- Artifact analyses for C and C++ -->
134
   <extension point="org.eclipse.ptp.pldt.mpi.core.artifactAnalysis">
135
      <artifactAnalysis
136
            languageID="org.eclipse.cdt.core.gcc"
137
            class="org.eclipse.ptp.pldt.mpi.core.analysis.CMPIArtifactAnalysis" />
138
      <artifactAnalysis
139
            languageID="org.eclipse.cdt.core.g++"
140
            class="org.eclipse.ptp.pldt.mpi.core.analysis.CMPIArtifactAnalysis" />
126
   </extension>
141
   </extension>
127
142
128
</plugin>
143
</plugin>
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.core/schema/artifactAnalysis.exsd (+88 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.ptp.pldt.mpi.core" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.ptp.pldt.mpi.core" id="artifactAnalysis" name="MPI Artifact Analysis"/>
7
      </appInfo>
8
      <documentation>
9
         Allows plug-ins to contribute MPI artifact analyses.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <sequence minOccurs="1" maxOccurs="unbounded">
21
            <element ref="artifactAnalysis"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appInfo>
43
                  <meta.attribute translatable="true"/>
44
               </appInfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="artifactAnalysis">
51
      <complexType>
52
         <attribute name="languageID" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appInfo>
58
                  <meta.attribute kind="identifier" basedOn="org.eclipse.cdt.core.language/language/@id"/>
59
               </appInfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="class" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  
66
               </documentation>
67
               <appInfo>
68
                  <meta.attribute kind="java" basedOn=":org.eclipse.ptp.pldt.common.IArtifactAnalysis"/>
69
               </appInfo>
70
            </annotation>
71
         </attribute>
72
      </complexType>
73
   </element>
74
75
   <annotation>
76
      <appInfo>
77
         <meta.section type="since"/>
78
      </appInfo>
79
      <documentation>
80
         6.0
81
      </documentation>
82
   </annotation>
83
84
85
86
87
88
</schema>
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.core/src/org/eclipse/ptp/pldt/mpi/core/actions/RunAnalyseMPIcommandHandler.java (-59 / +12 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007,2011 IBM Corporation.
2
 * Copyright (c) 2007, 2011, 2012 IBM Corporation, University of Illinois, and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-42 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Jeff Overbey (UIUC) - modified to use extension point
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
package org.eclipse.ptp.pldt.mpi.core.actions;
12
package org.eclipse.ptp.pldt.mpi.core.actions;
13
13
14
import java.lang.reflect.Method;
15
import java.util.List;
14
import java.util.List;
16
15
17
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
18
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
19
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
20
import org.eclipse.cdt.core.model.ILanguage;
21
import org.eclipse.cdt.core.model.ITranslationUnit;
16
import org.eclipse.cdt.core.model.ITranslationUnit;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.ptp.pldt.common.CommonPlugin;
25
import org.eclipse.ptp.pldt.common.ScanReturn;
17
import org.eclipse.ptp.pldt.common.ScanReturn;
26
import org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase;
18
import org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase;
27
import org.eclipse.ptp.pldt.common.util.ViewActivator;
19
import org.eclipse.ptp.pldt.common.util.ViewActivator;
28
import org.eclipse.ptp.pldt.mpi.core.MPIArtifactMarkingVisitor;
20
import org.eclipse.ptp.pldt.mpi.core.MPIArtifactMarkingVisitor;
29
import org.eclipse.ptp.pldt.mpi.core.MpiPlugin;
21
import org.eclipse.ptp.pldt.mpi.core.MpiPlugin;
30
import org.eclipse.ptp.pldt.mpi.core.analysis.MpiCASTVisitor;
31
import org.eclipse.ptp.pldt.mpi.core.analysis.MpiCPPASTVisitor;
32
import org.eclipse.ptp.pldt.mpi.internal.core.MpiIDs;
22
import org.eclipse.ptp.pldt.mpi.internal.core.MpiIDs;
33
23
34
/**
24
/**
35
 * @author tibbitts
25
 * @author Beth Tibbitts
36
 * 
26
 * @author Jeff Overbey
37
 */
27
 */
38
public class RunAnalyseMPIcommandHandler extends RunAnalyseHandlerBase {
28
public class RunAnalyseMPIcommandHandler extends RunAnalyseHandlerBase {
39
	/**
29
	/**
30
	 * ID for the extension point which allows plug-ins to contribute MPI artifact analyses based on language IDs.
31
	 */
32
	private static final String EXTENSION_POINT_ID = "org.eclipse.ptp.pldt.mpi.core.artifactAnalysis";
33
34
	/**
40
	 * Constructor for the "Run Analysis" action
35
	 * Constructor for the "Run Analysis" action
41
	 */
36
	 */
42
	public RunAnalyseMPIcommandHandler() {
37
	public RunAnalyseMPIcommandHandler() {
Lines 53-102 public class RunAnalyseMPIcommandHandler extends RunAnalyseHandlerBase { Link Here
53
	 */
48
	 */
54
	@Override
49
	@Override
55
	public ScanReturn doArtifactAnalysis(final ITranslationUnit tu, final List<String> includes) {
50
	public ScanReturn doArtifactAnalysis(final ITranslationUnit tu, final List<String> includes) {
56
		final ScanReturn msr = new ScanReturn();
51
		final boolean allowPrefixOnlyMatch = MpiPlugin.getDefault().getPreferenceStore().getBoolean(MpiIDs.MPI_RECOGNIZE_APIS_BY_PREFIX_ALONE);
57
		final String fileName = tu.getElementName();
52
		return runArtifactAnalysisFromExtensionPoint(EXTENSION_POINT_ID, tu, includes, allowPrefixOnlyMatch);
58
		ILanguage lang;
59
		boolean allowPrefixOnlyMatch = MpiPlugin.getDefault().getPreferenceStore()
60
				.getBoolean(MpiIDs.MPI_RECOGNIZE_APIS_BY_PREFIX_ALONE);
61
		try {
62
			lang = tu.getLanguage();
63
64
			// long startTime = System.currentTimeMillis();
65
			IASTTranslationUnit atu = getAST(tu); // use index; was tu.getAST();
66
67
			// long endTime = System.currentTimeMillis();
68
			// System.out.println("RunAnalyseMPICommandHandler: time to build AST for "+tu+": "+(endTime-startTime)/1000.0+" sec");
69
			String languageID = lang.getId();
70
			if (languageID.equals(GCCLanguage.ID) || languageID.equals(GPPLanguage.ID)) {
71
				// null IASTTranslationUnit when we're doing C/C++ means we should quit.
72
				// but want to continue to see if this is a fortran file we are analyzing.
73
				if (atu == null) {// this is null for Fortran file during JUnit testing.
74
					System.out.println("RunAnalyseMPICommandHandler.doArtifactAnalysis(), atu is null (Fortran testing?)"); //$NON-NLS-1$
75
					return msr;
76
				}
77
			}
78
			if (languageID.equals(GCCLanguage.ID)) {// C
79
				atu.accept(new MpiCASTVisitor(includes, fileName, allowPrefixOnlyMatch, msr));
80
			} else if (languageID.equals(GPPLanguage.ID)) { // C++
81
				atu.accept(new MpiCPPASTVisitor(includes, fileName, allowPrefixOnlyMatch, msr));
82
			} else {
83
				// Attempt to handle Fortran
84
				// Instantiate using reflection to avoid static Photran dependencies
85
				try {
86
					Class<?> c = Class.forName("org.eclipse.ptp.pldt.mpi.fortran.actions.AnalyseMPIFortranHandler"); //$NON-NLS-1$
87
					Method method = c.getMethod("run", String.class, ITranslationUnit.class, String.class, ScanReturn.class); //$NON-NLS-1$
88
					method.invoke(c.newInstance(), languageID, tu, fileName, msr);
89
				} catch (Exception e) {
90
					System.err.println("RunAnalyseMPIcommandHandler.doArtifactAnalysis: Photran not installed"); //$NON-NLS-1$
91
				}
92
			}
93
		} catch (CoreException e) {
94
			e.printStackTrace();
95
			CommonPlugin
96
					.log(IStatus.ERROR,
97
							"RunAnalyseMPICommandHandler.getAST():Error setting up visitor for project " + tu.getCProject() + " error=" + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
98
		}
99
		return msr;
100
	}
53
	}
101
54
102
	@Override
55
	@Override
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.core/src/org/eclipse/ptp/pldt/mpi/core/analysis/CMPIArtifactAnalysis.java (+48 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011, 2012 IBM Corporation, University of Illinois, and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Jeff Overbey (UIUC) - modified to use extension point
11
 *******************************************************************************/
12
package org.eclipse.ptp.pldt.mpi.core.analysis;
13
14
import java.util.List;
15
16
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
17
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
18
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
19
import org.eclipse.cdt.core.model.ITranslationUnit;
20
import org.eclipse.ptp.pldt.common.ArtifactAnalysisBase;
21
import org.eclipse.ptp.pldt.common.IArtifactAnalysis;
22
import org.eclipse.ptp.pldt.common.ScanReturn;
23
24
/**
25
 * MPI artifact analysis for C and C++.
26
 * <p>
27
 * Contributed to the <code>org.eclipse.ptp.pldt.mpi.core.artifactAnalysis</code> extension point.
28
 * 
29
 * @author Beth Tibbitts
30
 * @author Jeff Overbey
31
 */
32
public class CMPIArtifactAnalysis extends ArtifactAnalysisBase implements IArtifactAnalysis {
33
	public ScanReturn runArtifactAnalysis(String languageID, ITranslationUnit tu, List<String> includes, boolean allowPrefixOnlyMatch) {
34
		final ScanReturn msr = new ScanReturn();
35
		final String fileName = tu.getElementName();
36
		final IASTTranslationUnit atu = getAST(tu); // use index; was tu.getAST();
37
		if (atu != null) {
38
			if (languageID.equals(GCCLanguage.ID)) { // C
39
				atu.accept(new MpiCASTVisitor(includes, fileName, allowPrefixOnlyMatch, msr));
40
			} else if (languageID.equals(GPPLanguage.ID)) { // C++
41
				atu.accept(new MpiCPPASTVisitor(includes, fileName, allowPrefixOnlyMatch, msr));
42
			} else {
43
				throw new IllegalStateException("Unexpected language ID " + languageID);
44
			}
45
		}
46
		return msr;
47
	}
48
}
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.fortran/META-INF/MANIFEST.MF (-4 / +8 lines)
Lines 7-19 Bundle-ClassPath: . Link Here
7
Bundle-Activator: org.eclipse.ptp.pldt.mpi.fortran.Activator
7
Bundle-Activator: org.eclipse.ptp.pldt.mpi.fortran.Activator
8
Bundle-Vendor: %pluginProvider
8
Bundle-Vendor: %pluginProvider
9
Bundle-Localization: plugin
9
Bundle-Localization: plugin
10
Require-Bundle: org.eclipse.ui,
10
Require-Bundle: org.eclipse.core.runtime,
11
 org.eclipse.core.runtime,
12
 org.eclipse.core.resources,
11
 org.eclipse.core.resources,
12
 org.eclipse.help,
13
 org.eclipse.ui,
14
 org.eclipse.ui.editors,
13
 org.eclipse.cdt.core,
15
 org.eclipse.cdt.core,
14
 org.eclipse.cdt.ui,
16
 org.eclipse.cdt.ui,
15
 org.eclipse.ptp.pldt.common,
16
 org.eclipse.photran.cdtinterface;bundle-version="7.0.0",
17
 org.eclipse.photran.cdtinterface;bundle-version="7.0.0",
17
 org.eclipse.photran.core.vpg;bundle-version="7.0.0"
18
 org.eclipse.photran.core.vpg;bundle-version="7.0.0",
19
 org.eclipse.photran.ui;bundle-version="8.0.0",
20
 org.eclipse.ptp.pldt.common,
21
 org.eclipse.ptp.pldt.mpi.core
18
Bundle-ActivationPolicy: lazy
22
Bundle-ActivationPolicy: lazy
19
Bundle-RequiredExecutionEnvironment: J2SE-1.5
23
Bundle-RequiredExecutionEnvironment: J2SE-1.5
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.fortran/build.properties (-1 / +2 lines)
Lines 1-7 Link Here
1
bin.includes = META-INF/,\
1
bin.includes = META-INF/,\
2
               .,\
2
               .,\
3
               plugin.properties,\
3
               plugin.properties,\
4
               about.html
4
               about.html,\
5
               plugin.xml
5
jars.compile.order = .
6
jars.compile.order = .
6
source.. = src/
7
source.. = src/
7
output.. = bin/
8
output.. = bin/
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.fortran/plugin.xml (+20 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
5
   <!-- MPI artifact analysis for Fortran -->
6
   <extension point="org.eclipse.ptp.pldt.mpi.core.artifactAnalysis">
7
      <artifactAnalysis
8
            languageID="org.eclipse.photran.cdtinterface.fortran"
9
            class="org.eclipse.ptp.pldt.mpi.fortran.analysis.MPIFortranArtifactAnalysis" />
10
   </extension>
11
12
   <!-- Dynamic help for MPI in the Photran editor -->
13
   <extension
14
         point="org.eclipse.photran.ui.apiHelpProvider">
15
      <apiHelpProvider
16
            class="org.eclipse.ptp.pldt.mpi.fortran.editorHelp.MpiFortranHelpProvider">
17
      </apiHelpProvider>
18
   </extension>
19
20
</plugin>
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.fortran/src/org/eclipse/ptp/pldt/mpi/fortran/Activator.java (-20 / +49 lines)
Lines 13-18 package org.eclipse.ptp.pldt.mpi.fortran; Link Here
13
13
14
import org.eclipse.core.resources.IWorkspace;
14
import org.eclipse.core.resources.IWorkspace;
15
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
16
import org.eclipse.swt.widgets.Display;
18
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.ui.plugin.AbstractUIPlugin;
19
import org.eclipse.ui.plugin.AbstractUIPlugin;
18
import org.osgi.framework.BundleContext;
20
import org.osgi.framework.BundleContext;
Lines 28-33 public class Activator extends AbstractUIPlugin { Link Here
28
	private static final String PLUGIN_ID = "org.eclipse.ptp.pldt.mpi.fortran"; //$NON-NLS-1$
30
	private static final String PLUGIN_ID = "org.eclipse.ptp.pldt.mpi.fortran"; //$NON-NLS-1$
29
31
30
	/**
32
	/**
33
	 * Returns the shared instance.
34
	 */
35
	public static Activator getDefault() {
36
		return plugin;
37
	}
38
39
	/**
40
	 * Returns the workspace instance.
41
	 */
42
	public static IWorkspace getWorkspace() {
43
		return ResourcesPlugin.getWorkspace();
44
	}
45
46
	/**
47
	 * Returns the standard display to be used. The method first checks, if the
48
	 * thread calling this method has an associated display. If so, this display
49
	 * is returned. Otherwise the method returns the default display.
50
	 */
51
	public static Display getStandardDisplay() {
52
		Display display;
53
		display = Display.getCurrent();
54
		if (display == null) {
55
			display = Display.getDefault();
56
		}
57
		return display;
58
	}
59
60
	public static String getPluginId() {
61
		return PLUGIN_ID;
62
	}
63
64
	/**
31
	 * The constructor.
65
	 * The constructor.
32
	 */
66
	 */
33
	public Activator() {
67
	public Activator() {
Lines 53-86 public class Activator extends AbstractUIPlugin { Link Here
53
	}
87
	}
54
88
55
	/**
89
	/**
56
	 * Returns the shared instance.
90
	 * Create log entry from an IStatus
91
	 * 
92
	 * @param status
57
	 */
93
	 */
58
	public static Activator getDefault() {
94
	public static void log(IStatus status) {
59
		return plugin;
95
		getDefault().getLog().log(status);
60
	}
96
	}
61
97
62
	/**
98
	/**
63
	 * Returns the workspace instance.
99
	 * Create log entry from a string
100
	 * 
101
	 * @param msg
64
	 */
102
	 */
65
	public static IWorkspace getWorkspace() {
103
	public static void log(String msg) {
66
		return ResourcesPlugin.getWorkspace();
104
		log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, msg, null));
67
	}
105
	}
68
106
69
	/**
107
	/**
70
	 * Returns the standard display to be used. The method first checks, if the
108
	 * Create log entry from a Throwable
71
	 * thread calling this method has an associated display. If so, this display
109
	 * 
72
	 * is returned. Otherwise the method returns the default display.
110
	 * @param e
73
	 */
111
	 */
74
	public static Display getStandardDisplay() {
112
	public static void log(Throwable e) {
75
		Display display;
113
		log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, e.getMessage(), e));
76
		display = Display.getCurrent();
77
		if (display == null) {
78
			display = Display.getDefault();
79
		}
80
		return display;
81
	}
82
83
	public static String getPluginId() {
84
		return PLUGIN_ID;
85
	}
114
	}
86
}
115
}
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.fortran/src/org/eclipse/ptp/pldt/mpi/fortran/actions/AnalyseMPIFortranHandler.java (-2 / +2 lines)
Lines 19-25 import org.eclipse.photran.internal.core.lexer.ASTLexerFactory; Link Here
19
import org.eclipse.photran.internal.core.parser.ASTExecutableProgramNode;
19
import org.eclipse.photran.internal.core.parser.ASTExecutableProgramNode;
20
import org.eclipse.photran.internal.core.parser.Parser;
20
import org.eclipse.photran.internal.core.parser.Parser;
21
import org.eclipse.ptp.pldt.common.ScanReturn;
21
import org.eclipse.ptp.pldt.common.ScanReturn;
22
import org.eclipse.ptp.pldt.mpi.fortran.analysis.MpiFortranASTVisitor;
22
import org.eclipse.ptp.pldt.mpi.fortran.analysis.MPIFortranASTVisitor;
23
23
24
/**
24
/**
25
 * @since 4.0
25
 * @since 4.0
Lines 34-40 public class AnalyseMPIFortranHandler { Link Here
34
34
35
			try {
35
			try {
36
				ASTExecutableProgramNode ast = new Parser().parse(new ASTLexerFactory().createLexer(file));
36
				ASTExecutableProgramNode ast = new Parser().parse(new ASTLexerFactory().createLexer(file));
37
				ast.accept(new MpiFortranASTVisitor(fileName, msr));
37
				ast.accept(new MPIFortranASTVisitor(fileName, msr));
38
			} catch (Exception e) {
38
			} catch (Exception e) {
39
				e.printStackTrace(); // TODO
39
				e.printStackTrace(); // TODO
40
			}
40
			}
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.fortran/src/org/eclipse/ptp/pldt/mpi/fortran/analysis/MPIFortranASTVisitor.java (+71 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2010 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.pldt.mpi.fortran.analysis;
12
13
import org.eclipse.photran.internal.core.lexer.Token;
14
import org.eclipse.photran.internal.core.parser.ASTCallStmtNode;
15
import org.eclipse.photran.internal.core.parser.ASTNameNode;
16
import org.eclipse.photran.internal.core.parser.ASTVarOrFnRefNode;
17
import org.eclipse.photran.internal.core.parser.GenericASTVisitor;
18
import org.eclipse.ptp.pldt.common.Artifact;
19
import org.eclipse.ptp.pldt.common.ScanReturn;
20
import org.eclipse.ptp.pldt.common.util.SourceInfo;
21
22
/**
23
 * This dom-walker collects "artifacts" related to the specific domain <br>
24
 * (e.g. MPI, OpenMP, etc.). Currently these artifacts include function calls
25
 * and constants. It adds markers to the source file for C code, marking the
26
 * position of the artifacts found.
27
 * 
28
 * @author Beth Tibbitts
29
 * @since 4.0
30
 * 
31
 */
32
public class MPIFortranASTVisitor extends GenericASTVisitor {
33
	private static final String PREFIX = "MPI_"; //$NON-NLS-1$
34
35
	@SuppressWarnings("unused")
36
	private static final boolean traceOn = false;
37
	private final ScanReturn scanReturn;
38
	private final String fileName;
39
40
	@Override
41
	public void visitASTCallStmtNode(ASTCallStmtNode node) {
42
		Token subroutineName = node.getSubroutineName();
43
		addArtifact(subroutineName, Artifact.FUNCTION_CALL);
44
	}
45
46
	@Override
47
	public void visitASTVarOrFnRefNode(ASTVarOrFnRefNode node) {
48
		ASTNameNode nameNode = node.getName();
49
		if (nameNode != null) {
50
			Token varName = nameNode.getName();
51
			addArtifact(varName, Artifact.CONSTANT);
52
		}
53
	}
54
55
	private void addArtifact(Token subroutineName, int artifactType) {
56
		String callname = subroutineName.getText().toUpperCase();
57
		if (callname.startsWith(PREFIX)) {
58
			int start = subroutineName.getFileOffset();
59
			int end = subroutineName.getFileOffset() + subroutineName.getLength();
60
			SourceInfo si = new SourceInfo(subroutineName.getLine(), start, end, artifactType);
61
			scanReturn.addArtifact(new Artifact(fileName, subroutineName.getLine(), 1, callname, si));
62
		}
63
	}
64
65
	public MPIFortranASTVisitor(String fileName, ScanReturn scanReturn) {
66
		super();
67
		this.scanReturn = scanReturn;
68
		this.fileName = fileName;
69
	}
70
71
}
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.fortran/src/org/eclipse/ptp/pldt/mpi/fortran/analysis/MPIFortranArtifactAnalysis.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 University of Illinois at Urbana-Champaign and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     UIUC - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.pldt.mpi.fortran.analysis;
12
13
import java.util.List;
14
15
import org.eclipse.cdt.core.model.ITranslationUnit;
16
import org.eclipse.ptp.pldt.common.IArtifactAnalysis;
17
import org.eclipse.ptp.pldt.common.ScanReturn;
18
import org.eclipse.ptp.pldt.mpi.fortran.actions.AnalyseMPIFortranHandler;
19
20
/**
21
 * MPI artifact analysis for Fortran.
22
 * <p>
23
 * Contributed to the <code>org.eclipse.ptp.pldt.mpi.core.artifactAnalysis</code> extension point.
24
 * 
25
 * @author Jeff Overbey
26
 */
27
public class MPIFortranArtifactAnalysis implements IArtifactAnalysis {
28
	public ScanReturn runArtifactAnalysis(String languageID, ITranslationUnit tu, List<String> includes, boolean allowPrefixOnlyMatch) {
29
		final ScanReturn msr = new ScanReturn();
30
		new AnalyseMPIFortranHandler().run(languageID, tu, tu.getElementName(), msr);
31
		return msr;
32
	}
33
}
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.fortran/src/org/eclipse/ptp/pldt/mpi/fortran/analysis/MpiFortranASTVisitor.java (-71 lines)
Lines 1-71 Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2010 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.pldt.mpi.fortran.analysis;
12
13
import org.eclipse.photran.internal.core.lexer.Token;
14
import org.eclipse.photran.internal.core.parser.ASTCallStmtNode;
15
import org.eclipse.photran.internal.core.parser.ASTNameNode;
16
import org.eclipse.photran.internal.core.parser.ASTVarOrFnRefNode;
17
import org.eclipse.photran.internal.core.parser.GenericASTVisitor;
18
import org.eclipse.ptp.pldt.common.Artifact;
19
import org.eclipse.ptp.pldt.common.ScanReturn;
20
import org.eclipse.ptp.pldt.common.util.SourceInfo;
21
22
/**
23
 * This dom-walker collects "artifacts" related to the specific domain <br>
24
 * (e.g. MPI, OpenMP, etc.). Currently these artifacts include function calls
25
 * and constants. It adds markers to the source file for C code, marking the
26
 * position of the artifacts found.
27
 * 
28
 * @author Beth Tibbitts
29
 * @since 4.0
30
 * 
31
 */
32
public class MpiFortranASTVisitor extends GenericASTVisitor {
33
	private static final String PREFIX = "MPI_"; //$NON-NLS-1$
34
35
	@SuppressWarnings("unused")
36
	private static final boolean traceOn = false;
37
	private final ScanReturn scanReturn;
38
	private final String fileName;
39
40
	@Override
41
	public void visitASTCallStmtNode(ASTCallStmtNode node) {
42
		Token subroutineName = node.getSubroutineName();
43
		addArtifact(subroutineName, Artifact.FUNCTION_CALL);
44
	}
45
46
	@Override
47
	public void visitASTVarOrFnRefNode(ASTVarOrFnRefNode node) {
48
		ASTNameNode nameNode = node.getName();
49
		if (nameNode != null) {
50
			Token varName = nameNode.getName();
51
			addArtifact(varName, Artifact.CONSTANT);
52
		}
53
	}
54
55
	private void addArtifact(Token subroutineName, int artifactType) {
56
		String callname = subroutineName.getText().toUpperCase();
57
		if (callname.startsWith(PREFIX)) {
58
			int start = subroutineName.getFileOffset();
59
			int end = subroutineName.getFileOffset() + subroutineName.getLength();
60
			SourceInfo si = new SourceInfo(subroutineName.getLine(), start, end, artifactType);
61
			scanReturn.addArtifact(new Artifact(fileName, subroutineName.getLine(), 1, callname, si));
62
		}
63
	}
64
65
	public MpiFortranASTVisitor(String fileName, ScanReturn scanReturn) {
66
		super();
67
		this.scanReturn = scanReturn;
68
		this.fileName = fileName;
69
	}
70
71
}
(-)tools/pldt/org.eclipse.ptp.pldt.mpi.fortran/src/org/eclipse/ptp/pldt/mpi/fortran/editorHelp/MpiFortranHelpProvider.java (+108 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2011 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.pldt.mpi.fortran.editorHelp;
12
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.net.URL;
16
import java.util.Collections;
17
import java.util.HashMap;
18
import java.util.Map;
19
20
import javax.xml.parsers.DocumentBuilder;
21
import javax.xml.parsers.DocumentBuilderFactory;
22
23
import org.eclipse.core.runtime.FileLocator;
24
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Platform;
26
import org.eclipse.help.IHelpResource;
27
import org.eclipse.photran.ui.IFortranAPIHelpProvider;
28
import org.eclipse.ptp.pldt.mpi.core.MpiPlugin;
29
import org.eclipse.ptp.pldt.mpi.fortran.Activator;
30
import org.eclipse.ui.texteditor.ITextEditor;
31
import org.w3c.dom.Document;
32
import org.w3c.dom.Node;
33
import org.w3c.dom.NodeList;
34
35
/**
36
 * Help book for Fortran MPI functions
37
 * 
38
 * @author Beth Tibbitts
39
 * @author Jeff Overbey
40
 */
41
public class MpiFortranHelpProvider implements IFortranAPIHelpProvider {
42
	private final Map<String, String> fNameToCname;
43
44
	/**
45
	 * builds the list of function summaries by parsing an XML file
46
	 */
47
	public MpiFortranHelpProvider() {
48
		Map<String, String> fNameToCname;
49
		URL fileURL = FileLocator.find(Platform.getBundle(MpiPlugin.getPluginId()), new Path("mpiref.xml"), null); //$NON-NLS-1$
50
		try {
51
			fNameToCname = parseDOM(fileURL.openStream());
52
		} catch (IOException e) {
53
			Activator.log(e);
54
			fNameToCname = Collections.<String, String>emptyMap();
55
		}
56
		this.fNameToCname = fNameToCname;
57
	}
58
59
	public static Map<String, String> parseDOM(InputStream xmlIn) {
60
		final Map<String, String> fNameToCname = new HashMap<String, String>();
61
		if (xmlIn != null)
62
		{
63
			try {
64
				DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
65
				Document document = builder.parse(xmlIn);
66
				NodeList functionList = document.getElementsByTagName("function");//$NON-NLS-1$
67
				for (int i = 0; i < functionList.getLength(); i++) {
68
					Node func = functionList.item(i);
69
					NodeList child = func.getChildNodes();
70
					String fname = null;
71
					String cname = null;
72
					// String desc = null;
73
					for (int j = 0; j < child.getLength(); j++) {
74
						Node sub = child.item(j);
75
						if (sub.getNodeName().equals("cname")) {
76
							cname = sub.getTextContent(); // java 5
77
						//} else if (sub.getNodeName().equals("description")) {//$NON-NLS-1$
78
							// desc = sub.getTextContent(); // java 5
79
						} else if (sub.getNodeName().equals("fname")) {//$NON-NLS-1$
80
							fname = sub.getTextContent(); // java 5
81
						}
82
					}
83
					if (fname != null && cname != null) {
84
						fNameToCname.put(fname.toUpperCase(), cname);
85
					}
86
				}
87
			} catch (Exception e) {
88
				Activator.log(e);
89
			}
90
		}
91
		return fNameToCname;
92
	}
93
94
	public IHelpResource[] getHelpResources(ITextEditor fortranEditor, String name, String precedingText) {
95
		final String fname = name.toUpperCase();
96
		if (fNameToCname.containsKey(fname)) {
97
			return new IHelpResource[] { new IHelpResource() {
98
				public String getHref() {
99
					return String.format("/%s/html/%s.html", MpiPlugin.getPluginId(), fNameToCname.get(fname));
100
				}
101
				public String getLabel() {
102
					return fname;
103
				}
104
			} };
105
		}
106
		return null;
107
	}
108
}
(-)tools/pldt/org.eclipse.ptp.pldt.openacc.fortran/META-INF/MANIFEST.MF (+3 lines)
Lines 15-20 Require-Bundle: org.eclipse.core.runtime, Link Here
15
 org.eclipse.cdt.ui,
15
 org.eclipse.cdt.ui,
16
 org.eclipse.ptp.pldt.common,
16
 org.eclipse.ptp.pldt.common,
17
 org.eclipse.ptp.pldt.openacc,
17
 org.eclipse.ptp.pldt.openacc,
18
 org.eclipse.photran.core,
19
 org.eclipse.photran.core.vpg,
20
 org.eclipse.photran.cdtinterface,
18
 org.eclipse.photran.ui;bundle-version="8.0.0"
21
 org.eclipse.photran.ui;bundle-version="8.0.0"
19
Bundle-ActivationPolicy: lazy
22
Bundle-ActivationPolicy: lazy
20
Bundle-ClassPath: .
23
Bundle-ClassPath: .
(-)tools/pldt/org.eclipse.ptp.pldt.openacc.fortran/plugin.xml (+7 lines)
Lines 2-7 Link Here
2
<?eclipse version="3.0"?>
2
<?eclipse version="3.0"?>
3
<plugin>
3
<plugin>
4
4
5
   <!-- OpenACC artifact analysis for Fortran -->
6
   <extension point="org.eclipse.ptp.pldt.openacc.artifactAnalysis">
7
      <artifactAnalysis
8
            languageID="org.eclipse.photran.cdtinterface.fortran"
9
            class="org.eclipse.ptp.pldt.openacc.internal.fortran.actions.OpenACCFortranArtifactAnalysis" />
10
   </extension>
11
5
   <!-- OpenACC API help for Fortran -->
12
   <!-- OpenACC API help for Fortran -->
6
   <extension
13
   <extension
7
         point="org.eclipse.photran.ui.apiHelpProvider">
14
         point="org.eclipse.photran.ui.apiHelpProvider">
(-)tools/pldt/org.eclipse.ptp.pldt.openacc.fortran/src/org/eclipse/ptp/pldt/openacc/internal/fortran/actions/OpenACCFortranASTVisitor.java (+85 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2010 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.pldt.openacc.internal.fortran.actions;
12
13
import org.eclipse.photran.internal.core.lexer.Token;
14
import org.eclipse.photran.internal.core.parser.ASTCallStmtNode;
15
import org.eclipse.photran.internal.core.parser.ASTNameNode;
16
import org.eclipse.photran.internal.core.parser.ASTVarOrFnRefNode;
17
import org.eclipse.photran.internal.core.parser.GenericASTVisitor;
18
import org.eclipse.ptp.pldt.common.Artifact;
19
import org.eclipse.ptp.pldt.common.ScanReturn;
20
import org.eclipse.ptp.pldt.common.util.SourceInfo;
21
22
/**
23
 * This dom-walker collects "artifacts" related to the specific domain <br>
24
 * (e.g. MPI, OpenMP, etc.). Currently these artifacts include function calls
25
 * and constants. It adds markers to the source file for C code, marking the
26
 * position of the artifacts found.
27
 * 
28
 * @author Beth Tibbitts
29
 * @since 4.0
30
 * 
31
 */
32
public class OpenACCFortranASTVisitor extends GenericASTVisitor {
33
	private static final String PREFIX = "ACC_"; //$NON-NLS-1$
34
35
	@SuppressWarnings("unused")
36
	private static final boolean traceOn = false;
37
	private final ScanReturn scanReturn;
38
	private final String fileName;
39
40
	@Override
41
	public void visitToken(Token node) {
42
		/*
43
		 * In Fortran, OpenACC directives are comments (e.g., !$acc parallel).
44
		 * Photran attaches comments to the following token. Since they appear
45
		 * before several types of statements (including END statements), it's
46
		 * easiest to just iterate through all the tokens in the AST and collect
47
		 * the preceding OpenMP directives.
48
		 */
49
		for (Token accDirective : node.getOpenACCComments()) {
50
			addArtifact(accDirective, Artifact.PRAGMA);
51
		}
52
	}
53
54
	@Override
55
	public void visitASTCallStmtNode(ASTCallStmtNode node) {
56
		Token subroutineName = node.getSubroutineName();
57
		addArtifact(subroutineName, Artifact.FUNCTION_CALL);
58
	}
59
60
	@Override
61
	public void visitASTVarOrFnRefNode(ASTVarOrFnRefNode node) {
62
		ASTNameNode nameNode = node.getName();
63
		if (nameNode != null) {
64
			Token varName = nameNode.getName();
65
			addArtifact(varName, Artifact.CONSTANT);
66
		}
67
	}
68
69
	private void addArtifact(Token subroutineName, int artifactType) {
70
		String callname = subroutineName.getText().toUpperCase();
71
		if (artifactType == Artifact.PRAGMA || callname.startsWith(PREFIX)) {
72
			int start = subroutineName.getFileOffset();
73
			int end = subroutineName.getFileOffset() + subroutineName.getLength();
74
			SourceInfo si = new SourceInfo(subroutineName.getLine(), start, end, artifactType);
75
			scanReturn.addArtifact(new Artifact(fileName, subroutineName.getLine(), 1, callname, si));
76
		}
77
	}
78
79
	public OpenACCFortranASTVisitor(String fileName, ScanReturn scanReturn) {
80
		super();
81
		this.scanReturn = scanReturn;
82
		this.fileName = fileName;
83
	}
84
85
}
(-)tools/pldt/org.eclipse.ptp.pldt.openacc.fortran/src/org/eclipse/ptp/pldt/openacc/internal/fortran/actions/OpenACCFortranArtifactAnalysis.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 University of Illinois at Urbana-Champaign and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     UIUC - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.pldt.openacc.internal.fortran.actions;
12
13
import java.util.List;
14
15
import org.eclipse.cdt.core.model.ITranslationUnit;
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.photran.internal.cdtinterface.core.FortranLanguage;
19
import org.eclipse.photran.internal.core.lexer.ASTLexerFactory;
20
import org.eclipse.photran.internal.core.parser.ASTExecutableProgramNode;
21
import org.eclipse.photran.internal.core.parser.Parser;
22
import org.eclipse.ptp.pldt.common.IArtifactAnalysis;
23
import org.eclipse.ptp.pldt.common.ScanReturn;
24
25
/**
26
 * OpenACC artifact analysis for Fortran.
27
 * <p>
28
 * Contributed to the <code>org.eclipse.ptp.pldt.mpi.core.artifactAnalysis</code> extension point.
29
 * 
30
 * @author Jeff Overbey
31
 */
32
public class OpenACCFortranArtifactAnalysis implements IArtifactAnalysis {
33
	@Override
34
	public ScanReturn runArtifactAnalysis(String languageID, ITranslationUnit tu, List<String> includes, boolean allowPrefixOnlyMatch) {
35
		final ScanReturn msr = new ScanReturn();
36
		final String fileName = tu.getElementName();
37
		if (languageID.equals(FortranLanguage.LANGUAGE_ID)) {
38
			IResource res = tu.getUnderlyingResource();
39
			if (!(res instanceof IFile))
40
				throw new IllegalStateException();
41
			IFile file = (IFile) res;
42
43
			try {
44
				ASTExecutableProgramNode ast = new Parser().parse(new ASTLexerFactory().createLexer(file));
45
				ast.accept(new OpenACCFortranASTVisitor(fileName, msr));
46
			} catch (Exception e) {
47
				e.printStackTrace(); // TODO
48
			}
49
		}
50
		return msr;
51
	}
52
}
(-)tools/pldt/org.eclipse.ptp.pldt.openacc.fortran/src/org/eclipse/ptp/pldt/openacc/internal/fortran/editorHelp/OpenACCFortranHelpProvider.java (-5 / +18 lines)
Lines 27-42 public class OpenACCFortranHelpProvider implements IFortranAPIHelpProvider { Link Here
27
	/** Plug-in ID for the main (non-Fortran) OpenACC plug-in, which contains HTML documentation. */
27
	/** Plug-in ID for the main (non-Fortran) OpenACC plug-in, which contains HTML documentation. */
28
	private static final String OPENACC_PLUGIN_ID = "org.eclipse.ptp.pldt.openacc"; //$NON-NLS-1$
28
	private static final String OPENACC_PLUGIN_ID = "org.eclipse.ptp.pldt.openacc"; //$NON-NLS-1$
29
29
30
	/** Regular expression matching the start of an OpenACC directive */
30
	/** Pattern matching the start of an OpenACC directive */
31
	private static final Pattern OPENACC_DIRECTIVE_PREFIX = Pattern
31
	private static final Pattern OPENACC_DIRECTIVE_PREFIX_PATTERN = Pattern
32
			.compile("(^[Cc*]|[ \\t]*!)\\$acc([ \\t]+end)?([ \\t]+parallel)?[ \\t]*"); //$NON-NLS-1$
32
			.compile("(^[Cc*]|[ \\t]*!)\\$acc([ \\t]+end)?([ \\t]+parallel)?[ \\t]*"); //$NON-NLS-1$
33
33
34
	/** Format string for an OpenACC directive.  %s is replaced with a directive name. */
35
	private static final String OPENACC_DIRECTIVE_REGEX_FORMAT =
36
			"(^[Cc*]|[ \\t]*!)\\$acc([ \\t]+end)?([ \\t]+parallel)?[ \\t]+%s.*"; //$NON-NLS-1$
37
34
	private final Set<String> procedures = new HashSet<String>(32);
38
	private final Set<String> procedures = new HashSet<String>(32);
35
	private final Set<String> directives = new HashSet<String>(32);
39
	private final Set<String> directives = new HashSet<String>(32);
36
40
37
	/** Constructor */
41
	/** Constructor */
38
	public OpenACCFortranHelpProvider() {
42
	public OpenACCFortranHelpProvider() {
39
		procedures.add("acc_get_num_devices"); // OpenACC Application Programming Interface, Version 1.0, Section 3.2.1 //$NON-NLS-1$
43
		// Section numbers from the OpenACC specification: "The OpenACC Application Programming Interface, Version 1.0"
44
		procedures.add("acc_get_num_devices"); // Section 3.2.1 //$NON-NLS-1$
40
		procedures.add("acc_set_device_type"); // 3.2.2 //$NON-NLS-1$
45
		procedures.add("acc_set_device_type"); // 3.2.2 //$NON-NLS-1$
41
		procedures.add("acc_get_device_type"); // 3.2.3 //$NON-NLS-1$
46
		procedures.add("acc_get_device_type"); // 3.2.3 //$NON-NLS-1$
42
		procedures.add("acc_set_device_num"); // 3.2.4 //$NON-NLS-1$
47
		procedures.add("acc_set_device_num"); // 3.2.4 //$NON-NLS-1$
Lines 67-74 public class OpenACCFortranHelpProvider implements IFortranAPIHelpProvider { Link Here
67
		final String fname = apiName.toLowerCase();
72
		final String fname = apiName.toLowerCase();
68
		if (procedures.contains(fname)) {
73
		if (procedures.contains(fname)) {
69
			return getHelpResourceForFilename(fname);
74
			return getHelpResourceForFilename(fname);
70
		} else if (directives.contains(fname) && OPENACC_DIRECTIVE_PREFIX.matcher(precedingText).matches()) {
75
		} else if (OPENACC_DIRECTIVE_PREFIX_PATTERN.matcher(precedingText).find()) {
71
			return getHelpResourceForFilename("pragma_acc_" + fname); //$NON-NLS-1$
76
			if (directives.contains(fname)) {
77
				return getHelpResourceForFilename("pragma_acc_" + fname); //$NON-NLS-1$
78
			} else {
79
				for (String directive : directives) {
80
					if (precedingText.matches(String.format(OPENACC_DIRECTIVE_REGEX_FORMAT, directive))) {
81
						return getHelpResourceForFilename("pragma_acc_" + directive); //$NON-NLS-1$
82
					}
83
				}
84
			}
72
		}
85
		}
73
		return null;
86
		return null;
74
	}
87
	}
(-)tools/pldt/org.eclipse.ptp.pldt.openacc.fortran/templates/openacc_templates.xml (-1 / +69 lines)
Lines 1-7 Link Here
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<templates>
2
<templates>
3
	<template id="org.eclipse.ptp.pldt.openacc.fortran.cache"
4
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
5
		deleted="false" description="OpenACC cache directive" enabled="true"
6
		name="!$acc cache">!$$acc cache (${cursor})</template>
7
	<template id="org.eclipse.ptp.pldt.openacc.fortran.data"
8
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
9
		deleted="false" description="OpenACC data directive" enabled="true"
10
		name="!$acc data">!$$acc data${cursor}</template>
11
	<template id="org.eclipse.ptp.pldt.openacc.fortran.endd_ata"
12
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
13
		deleted="false" description="OpenACC end data directive" enabled="true"
14
		name="!$acc end data">!$$acc end data${cursor}</template>
15
	<template id="org.eclipse.ptp.pldt.openacc.fortran.declare"
16
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
17
		deleted="false" description="OpenACC declare directive" enabled="true"
18
		name="!$acc declare">!$$acc declare ${cursor}</template>
19
	<template id="org.eclipse.ptp.pldt.openacc.fortran.host_data"
20
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
21
		deleted="false" description="OpenACC host_data directive" enabled="true"
22
		name="!$acc host_data">!$$acc host_data${cursor}</template>
23
	<template id="org.eclipse.ptp.pldt.openacc.fortran.end_host_data"
24
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
25
		deleted="false" description="OpenACC end host_data directive" enabled="true"
26
		name="!$acc end host_data">!$$acc end host_data${cursor}</template>
27
	<template id="org.eclipse.ptp.pldt.openacc.fortran.kernels"
28
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
29
		deleted="false" description="OpenACC kernels directive" enabled="true"
30
		name="!$acc kernels">!$$acc kernels${cursor}</template>
31
	<template id="org.eclipse.ptp.pldt.openacc.fortran.end_kernels"
32
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
33
		deleted="false" description="OpenACC end kernels directive" enabled="true"
34
		name="!$acc end kernels">!$$acc end kernels${cursor}</template>
35
	<template id="org.eclipse.ptp.pldt.openacc.fortran.kernels_loop"
36
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
37
		deleted="false" description="OpenACC kernels loop directive" enabled="true"
38
		name="!$acc kernels loop">!$$acc kernels loop${cursor}</template>
39
	<template id="org.eclipse.ptp.pldt.openacc.fortran.end_kernels_loop"
40
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
41
		deleted="false" description="OpenACC end kernels loop directive" enabled="true"
42
		name="!$acc end kernels loop">!$$acc end kernels loop${cursor}</template>
43
	<template id="org.eclipse.ptp.pldt.openacc.fortran.loop"
44
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
45
		deleted="false" description="OpenACC loop directive" enabled="true"
46
		name="!$acc loop">!$$acc loop${cursor}</template>
47
	<template id="org.eclipse.ptp.pldt.openacc.fortran.end_loop"
48
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
49
		deleted="false" description="OpenACC end loop directive" enabled="true"
50
		name="!$acc end loop">!$$acc end loop${cursor}</template>
3
	<template id="org.eclipse.ptp.pldt.openacc.fortran.parallel"
51
	<template id="org.eclipse.ptp.pldt.openacc.fortran.parallel"
4
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
52
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
5
		deleted="false" description="OpenACC parallel directive" enabled="true"
53
		deleted="false" description="OpenACC parallel directive" enabled="true"
6
		name="!$acc parallel">!$$acc parallel${cursor}</template>
54
		name="!$acc parallel">!$$acc parallel${cursor}</template>
7
</templates>
55
	<template id="org.eclipse.ptp.pldt.openacc.fortran.end_parallel"
56
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
57
		deleted="false" description="OpenACC end parallel directive" enabled="true"
58
		name="!$acc end parallel">!$$acc end parallel${cursor}</template>
59
	<template id="org.eclipse.ptp.pldt.openacc.fortran.parallel_loop"
60
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
61
		deleted="false" description="OpenACC parallel loop directive" enabled="true"
62
		name="!$acc parallel loop">!$$acc parallel loop${cursor}</template>
63
	<template id="org.eclipse.ptp.pldt.openacc.fortran.end_parallel_loop"
64
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
65
		deleted="false" description="OpenACC end parallel loop directive" enabled="true"
66
		name="!$acc end parallel loop">!$$acc end parallel loop${cursor}</template>
67
	<template id="org.eclipse.ptp.pldt.openacc.fortran.update"
68
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
69
		deleted="false" description="OpenACC update directive" enabled="true"
70
		name="!$acc update">!$$acc update ${cursor}</template>
71
	<template id="org.eclipse.ptp.pldt.openacc.fortran.wait"
72
		autoinsert="true" context="org.eclipse.photran.ui.template.context"
73
		deleted="false" description="OpenACC wait directive" enabled="true"
74
		name="!$acc wait">!$$acc wait${cursor}</template>
75
</templates>
(-)tools/pldt/org.eclipse.ptp.pldt.openacc/build.properties (-1 / +2 lines)
Lines 11-15 bin.includes = META-INF/,\ Link Here
11
               about.mappings,\
11
               about.mappings,\
12
               about.properties,\
12
               about.properties,\
13
               ptp_logo_icon32.png,\
13
               ptp_logo_icon32.png,\
14
               templates/
14
               templates/,\
15
               schema/
15
jre.compilation.profile = JavaSE-1.6
16
jre.compilation.profile = JavaSE-1.6
(-)tools/pldt/org.eclipse.ptp.pldt.openacc/plugin.xml (+15 lines)
Lines 93-98 Link Here
93
         </initializer>
93
         </initializer>
94
      </extension>
94
      </extension>
95
95
96
   <!-- OpenACC artifact analysis extension point -->
97
   <extension-point
98
      id="artifactAnalysis"
99
      name="OpenACC Artifact Analysis"
100
      schema="schema/artifactAnalysis.exsd"/>
101
   <!-- OpenACC atifact analyses for C and C++ -->
102
   <extension point="org.eclipse.ptp.pldt.openacc.artifactAnalysis">
103
      <artifactAnalysis
104
            languageID="org.eclipse.cdt.core.gcc"
105
            class="org.eclipse.ptp.pldt.openacc.internal.actions.OpenACCCArtifactAnalysis" />
106
      <artifactAnalysis
107
            languageID="org.eclipse.cdt.core.g++"
108
            class="org.eclipse.ptp.pldt.openacc.internal.actions.OpenACCCArtifactAnalysis" />
109
   </extension>
110
96
   <!-- OpenACC C help book -->
111
   <!-- OpenACC C help book -->
97
   <extension
112
   <extension
98
         point="org.eclipse.cdt.ui.CHelpProvider">
113
         point="org.eclipse.cdt.ui.CHelpProvider">
(-)tools/pldt/org.eclipse.ptp.pldt.openacc/schema/artifactAnalysis.exsd (+88 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.ptp.pldt.mpi.core" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.ptp.pldt.mpi.core" id="artifactAnalysis" name="OpenACC Artifact Analysis"/>
7
      </appInfo>
8
      <documentation>
9
         Allows plug-ins to contribute OpenACC artifact analyses.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <sequence minOccurs="1" maxOccurs="unbounded">
21
            <element ref="artifactAnalysis"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appInfo>
43
                  <meta.attribute translatable="true"/>
44
               </appInfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="artifactAnalysis">
51
      <complexType>
52
         <attribute name="languageID" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appInfo>
58
                  <meta.attribute kind="identifier" basedOn="org.eclipse.cdt.core.language/language/@id"/>
59
               </appInfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="class" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  
66
               </documentation>
67
               <appInfo>
68
                  <meta.attribute kind="java" basedOn=":org.eclipse.ptp.pldt.common.IArtifactAnalysis"/>
69
               </appInfo>
70
            </annotation>
71
         </attribute>
72
      </complexType>
73
   </element>
74
75
   <annotation>
76
      <appInfo>
77
         <meta.section type="since"/>
78
      </appInfo>
79
      <documentation>
80
         6.0
81
      </documentation>
82
   </annotation>
83
84
85
86
87
88
</schema>
(-)tools/pldt/org.eclipse.ptp.pldt.openacc/src/org/eclipse/ptp/pldt/openacc/internal/actions/OpenACCCArtifactAnalysis.java (+84 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011, 2012 IBM Corporation, University of Illinois, and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Jeff Overbey (UIUC) - modified to use extension point
11
 *******************************************************************************/
12
package org.eclipse.ptp.pldt.openacc.internal.actions;
13
14
import java.util.List;
15
import java.util.regex.Pattern;
16
17
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
18
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorPragmaStatement;
19
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
20
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
21
import org.eclipse.cdt.core.model.ITranslationUnit;
22
import org.eclipse.ptp.pldt.common.Artifact;
23
import org.eclipse.ptp.pldt.common.ArtifactAnalysisBase;
24
import org.eclipse.ptp.pldt.common.IArtifactAnalysis;
25
import org.eclipse.ptp.pldt.common.ScanReturn;
26
import org.eclipse.ptp.pldt.common.util.SourceInfo;
27
import org.eclipse.ptp.pldt.openacc.internal.messages.Messages;
28
29
/**
30
 * OpenACC artifact analysis for C and C++.
31
 * <p>
32
 * Contributed to the <code>org.eclipse.ptp.pldt.openacc.artifactAnalysis</code> extension point.
33
 * 
34
 * @author Beth Tibbitts
35
 * @author Jeff Overbey
36
 */
37
public class OpenACCCArtifactAnalysis extends ArtifactAnalysisBase implements IArtifactAnalysis {
38
39
	private static final Pattern ACC_PRAGMA_PATTERN = Pattern
40
			.compile("acc[ \t]*(parallel|kernels|data|host_data|loop|cache|declare|update|wait).*"); //$NON-NLS-1$
41
42
	@Override
43
	public ScanReturn runArtifactAnalysis(String languageID, ITranslationUnit tu, List<String> includes, boolean allowPrefixOnlyMatch) {
44
		final ScanReturn msr = new ScanReturn();
45
		final IASTTranslationUnit atu = getAST(tu); // use index; was tu.getAST();
46
		if (atu != null) {
47
			findOpenACCFunctionCalls(includes, msr, tu.getElementName(), atu, allowPrefixOnlyMatch);
48
			findOpenACCPragmas(atu, msr);
49
		}
50
		return msr;
51
	}
52
53
	private void findOpenACCFunctionCalls(final List<String> includes,
54
			final ScanReturn msr, final String fileName,
55
			final IASTTranslationUnit atu, boolean allowPrefixOnlyMatch) {
56
		atu.accept(new OpenACCCASTVisitor(includes, fileName, allowPrefixOnlyMatch, msr));
57
	}
58
59
	private void findOpenACCPragmas(final IASTTranslationUnit atu, final ScanReturn msr) {
60
		for (final IASTPreprocessorStatement preprocStmt : atu.getAllPreprocessorStatements()) {
61
			if (preprocStmt instanceof IASTPreprocessorPragmaStatement) {
62
				final String pragmaText = String.valueOf(((IASTPreprocessorPragmaStatement) preprocStmt).getMessage()).trim();
63
				if (preprocStmt.isPartOfTranslationUnitFile() && ACC_PRAGMA_PATTERN.matcher(pragmaText).matches()) {
64
					final IASTFileLocation astFileLocation = preprocStmt.getFileLocation();
65
					final SourceInfo sourceInfo = new SourceInfo();
66
					sourceInfo.setStartingLine(astFileLocation.getStartingLineNumber());
67
					sourceInfo.setStart(astFileLocation.getNodeOffset());
68
					sourceInfo.setEnd(astFileLocation.getNodeOffset() + astFileLocation.getNodeLength());
69
					sourceInfo.setConstructType(Artifact.PRAGMA);
70
71
					msr.addArtifact(
72
							new Artifact(
73
									preprocStmt.getContainingFilename(),
74
									astFileLocation.getStartingLineNumber(),
75
									1,
76
									"#pragma " + pragmaText, //$NON-NLS-1$
77
									Messages.RunAnalyseOpenACCcommandHandler_OpenACC_directive,
78
									sourceInfo,
79
									null));
80
				}
81
			}
82
		}
83
	}
84
}
(-)tools/pldt/org.eclipse.ptp.pldt.openacc/src/org/eclipse/ptp/pldt/openacc/internal/actions/RunAnalyseOpenACCcommandHandler.java (-65 / +11 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2007, 2011 IBM Corporation and University of Illinois.
2
 * Copyright (c) 2007, 2011, 2012 IBM Corporation and University of Illinois.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-36 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Jeff Overbey - adaptation to OpenACC
10
 *     Jeff Overbey - adaptation to OpenACC, modified to use extension point
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.ptp.pldt.openacc.internal.actions;
12
package org.eclipse.ptp.pldt.openacc.internal.actions;
13
13
14
import java.util.List;
14
import java.util.List;
15
import java.util.regex.Pattern;
16
15
17
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
18
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorPragmaStatement;
19
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
20
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
21
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
22
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
23
import org.eclipse.cdt.core.model.ITranslationUnit;
16
import org.eclipse.cdt.core.model.ITranslationUnit;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.ptp.pldt.common.Artifact;
26
import org.eclipse.ptp.pldt.common.ArtifactMarkingVisitor;
17
import org.eclipse.ptp.pldt.common.ArtifactMarkingVisitor;
27
import org.eclipse.ptp.pldt.common.ScanReturn;
18
import org.eclipse.ptp.pldt.common.ScanReturn;
28
import org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase;
19
import org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase;
29
import org.eclipse.ptp.pldt.common.util.SourceInfo;
30
import org.eclipse.ptp.pldt.common.util.ViewActivator;
20
import org.eclipse.ptp.pldt.common.util.ViewActivator;
31
import org.eclipse.ptp.pldt.openacc.internal.Activator;
21
import org.eclipse.ptp.pldt.openacc.internal.Activator;
32
import org.eclipse.ptp.pldt.openacc.internal.IDs;
22
import org.eclipse.ptp.pldt.openacc.internal.IDs;
33
import org.eclipse.ptp.pldt.openacc.internal.messages.Messages;
34
23
35
/**
24
/**
36
 * Handler for the &quot;Show OpenACC Artifacts&quot; command.
25
 * Handler for the &quot;Show OpenACC Artifacts&quot; command.
Lines 39-48 import org.eclipse.ptp.pldt.openacc.internal.messages.Messages; Link Here
39
 * @author Jeff Overbey
28
 * @author Jeff Overbey
40
 */
29
 */
41
public class RunAnalyseOpenACCcommandHandler extends RunAnalyseHandlerBase {
30
public class RunAnalyseOpenACCcommandHandler extends RunAnalyseHandlerBase {
31
	/**
32
	 * ID for the OpenACC Artifacts view, contributed in plugin.xml.
33
	 */
42
	private static final String VIEW_ID = "org.eclipse.ptp.pldt.openacc.views.OpenACCArtifactView"; //$NON-NLS-1$
34
	private static final String VIEW_ID = "org.eclipse.ptp.pldt.openacc.views.OpenACCArtifactView"; //$NON-NLS-1$
43
35
44
	private static final Pattern ACC_PRAGMA_PATTERN = Pattern
36
	/**
45
			.compile("acc[ \t]*(parallel|kernels|data|host_data|loop|cache|declare|update|wait).*"); //$NON-NLS-1$
37
	 * ID for the extension point which allows plug-ins to contribute OpenMP artifact analyses based on language IDs.
38
	 */
39
	private static final String EXTENSION_POINT_ID = "org.eclipse.ptp.pldt.openacc.artifactAnalysis"; //$NON-NLS-1$
46
40
47
	/**
41
	/**
48
	 * Constructor.  Invoked dynamically due to class reference in plugin.xml.
42
	 * Constructor.  Invoked dynamically due to class reference in plugin.xml.
Lines 62-117 public class RunAnalyseOpenACCcommandHandler extends RunAnalyseHandlerBase { Link Here
62
	 */
56
	 */
63
	@Override
57
	@Override
64
	public ScanReturn doArtifactAnalysis(final ITranslationUnit tu, final List<String> includes) {
58
	public ScanReturn doArtifactAnalysis(final ITranslationUnit tu, final List<String> includes) {
65
		final ScanReturn msr = new ScanReturn();
59
		final boolean allowPrefixOnlyMatch = Activator.getDefault().getPreferenceStore().getBoolean(IDs.PREF_RECOGNIZE_APIS_BY_PREFIX_ALONE);
66
		final boolean allowPrefixOnlyMatch = Activator.getDefault().getPreferenceStore()
60
		return runArtifactAnalysisFromExtensionPoint(EXTENSION_POINT_ID, tu, includes, allowPrefixOnlyMatch);
67
				.getBoolean(IDs.PREF_RECOGNIZE_APIS_BY_PREFIX_ALONE);
68
		if (traceOn)
69
		{
70
			System.out.println("RALCH:OpenACC allowPrefixOnlyMatch=" + allowPrefixOnlyMatch); //$NON-NLS-1$
71
		}
72
		try {
73
			final IASTTranslationUnit atu = tu.getAST();
74
			final String languageID = tu.getLanguage().getId();
75
			if (languageID.equals(GCCLanguage.ID) || languageID.equals(GPPLanguage.ID)) {
76
				findOpenACCFunctionCalls(includes, msr, tu.getElementName(), atu, allowPrefixOnlyMatch);
77
				findOpenACCPragmas(atu, msr);
78
			}
79
		} catch (final CoreException e) {
80
			Activator.log(e);
81
		}
82
		return msr;
83
	}
84
85
	private void findOpenACCFunctionCalls(final List<String> includes,
86
			final ScanReturn msr, final String fileName,
87
			final IASTTranslationUnit atu, boolean allowPrefixOnlyMatch) {
88
		atu.accept(new OpenACCCASTVisitor(includes, fileName, allowPrefixOnlyMatch, msr));
89
	}
90
91
	private void findOpenACCPragmas(final IASTTranslationUnit atu, final ScanReturn msr) {
92
		for (final IASTPreprocessorStatement preprocStmt : atu.getAllPreprocessorStatements()) {
93
			if (preprocStmt instanceof IASTPreprocessorPragmaStatement) {
94
				final String pragmaText = String.valueOf(((IASTPreprocessorPragmaStatement) preprocStmt).getMessage()).trim();
95
				if (preprocStmt.isPartOfTranslationUnitFile() && ACC_PRAGMA_PATTERN.matcher(pragmaText).matches()) {
96
					final IASTFileLocation astFileLocation = preprocStmt.getFileLocation();
97
					final SourceInfo sourceInfo = new SourceInfo();
98
					sourceInfo.setStartingLine(astFileLocation.getStartingLineNumber());
99
					sourceInfo.setStart(astFileLocation.getNodeOffset());
100
					sourceInfo.setEnd(astFileLocation.getNodeOffset() + astFileLocation.getNodeLength());
101
					sourceInfo.setConstructType(Artifact.PRAGMA);
102
103
					msr.addArtifact(
104
							new Artifact(
105
									preprocStmt.getContainingFilename(),
106
									astFileLocation.getStartingLineNumber(),
107
									1,
108
									"#pragma " + pragmaText, //$NON-NLS-1$
109
									Messages.RunAnalyseOpenACCcommandHandler_OpenACC_directive,
110
									sourceInfo,
111
									null));
112
				}
113
			}
114
		}
115
	}
61
	}
116
62
117
	@Override
63
	@Override
(-)tools/pldt/org.eclipse.ptp.pldt.openmp.core/build.properties (-1 / +2 lines)
Lines 7-11 bin.includes = META-INF/,\ Link Here
7
               samples/,\
7
               samples/,\
8
               plugin.properties,\
8
               plugin.properties,\
9
               html/,\
9
               html/,\
10
               about.html
10
               about.html,\
11
               schema/
11
bin.excludes = icons/.cvsignore
12
bin.excludes = icons/.cvsignore
(-)tools/pldt/org.eclipse.ptp.pldt.openmp.core/plugin.xml (+16 lines)
Lines 105-108 Link Here
105
               class="org.eclipse.ptp.pldt.openmp.core.prefs.OpenMPPreferenceInitializer">
105
               class="org.eclipse.ptp.pldt.openmp.core.prefs.OpenMPPreferenceInitializer">
106
         </initializer>
106
         </initializer>
107
      </extension>
107
      </extension>
108
109
   <!-- Artifact analysis extension point -->
110
   <extension-point
111
      id="artifactAnalysis"
112
      name="OpenMP Artifact Analysis"
113
      schema="schema/artifactAnalysis.exsd"/>
114
   <!-- Artifact analysis for C -->
115
   <extension point="org.eclipse.ptp.pldt.openmp.core.artifactAnalysis">
116
      <artifactAnalysis
117
            languageID="org.eclipse.cdt.core.gcc"
118
            class="org.eclipse.ptp.pldt.openmp.core.analysis.OpenMPCArtifactAnalysis" />
119
      <artifactAnalysis
120
            languageID="org.eclipse.cdt.core.g++"
121
            class="org.eclipse.ptp.pldt.openmp.core.analysis.OpenMPCArtifactAnalysis" />
122
   </extension>
123
108
</plugin>
124
</plugin>
(-)tools/pldt/org.eclipse.ptp.pldt.openmp.core/schema/artifactAnalysis.exsd (+88 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.ptp.pldt.mpi.core" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.ptp.pldt.mpi.core" id="artifactAnalysis" name="OpenMP Artifact Analysis"/>
7
      </appInfo>
8
      <documentation>
9
         Allows plug-ins to contribute OpenMP artifact analyses.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <sequence minOccurs="1" maxOccurs="unbounded">
21
            <element ref="artifactAnalysis"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appInfo>
43
                  <meta.attribute translatable="true"/>
44
               </appInfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="artifactAnalysis">
51
      <complexType>
52
         <attribute name="languageID" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appInfo>
58
                  <meta.attribute kind="identifier" basedOn="org.eclipse.cdt.core.language/language/@id"/>
59
               </appInfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="class" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  
66
               </documentation>
67
               <appInfo>
68
                  <meta.attribute kind="java" basedOn=":org.eclipse.ptp.pldt.common.IArtifactAnalysis"/>
69
               </appInfo>
70
            </annotation>
71
         </attribute>
72
      </complexType>
73
   </element>
74
75
   <annotation>
76
      <appInfo>
77
         <meta.section type="since"/>
78
      </appInfo>
79
      <documentation>
80
         6.0
81
      </documentation>
82
   </annotation>
83
84
85
86
87
88
</schema>
(-)tools/pldt/org.eclipse.ptp.pldt.openmp.core/src/org/eclipse/ptp/pldt/openmp/core/actions/RunAnalyseOpenMPcommandHandler.java (-135 / +10 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007,2011 IBM Corporation.
2
 * Copyright (c) 2007, 2011, 2012 IBM Corporation, University of Illinois, and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-48 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Jeff Overbey (UIUC) - modified to use extension point
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
package org.eclipse.ptp.pldt.openmp.core.actions;
12
package org.eclipse.ptp.pldt.openmp.core.actions;
13
13
14
import java.lang.reflect.Method;
15
import java.util.HashMap;
14
import java.util.HashMap;
16
import java.util.Iterator;
15
import java.util.Iterator;
17
import java.util.List;
16
import java.util.List;
18
import java.util.Map;
17
import java.util.Map;
19
18
20
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
21
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
22
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
23
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
24
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
25
import org.eclipse.cdt.core.model.ILanguage;
26
import org.eclipse.cdt.core.model.ITranslationUnit;
19
import org.eclipse.cdt.core.model.ITranslationUnit;
27
import org.eclipse.core.resources.IFile;
28
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IResource;
29
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.ptp.pldt.common.Artifact;
22
import org.eclipse.ptp.pldt.common.Artifact;
31
import org.eclipse.ptp.pldt.common.ScanReturn;
23
import org.eclipse.ptp.pldt.common.ScanReturn;
32
import org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase;
24
import org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase;
33
import org.eclipse.ptp.pldt.common.util.SourceInfo;
34
import org.eclipse.ptp.pldt.common.util.ViewActivator;
25
import org.eclipse.ptp.pldt.common.util.ViewActivator;
35
import org.eclipse.ptp.pldt.openmp.analysis.OpenMPAnalysisManager;
36
import org.eclipse.ptp.pldt.openmp.analysis.OpenMPError;
26
import org.eclipse.ptp.pldt.openmp.analysis.OpenMPError;
37
import org.eclipse.ptp.pldt.openmp.analysis.OpenMPErrorManager;
38
import org.eclipse.ptp.pldt.openmp.analysis.PAST.PASTNode;
39
import org.eclipse.ptp.pldt.openmp.analysis.PAST.PASTPragma;
40
import org.eclipse.ptp.pldt.openmp.core.OpenMPArtifactMarkingVisitor;
27
import org.eclipse.ptp.pldt.openmp.core.OpenMPArtifactMarkingVisitor;
41
import org.eclipse.ptp.pldt.openmp.core.OpenMPPlugin;
28
import org.eclipse.ptp.pldt.openmp.core.OpenMPPlugin;
42
import org.eclipse.ptp.pldt.openmp.core.OpenMPScanReturn;
29
import org.eclipse.ptp.pldt.openmp.core.OpenMPScanReturn;
43
import org.eclipse.ptp.pldt.openmp.core.analysis.OpenMPCASTVisitor;
44
import org.eclipse.ptp.pldt.openmp.core.internal.OpenMPIDs;
30
import org.eclipse.ptp.pldt.openmp.core.internal.OpenMPIDs;
45
import org.eclipse.ptp.pldt.openmp.core.messages.Messages;
46
import org.eclipse.ptp.pldt.openmp.ui.pv.internal.IDs;
31
import org.eclipse.ptp.pldt.openmp.ui.pv.internal.IDs;
47
import org.eclipse.ptp.pldt.openmp.ui.pv.views.ProblemMarkerAttrIds;
32
import org.eclipse.ptp.pldt.openmp.ui.pv.views.ProblemMarkerAttrIds;
48
import org.eclipse.ui.texteditor.MarkerUtilities;
33
import org.eclipse.ui.texteditor.MarkerUtilities;
Lines 53-59 import org.eclipse.ui.texteditor.MarkerUtilities; Link Here
53
 * 
38
 * 
54
 */
39
 */
55
public class RunAnalyseOpenMPcommandHandler extends RunAnalyseHandlerBase {
40
public class RunAnalyseOpenMPcommandHandler extends RunAnalyseHandlerBase {
56
	private static final String OPENMP_DIRECTIVE = Messages.RunAnalyseOpenMPcommandHandler_OpenMP_directive;
41
	/**
42
	 * ID for the extension point which allows plug-ins to contribute OpenMP artifact analyses based on language IDs.
43
	 */
44
	private static final String EXTENSION_POINT_ID = "org.eclipse.ptp.pldt.openmp.core.artifactAnalysis";
45
57
	private static final boolean traceOn = false;
46
	private static final boolean traceOn = false;
58
47
59
	/**
48
	/**
Lines 73-194 public class RunAnalyseOpenMPcommandHandler extends RunAnalyseHandlerBase { Link Here
73
	 */
62
	 */
74
	@Override
63
	@Override
75
	public ScanReturn doArtifactAnalysis(final ITranslationUnit tu, final List<String> includes) {
64
	public ScanReturn doArtifactAnalysis(final ITranslationUnit tu, final List<String> includes) {
76
		OpenMPScanReturn msr = new OpenMPScanReturn();
65
		boolean allowPrefixOnlyMatch = OpenMPPlugin.getDefault().getPreferenceStore().getBoolean(OpenMPIDs.OPENMP_RECOGNIZE_APIS_BY_PREFIX_ALONE);
77
		final String fileName = tu.getElementName();
66
		return runArtifactAnalysisFromExtensionPoint(EXTENSION_POINT_ID, tu, includes, allowPrefixOnlyMatch);
78
		IASTTranslationUnit atu = null;
79
		ILanguage lang;
80
		boolean allowPrefixOnlyMatch = OpenMPPlugin.getDefault().getPreferenceStore()
81
				.getBoolean(OpenMPIDs.OPENMP_RECOGNIZE_APIS_BY_PREFIX_ALONE);
82
		try {
83
			lang = tu.getLanguage();
84
85
			// atu = tu.getAST();
86
			atu = getAST(tu); // use index; was tu.getAST(); otherwise fortran fails?
87
			String languageID = lang.getId();
88
89
			if (languageID.equals(GCCLanguage.ID) || languageID.equals(GPPLanguage.ID)) {
90
				// null IASTTranslationUnit when we're doing C/C++ means we should quit.
91
				// but want to continue to see if this is a fortran file we are analyzing.
92
				if (atu == null) {// this is null for Fortran file during JUnit testing.
93
					System.out.println("RunAnalyseOpenMPCommandHandler.doArtifactAnalysis(), atu is null (testing?)"); //$NON-NLS-1$
94
					return msr;
95
				}
96
			}
97
98
			if (languageID.equals(GCCLanguage.ID)) {// cdt40
99
				atu.accept(new OpenMPCASTVisitor(includes, fileName, allowPrefixOnlyMatch, msr));
100
			} else {
101
				// Attempt to handle Fortran
102
				// Instantiate using reflection to avoid static Photran
103
				// dependencies
104
				try {
105
					Class<?> c = Class.forName("org.eclipse.ptp.pldt.openmp.fortran.actions.AnalyseOpenMPFortranHandler"); //$NON-NLS-1$
106
					Method method = c.getMethod("run", String.class, ITranslationUnit.class, String.class, ScanReturn.class); //$NON-NLS-1$
107
					method.invoke(c.newInstance(), languageID, tu, fileName, msr);
108
				} catch (Exception e) {
109
					System.err.println("RunAnalyseOpenMPcommandHandler.doArtifactAnalysis: Photran not installed"); //$NON-NLS-1$
110
				}
111
			}
112
		} catch (CoreException e) {
113
			// TODO Auto-generated catch block
114
			e.printStackTrace();
115
		}
116
		IResource res = tu.getResource();
117
		IFile file = null;
118
		if (res instanceof IFile) {
119
			file = (IFile) res;
120
		} else {
121
			System.out.println("RunAnalyseOpenMP.doArtifactAnalysis, file cast won't work..."); //$NON-NLS-1$
122
		}
123
		// Find the OpenMP #pragmas
124
		if (atu != null) { // not for Fortran
125
			processOpenMPPragmas(msr, atu, file);
126
		}
127
		return msr;
128
	}
129
130
	/**
131
	 * Special processing to find #pragmas, since the CDT AST does not normally include them.<br>
132
	 * Also adds the "OpenMP Problems"
133
	 * 
134
	 * @param msr
135
	 * @param astTransUnit
136
	 * @param iFile
137
	 */
138
	protected void processOpenMPPragmas(OpenMPScanReturn msr, IASTTranslationUnit astTransUnit, IFile iFile) {
139
		OpenMPAnalysisManager omgr = new OpenMPAnalysisManager(astTransUnit, iFile);
140
		PASTNode[] pList = omgr.getPAST();
141
142
		for (int i = 0; i < pList.length; i++) {// length local=3271; remote 4 (!!)
143
			PASTNode temp = pList[i];
144
			String tempStr = temp.getRawSignature();
145
			// local: will be a PASTOMPPragma node; remote: will be a PASTPragma node.
146
			// So workaround is to accept a PASTPragma node here so we can handle remote files.
147
			// Need to investigate what this does to further analysis e.g. concurrency analysis.
148
			if (pList[i] instanceof PASTPragma) {// was PASTOMPPragma
149
150
				PASTPragma pop = (PASTPragma) pList[i];
151
				if (traceOn) {
152
					System.out.println("found #pragma, line " + pop.getStartingLine()); //$NON-NLS-1$
153
				}
154
				SourceInfo si = getSourceInfo(pop, Artifact.PRAGMA);
155
				String shortName = pop.getContent();
156
				if (shortName.length() == 0) {
157
					shortName = "#pragma"; // HACK: workaround for remote files where getContent() is always empty.
158
					// The same reason why this is empty is also (I think) why it's not a PASTOMPPragma node.
159
					// PASTOMPFactory.parse() always finds empty token first on a remote file, so aborts.
160
				}
161
				Artifact a = new Artifact(pop.getFilename(), pop.getStartingLine(), pop.getStartLocation(), shortName,
162
						OPENMP_DIRECTIVE, si, pop);
163
				msr.addArtifact(a);
164
			}
165
		}
166
167
		msr.addProblems(OpenMPErrorManager.getCurrentErrorManager().getErrors());
168
	}
169
170
	/**
171
	 * Get exact source locational info for a function call
172
	 * 
173
	 * @param pastNode
174
	 * @param constructType
175
	 * @return
176
	 */
177
	private SourceInfo getSourceInfo(PASTNode pastNode, int constructType) {
178
		SourceInfo sourceInfo = null;
179
		IASTNodeLocation[] locations = pastNode.getNodeLocations();
180
		if (locations.length == 1) {
181
			IASTFileLocation astFileLocation = null;
182
			if (locations[0] instanceof IASTFileLocation) {
183
				astFileLocation = (IASTFileLocation) locations[0];
184
				sourceInfo = new SourceInfo();
185
				sourceInfo.setStartingLine(astFileLocation.getStartingLineNumber());
186
				sourceInfo.setStart(astFileLocation.getNodeOffset());
187
				sourceInfo.setEnd(astFileLocation.getNodeOffset() + astFileLocation.getNodeLength());
188
				sourceInfo.setConstructType(constructType);
189
			}
190
		}
191
		return sourceInfo;
192
	}
67
	}
193
68
194
	/**
69
	/**
(-)tools/pldt/org.eclipse.ptp.pldt.openmp.core/src/org/eclipse/ptp/pldt/openmp/core/analysis/OpenMPCArtifactAnalysis.java (+125 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2011, 2012 IBM Corporation, University of Illinois, and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Jeff Overbey (UIUC) - modified to use extension point
11
 *******************************************************************************/
12
package org.eclipse.ptp.pldt.openmp.core.analysis;
13
14
import java.util.List;
15
16
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
17
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
18
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
19
import org.eclipse.cdt.core.model.ITranslationUnit;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.ptp.pldt.common.Artifact;
22
import org.eclipse.ptp.pldt.common.ArtifactAnalysisBase;
23
import org.eclipse.ptp.pldt.common.IArtifactAnalysis;
24
import org.eclipse.ptp.pldt.common.ScanReturn;
25
import org.eclipse.ptp.pldt.common.util.SourceInfo;
26
import org.eclipse.ptp.pldt.openmp.analysis.OpenMPAnalysisManager;
27
import org.eclipse.ptp.pldt.openmp.analysis.OpenMPErrorManager;
28
import org.eclipse.ptp.pldt.openmp.analysis.PAST.PASTNode;
29
import org.eclipse.ptp.pldt.openmp.analysis.PAST.PASTPragma;
30
import org.eclipse.ptp.pldt.openmp.core.OpenMPScanReturn;
31
import org.eclipse.ptp.pldt.openmp.core.messages.Messages;
32
33
/**
34
 * OpenMP artifact analysis for C.
35
 * <p>
36
 * Contributed to the <code>org.eclipse.ptp.pldt.openmp.core.artifactAnalysis</code> extension point.
37
 * 
38
 * @author Beth Tibbitts
39
 * @author Jeff Overbey
40
 */
41
public class OpenMPCArtifactAnalysis extends ArtifactAnalysisBase implements IArtifactAnalysis {
42
43
	private static final String OPENMP_DIRECTIVE = Messages.RunAnalyseOpenMPcommandHandler_OpenMP_directive;
44
45
	public ScanReturn runArtifactAnalysis(String languageID, ITranslationUnit tu, List<String> includes, boolean allowPrefixOnlyMatch) {
46
		final OpenMPScanReturn msr = new OpenMPScanReturn();
47
		final String fileName = tu.getElementName();
48
		final IASTTranslationUnit atu = getAST(tu); // use index; was tu.getAST()
49
		if (atu != null) {
50
			atu.accept(new OpenMPCASTVisitor(includes, fileName, allowPrefixOnlyMatch, msr));
51
52
			// Find the OpenMP #pragmas
53
			if (tu.getResource() instanceof IFile) {
54
				processOpenMPPragmas(msr, atu, (IFile) tu.getResource());
55
			}
56
		}
57
		return msr;
58
	}
59
60
61
	/**
62
	 * Special processing to find #pragmas, since the CDT AST does not normally include them.<br>
63
	 * Also adds the "OpenMP Problems"
64
	 * 
65
	 * @param msr
66
	 * @param astTransUnit
67
	 * @param iFile
68
	 */
69
	protected void processOpenMPPragmas(OpenMPScanReturn msr, IASTTranslationUnit astTransUnit, IFile iFile) {
70
		OpenMPAnalysisManager omgr = new OpenMPAnalysisManager(astTransUnit, iFile);
71
		PASTNode[] pList = omgr.getPAST();
72
73
		for (int i = 0; i < pList.length; i++) {// length local=3271; remote 4 (!!)
74
			PASTNode temp = pList[i];
75
			String tempStr = temp.getRawSignature();
76
			// local: will be a PASTOMPPragma node; remote: will be a PASTPragma node.
77
			// So workaround is to accept a PASTPragma node here so we can handle remote files.
78
			// Need to investigate what this does to further analysis e.g. concurrency analysis.
79
			if (pList[i] instanceof PASTPragma) {// was PASTOMPPragma
80
81
				PASTPragma pop = (PASTPragma) pList[i];
82
				//if (traceOn) {
83
				//	System.out.println("found #pragma, line " + pop.getStartingLine()); //$NON-NLS-1$
84
				//}
85
				SourceInfo si = getSourceInfo(pop, Artifact.PRAGMA);
86
				String shortName = pop.getContent();
87
				if (shortName.length() == 0) {
88
					shortName = "#pragma"; // HACK: workaround for remote files where getContent() is always empty.
89
					// The same reason why this is empty is also (I think) why it's not a PASTOMPPragma node.
90
					// PASTOMPFactory.parse() always finds empty token first on a remote file, so aborts.
91
				}
92
				Artifact a = new Artifact(pop.getFilename(), pop.getStartingLine(), pop.getStartLocation(), shortName,
93
						OPENMP_DIRECTIVE, si, pop);
94
				msr.addArtifact(a);
95
			}
96
		}
97
98
		msr.addProblems(OpenMPErrorManager.getCurrentErrorManager().getErrors());
99
	}
100
101
102
	/**
103
	 * Get exact source locational info for a function call
104
	 * 
105
	 * @param pastNode
106
	 * @param constructType
107
	 * @return
108
	 */
109
	private SourceInfo getSourceInfo(PASTNode pastNode, int constructType) {
110
		SourceInfo sourceInfo = null;
111
		IASTNodeLocation[] locations = pastNode.getNodeLocations();
112
		if (locations.length == 1) {
113
			IASTFileLocation astFileLocation = null;
114
			if (locations[0] instanceof IASTFileLocation) {
115
				astFileLocation = (IASTFileLocation) locations[0];
116
				sourceInfo = new SourceInfo();
117
				sourceInfo.setStartingLine(astFileLocation.getStartingLineNumber());
118
				sourceInfo.setStart(astFileLocation.getNodeOffset());
119
				sourceInfo.setEnd(astFileLocation.getNodeOffset() + astFileLocation.getNodeLength());
120
				sourceInfo.setConstructType(constructType);
121
			}
122
		}
123
		return sourceInfo;
124
	}
125
}
(-)tools/pldt/org.eclipse.ptp.pldt.openmp.fortran/build.properties (-1 / +2 lines)
Lines 3-6 output.. = bin/ Link Here
3
bin.includes = META-INF/,\
3
bin.includes = META-INF/,\
4
               .,\
4
               .,\
5
               plugin.properties,\
5
               plugin.properties,\
6
               about.html
6
               about.html,\
7
               plugin.xml
(-)tools/pldt/org.eclipse.ptp.pldt.openmp.fortran/plugin.xml (+12 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
5
   <!-- OpenMP artifact analysis for Fortran -->
6
   <extension point="org.eclipse.ptp.pldt.openmp.core.artifactAnalysis">
7
      <artifactAnalysis
8
            languageID="org.eclipse.photran.cdtinterface.fortran"
9
            class="org.eclipse.ptp.pldt.openmp.fortran.analysis.OpenMPFortranArtifactAnalysis" />
10
   </extension>
11
12
</plugin>
(-)tools/pldt/org.eclipse.ptp.pldt.openmp.fortran/src/org/eclipse/ptp/pldt/openmp/fortran/actions/AnalyseOpenMPFortranHandler.java (-43 lines)
Lines 1-43 Link Here
1
/**********************************************************************
2
 * Copyright (c) 2010 IBM Corporation.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ptp.pldt.openmp.fortran.actions;
13
14
import org.eclipse.cdt.core.model.ITranslationUnit;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.photran.internal.cdtinterface.core.FortranLanguage;
18
import org.eclipse.photran.internal.core.lexer.ASTLexerFactory;
19
import org.eclipse.photran.internal.core.parser.ASTExecutableProgramNode;
20
import org.eclipse.photran.internal.core.parser.Parser;
21
import org.eclipse.ptp.pldt.common.ScanReturn;
22
import org.eclipse.ptp.pldt.openmp.fortran.analysis.OpenMPFortranASTVisitor;
23
24
/**
25
 * @since 4.0
26
 */
27
public class AnalyseOpenMPFortranHandler {
28
	public void run(String languageID, ITranslationUnit tu, String fileName, ScanReturn msr) {
29
		if (languageID.equals(FortranLanguage.LANGUAGE_ID)) {
30
			IResource res = tu.getUnderlyingResource();
31
			if (!(res instanceof IFile))
32
				throw new IllegalStateException();
33
			IFile file = (IFile) res;
34
35
			try {
36
				ASTExecutableProgramNode ast = new Parser().parse(new ASTLexerFactory().createLexer(file));
37
				ast.accept(new OpenMPFortranASTVisitor(fileName, msr));
38
			} catch (Exception e) {
39
				e.printStackTrace(); // TODO
40
			}
41
		}
42
	}
43
}
(-)tools/pldt/org.eclipse.ptp.pldt.openmp.fortran/src/org/eclipse/ptp/pldt/openmp/fortran/analysis/OpenMPFortranArtifactAnalysis.java (+51 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 University of Illinois at Urbana-Champaign and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     UIUC - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ptp.pldt.openmp.fortran.analysis;
12
13
import java.util.List;
14
15
import org.eclipse.cdt.core.model.ITranslationUnit;
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.photran.internal.cdtinterface.core.FortranLanguage;
19
import org.eclipse.photran.internal.core.lexer.ASTLexerFactory;
20
import org.eclipse.photran.internal.core.parser.ASTExecutableProgramNode;
21
import org.eclipse.photran.internal.core.parser.Parser;
22
import org.eclipse.ptp.pldt.common.IArtifactAnalysis;
23
import org.eclipse.ptp.pldt.common.ScanReturn;
24
25
/**
26
 * OpenMP artifact analysis for Fortran.
27
 * <p>
28
 * Contributed to the <code>org.eclipse.ptp.pldt.mpi.core.artifactAnalysis</code> extension point.
29
 * 
30
 * @author Jeff Overbey
31
 */
32
public class OpenMPFortranArtifactAnalysis implements IArtifactAnalysis {
33
	public ScanReturn runArtifactAnalysis(String languageID, ITranslationUnit tu, List<String> includes, boolean allowPrefixOnlyMatch) {
34
		final ScanReturn msr = new ScanReturn();
35
		final String fileName = tu.getElementName();
36
		if (languageID.equals(FortranLanguage.LANGUAGE_ID)) {
37
			IResource res = tu.getUnderlyingResource();
38
			if (!(res instanceof IFile))
39
				throw new IllegalStateException();
40
			IFile file = (IFile) res;
41
42
			try {
43
				ASTExecutableProgramNode ast = new Parser().parse(new ASTLexerFactory().createLexer(file));
44
				ast.accept(new OpenMPFortranASTVisitor(fileName, msr));
45
			} catch (Exception e) {
46
				e.printStackTrace(); // TODO
47
			}
48
		}
49
		return msr;
50
	}
51
}

Return to bug 373597