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 |
/** |