Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b798fc5cb8dd1a597cd9cfe0b0010148e0fde2f5 (plain) (blame)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*******************************************************************************
 * Copyright (c) 2007, 2015 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
 *     Markus Schorn (Wind River Systems)
 *     Richard Eames
 *******************************************************************************/
package org.eclipse.cdt.core.dom.parser;

import java.util.ArrayList;

import org.eclipse.cdt.core.parser.IMacro;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;

/**
 * Abstract scanner extension configuration to help model C/C++ dialects.
 * @since 4.0
 */
public abstract class AbstractScannerExtensionConfiguration implements IScannerExtensionConfiguration {
	private static final IMacro[] EMPTY_MACRO_ARRAY = new IMacro[0];
	private ArrayList<IMacro> fAddMacroList;
	private IMacro[] fAddMacros;
	private CharArrayIntMap fAddKeywords;
	private CharArrayIntMap fAddPreprocessorKeywords;
	
	protected static class MacroDefinition implements IMacro {
		private final char[] fSignature;
		private final char[] fExpansion;
		
		MacroDefinition(char[] signature, char[] expansion) {
			fSignature= signature;
			fExpansion= expansion;
		}
		
		@Override
		public char[] getSignature() {
			return fSignature;
		}
		@Override
		public char[] getExpansion() {
			return fExpansion;
		}
	}

	public AbstractScannerExtensionConfiguration() {
	}
	
	/*
	 * @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#support$InIdentifiers()
	 */
	@Override
	public boolean support$InIdentifiers() {
		return false;
	}

	/**
	 * {@inheritDoc}
	 * @since 5.1
	 */
	@Override
	public boolean supportAtSignInIdentifiers() {
		return false;
	}
	
	
	/**
	 * {@inheritDoc}
	 * @since 5.1
	 */
	@Override
	public boolean supportUTFLiterals() {
		return true;
	}
	
	
	/**
	 * {@inheritDoc}
	 * @since 5.1
	 */
	@Override
	public boolean supportSlashPercentComments() {
		return false;
	}

	/*
	 * @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#supportAdditionalNumericLiteralSuffixes()
	 */
	@Override
	public char[] supportAdditionalNumericLiteralSuffixes() {
		return null;
	}

	/*
	 * @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#supportMinAndMaxOperators()
	 */
	@Override
	public boolean supportMinAndMaxOperators() {
		return false;
	}

	/**
	 * @since 5.5
	 */
	@Override
	public boolean supportRawStringLiterals() {
		return false;
	}
	
	/**
	 * {@inheritDoc}
	 * @since 5.11
	 */
	@Override
	public boolean supportUserDefinedLiterals() {
		return false;
	}
	
	@Override
	public CharArrayIntMap getAdditionalPreprocessorKeywords() {
		return fAddPreprocessorKeywords;
	}
	
	@Override
	public CharArrayIntMap getAdditionalKeywords() {
		return fAddKeywords;
	}

	@Override
	public IMacro[] getAdditionalMacros() {
		if (fAddMacros == null) {
			if (fAddMacroList == null) {
				fAddMacros= EMPTY_MACRO_ARRAY;
			} else {
				fAddMacros= fAddMacroList.toArray(new IMacro[fAddMacroList.size()]);
			}
		}
		return fAddMacros;
	}

	/**
	 * Adds a macro to the list of additional macros. 
	 * The macro can either be of object- or of function-style.
	 * <pre>
	 * Example:
	 *    addMacro("max(a,b)", "(((a)>(b) ? (a) : (b))");
	 * </pre>
	 * @param signature the signature of the macro, see {@link IMacro#getSignature()}.
	 * @param value the macro value
	 * @since 5.1
	 */
	protected void addMacro(String signature, String value) {
		if (fAddMacroList == null) {
			fAddMacroList= new ArrayList<IMacro>();
		}
		fAddMacroList.add(new MacroDefinition(signature.toCharArray(), value.toCharArray()));
		fAddMacros= null;
	}
	
	/**
	 * Adds a preprocessor keyword to the map of additional preprocessor keywords. 
	 * @param name the name of the keyword
	 * @param tokenKind the kind of token the keyword is mapped to. See {@link IToken}.
	 * @since 5.1
	 */
	protected void addPreprocessorKeyword(char[] name, int tokenKind) {
		if (fAddPreprocessorKeywords == null) {
			fAddPreprocessorKeywords= new CharArrayIntMap(10, -1);
		}
		fAddPreprocessorKeywords.put(name, tokenKind);
	}

	/**
	 * Adds a  keyword to the map of additional keywords. 
	 * @param name the name of the keyword
	 * @param tokenKind the kind of token the keyword is mapped to. See {@link IToken}.
	 * @since 5.1
	 */
	protected void addKeyword(char[] name, int tokenKind) {
		if (fAddKeywords == null) {
			fAddKeywords= new CharArrayIntMap(10, -1);
		}
		fAddKeywords.put(name, tokenKind);
	}

	/**
	 * @deprecated use {@link #addMacro(String, String)}
	 */
	@Deprecated
	protected static IMacro createMacro(String signature, String value) {
		return new MacroDefinition(signature.toCharArray(), value.toCharArray());
	}

	/**
	 * @deprecated use {@link #addMacro(String, String)}
	 */
	@Deprecated
	protected static IMacro createFunctionStyleMacro(String name, String value, String[] arguments) {
		StringBuffer buf= new StringBuffer();
		buf.append(name);
		buf.append('(');
		for (int i = 0; i < arguments.length; i++) {
			if (i>0) {
				buf.append(',');
			}
			buf.append(arguments[i]);
		}
		buf.append(')');
		char[] signature= new char[buf.length()];
		buf.getChars(0, signature.length, signature, 0);
		return new MacroDefinition(signature, value.toCharArray());
	}
	
	/**
	 * @deprecated see {@link IScannerExtensionConfiguration#initializeMacroValuesTo1()}
	 */
	@Override
	@Deprecated
	public boolean initializeMacroValuesTo1() {
		return false;
	}

}

Back to the top