1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*******************************************************************************
* Copyright (c) 2009, 2012 Andrew Gvozdev and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrew Gvozdev - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.xlc.core;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditableProvider;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.managedbuilder.language.settings.providers.ToolchainBuiltinSpecsDetector;
/**
* Language settings provider to detect built-in compiler settings for IBM XLC compiler.
*/
public class XlcBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector
implements ILanguageSettingsEditableProvider {
// must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point
private static final String XLC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.xlc.exe.debug"; //$NON-NLS-1$
private static final Pattern OPTIONS_PATTERN = Pattern
.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$
private static final int OPTION_GROUP = 0;
/* Sample output:
> xlC -E -V -P -w ~/tmp/spec.C
export XL_CONFIG=/etc/vac.cfg:xlC
/usr/vac/exe/xlCcpp /home/me/tmp/spec.C - -qc++=/usr/vacpp/include -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX50 -D_AIX51 -D_AIX52 -D_IBMR2 -D_POWER -E -P -w -qlanglvl=ansi -qansialias
rm /tmp/xlcW0lt4Jia
rm /tmp/xlcW1lt4Jib
rm /tmp/xlcW2lt4Jic
*/
@SuppressWarnings("nls")
private static final AbstractOptionParser[] optionParsers = {
new IncludePathOptionParser("-I\\s*([\"'])(.*)\\1", "$2",
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL),
new IncludePathOptionParser("-I\\s*([^\\s\"']*)", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
new IncludePathOptionParser("-qc\\+\\+=\\s*([^\\s\"']*)", "$1",
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
new MacroOptionParser("-D\\s*([\"'])([^=]*)(=(.*))?\\1", "$2", "$4",
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
new MacroOptionParser("-D\\s*([^\\s=\"']*)=(\\\\([\"']))(.*?)\\2", "$1", "$3$4$3",
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
new MacroOptionParser("-D\\s*([^\\s=\"']*)=([\"'])(.*?)\\2", "$1", "$3",
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
new MacroOptionParser("-D\\s*([^\\s=\"']*)(=([^\\s\"']*))?", "$1", "$3",
ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), };
@Override
public String getToolchainId() {
return XLC_TOOLCHAIN_ID;
}
@Override
protected AbstractOptionParser[] getOptionParsers() {
return optionParsers;
}
@Override
protected List<String> parseOptions(String line) {
List<String> options = new ArrayList<>();
Matcher optionMatcher = OPTIONS_PATTERN.matcher(line);
while (optionMatcher.find()) {
String option = optionMatcher.group(OPTION_GROUP);
if (option != null) {
options.add(option);
}
}
return options;
}
@Override
public XlcBuiltinSpecsDetector cloneShallow() throws CloneNotSupportedException {
return (XlcBuiltinSpecsDetector) super.cloneShallow();
}
@Override
public XlcBuiltinSpecsDetector clone() throws CloneNotSupportedException {
return (XlcBuiltinSpecsDetector) super.clone();
}
}
|