mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 22:35:43 +02:00
Extends IMacroBinding and the CharArrayUtils, also adding java-doc for some of the API.
This commit is contained in:
parent
3381fad4e4
commit
f80b1e7e37
8 changed files with 195 additions and 32 deletions
|
@ -1,20 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 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:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
/**
|
||||
* The exception is thrown when a completion is requested within one of the following constructs:
|
||||
* <p> character-literal, string-literal, comment, preprocessing directive, macro-expansion.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class CompletionInPreprocessorException extends Exception {
|
||||
|
||||
}
|
|
@ -52,6 +52,9 @@ public interface IScanner extends IMacroCollector {
|
|||
public IToken nextToken() throws EndOfFileException;
|
||||
|
||||
public int getCount();
|
||||
/**
|
||||
* Returns <code>true</code>, whenever we are processing the outermost file of the translation unit.
|
||||
*/
|
||||
public boolean isOnTopContext();
|
||||
public CharArrayObjectMap getRealDefinitions();
|
||||
public void cancel();
|
||||
|
|
|
@ -41,6 +41,8 @@ public interface IToken {
|
|||
|
||||
|
||||
// Token types
|
||||
int FIRST_RESERVED_PREPROCESSOR= -200;
|
||||
int LAST_RESERVED_PREPROCESSOR= -101;
|
||||
int FIRST_RESERVED_SCANNER= -100;
|
||||
int LAST_RESERVED_SCANNER= -1;
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
|
@ -229,9 +231,9 @@ public class Keywords {
|
|||
public static final char[] cpDOT = ".".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cpDIVASSIGN = "/=".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cpDIV = "/".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cpBACKSLASH = "\\".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cpPOUND = "#".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cpPOUNDPOUND = "##".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cpBACKSLASH = "\\".toCharArray(); //$NON-NLS-1$
|
||||
|
||||
// gcc extensions
|
||||
public static final char[] cpMIN = "<?".toCharArray(); //$NON-NLS-1$
|
||||
|
@ -248,6 +250,9 @@ public class Keywords {
|
|||
public static final char[] cERROR = "error".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cPRAGMA = "pragma".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cLINE = "line".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cDEFINED= "defined".toCharArray(); //$NON-NLS-1$
|
||||
|
||||
public static final char[] cVA_ARGS= "__VA_ARGS__".toCharArray(); //$NON-NLS-1$
|
||||
|
||||
// preprocessor extensions (supported by GCC)
|
||||
public static final char[] cINCLUDE_NEXT = "include_next".toCharArray(); //$NON-NLS-1$
|
||||
|
@ -257,4 +262,122 @@ public class Keywords {
|
|||
public static final char[] cWARNING = "warning".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cASSERT = "assert".toCharArray(); //$NON-NLS-1$
|
||||
public static final char[] cUNASSERT = "unassert".toCharArray(); //$NON-NLS-1$
|
||||
|
||||
public static void addKeywordsC(CharArrayIntMap kw) {
|
||||
addCommon(kw);
|
||||
addC(kw);
|
||||
}
|
||||
|
||||
public static void addKeywordsCpp(CharArrayIntMap kw) {
|
||||
addCommon(kw);
|
||||
addCpp(kw);
|
||||
}
|
||||
|
||||
|
||||
private static void addCommon(CharArrayIntMap words) {
|
||||
words.put(Keywords.cAUTO, IToken.t_auto);
|
||||
words.put(Keywords.cBREAK, IToken.t_break);
|
||||
words.put(Keywords.cCASE, IToken.t_case);
|
||||
words.put(Keywords.cCHAR, IToken.t_char);
|
||||
words.put(Keywords.cCONST, IToken.t_const);
|
||||
words.put(Keywords.cCONTINUE, IToken.t_continue);
|
||||
words.put(Keywords.cDEFAULT, IToken.t_default);
|
||||
words.put(Keywords.cDO, IToken.t_do);
|
||||
words.put(Keywords.cDOUBLE, IToken.t_double);
|
||||
words.put(Keywords.cELSE, IToken.t_else);
|
||||
words.put(Keywords.cENUM, IToken.t_enum);
|
||||
words.put(Keywords.cEXTERN, IToken.t_extern);
|
||||
words.put(Keywords.cFLOAT, IToken.t_float);
|
||||
words.put(Keywords.cFOR, IToken.t_for);
|
||||
words.put(Keywords.cGOTO, IToken.t_goto);
|
||||
words.put(Keywords.cIF, IToken.t_if);
|
||||
words.put(Keywords.cINLINE, IToken.t_inline);
|
||||
words.put(Keywords.cINT, IToken.t_int);
|
||||
words.put(Keywords.cLONG, IToken.t_long);
|
||||
words.put(Keywords.cREGISTER, IToken.t_register);
|
||||
words.put(Keywords.cRETURN, IToken.t_return);
|
||||
words.put(Keywords.cSHORT, IToken.t_short);
|
||||
words.put(Keywords.cSIGNED, IToken.t_signed);
|
||||
words.put(Keywords.cSIZEOF, IToken.t_sizeof);
|
||||
words.put(Keywords.cSTATIC, IToken.t_static);
|
||||
words.put(Keywords.cSTRUCT, IToken.t_struct);
|
||||
words.put(Keywords.cSWITCH, IToken.t_switch);
|
||||
words.put(Keywords.cTYPEDEF, IToken.t_typedef);
|
||||
words.put(Keywords.cUNION, IToken.t_union);
|
||||
words.put(Keywords.cUNSIGNED, IToken.t_unsigned);
|
||||
words.put(Keywords.cVOID, IToken.t_void);
|
||||
words.put(Keywords.cVOLATILE, IToken.t_volatile);
|
||||
words.put(Keywords.cWHILE, IToken.t_while);
|
||||
words.put(Keywords.cASM, IToken.t_asm);
|
||||
}
|
||||
|
||||
// ANSI C keywords
|
||||
private static void addC(CharArrayIntMap ckeywords) {
|
||||
ckeywords.put(Keywords.cRESTRICT, IToken.t_restrict);
|
||||
ckeywords.put(Keywords.c_BOOL, IToken.t__Bool);
|
||||
ckeywords.put(Keywords.c_COMPLEX, IToken.t__Complex);
|
||||
ckeywords.put(Keywords.c_IMAGINARY, IToken.t__Imaginary);
|
||||
}
|
||||
|
||||
private static void addCpp(CharArrayIntMap cppkeywords) {
|
||||
cppkeywords.put(Keywords.cBOOL, IToken.t_bool);
|
||||
cppkeywords.put(Keywords.cCATCH, IToken.t_catch);
|
||||
cppkeywords.put(Keywords.cCLASS, IToken.t_class);
|
||||
cppkeywords.put(Keywords.cCONST_CAST, IToken.t_const_cast);
|
||||
cppkeywords.put(Keywords.cDELETE, IToken.t_delete);
|
||||
cppkeywords.put(Keywords.cDYNAMIC_CAST, IToken.t_dynamic_cast);
|
||||
cppkeywords.put(Keywords.cEXPLICIT, IToken.t_explicit);
|
||||
cppkeywords.put(Keywords.cEXPORT, IToken.t_export);
|
||||
cppkeywords.put(Keywords.cFALSE, IToken.t_false);
|
||||
cppkeywords.put(Keywords.cFRIEND, IToken.t_friend);
|
||||
cppkeywords.put(Keywords.cMUTABLE, IToken.t_mutable);
|
||||
cppkeywords.put(Keywords.cNAMESPACE, IToken.t_namespace);
|
||||
cppkeywords.put(Keywords.cNEW, IToken.t_new);
|
||||
cppkeywords.put(Keywords.cOPERATOR, IToken.t_operator);
|
||||
cppkeywords.put(Keywords.cPRIVATE, IToken.t_private);
|
||||
cppkeywords.put(Keywords.cPROTECTED, IToken.t_protected);
|
||||
cppkeywords.put(Keywords.cPUBLIC, IToken.t_public);
|
||||
cppkeywords.put(Keywords.cREINTERPRET_CAST, IToken.t_reinterpret_cast);
|
||||
cppkeywords.put(Keywords.cSTATIC_CAST, IToken.t_static_cast);
|
||||
cppkeywords.put(Keywords.cTEMPLATE, IToken.t_template);
|
||||
cppkeywords.put(Keywords.cTHIS, IToken.t_this);
|
||||
cppkeywords.put(Keywords.cTHROW, IToken.t_throw);
|
||||
cppkeywords.put(Keywords.cTRUE, IToken.t_true);
|
||||
cppkeywords.put(Keywords.cTRY, IToken.t_try);
|
||||
cppkeywords.put(Keywords.cTYPEID, IToken.t_typeid);
|
||||
cppkeywords.put(Keywords.cTYPENAME, IToken.t_typename);
|
||||
cppkeywords.put(Keywords.cUSING, IToken.t_using);
|
||||
cppkeywords.put(Keywords.cVIRTUAL, IToken.t_virtual);
|
||||
cppkeywords.put(Keywords.cWCHAR_T, IToken.t_wchar_t);
|
||||
|
||||
// C++ operator alternative
|
||||
cppkeywords.put(Keywords.cAND, IToken.tAND);
|
||||
cppkeywords.put(Keywords.cAND_EQ, IToken.tAMPERASSIGN);
|
||||
cppkeywords.put(Keywords.cBITAND, IToken.tAMPER);
|
||||
cppkeywords.put(Keywords.cBITOR, IToken.tBITOR);
|
||||
cppkeywords.put(Keywords.cCOMPL, IToken.tBITCOMPLEMENT);
|
||||
cppkeywords.put(Keywords.cNOT, IToken.tNOT);
|
||||
cppkeywords.put(Keywords.cNOT_EQ, IToken.tNOTEQUAL);
|
||||
cppkeywords.put(Keywords.cOR, IToken.tOR);
|
||||
cppkeywords.put(Keywords.cOR_EQ, IToken.tBITORASSIGN);
|
||||
cppkeywords.put(Keywords.cXOR, IToken.tXOR);
|
||||
cppkeywords.put(Keywords.cXOR_EQ, IToken.tXORASSIGN);
|
||||
}
|
||||
|
||||
public static void addKeywordsPreprocessor(CharArrayIntMap ppKeywords) {
|
||||
// Preprocessor keywords
|
||||
ppKeywords = new CharArrayIntMap(16, IPreprocessorDirective.ppInvalid);
|
||||
ppKeywords.put(Keywords.cIF, IPreprocessorDirective.ppIf);
|
||||
ppKeywords.put(Keywords.cIFDEF, IPreprocessorDirective.ppIfdef);
|
||||
ppKeywords.put(Keywords.cIFNDEF, IPreprocessorDirective.ppIfndef);
|
||||
ppKeywords.put(Keywords.cELIF, IPreprocessorDirective.ppElif);
|
||||
ppKeywords.put(Keywords.cELSE, IPreprocessorDirective.ppElse);
|
||||
ppKeywords.put(Keywords.cENDIF, IPreprocessorDirective.ppEndif);
|
||||
ppKeywords.put(Keywords.cINCLUDE, IPreprocessorDirective.ppInclude);
|
||||
ppKeywords.put(Keywords.cDEFINE, IPreprocessorDirective.ppDefine);
|
||||
ppKeywords.put(Keywords.cUNDEF, IPreprocessorDirective.ppUndef);
|
||||
ppKeywords.put(Keywords.cERROR, IPreprocessorDirective.ppError);
|
||||
ppKeywords.put(Keywords.cPRAGMA, IPreprocessorDirective.ppPragma);
|
||||
ppKeywords.put(Keywords.cLINE, IPreprocessorDirective.ppIgnore);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,27 +13,58 @@ package org.eclipse.cdt.core.parser;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
* The exception is thrown, when content-assist is requested within a context that is handled
|
||||
* by the lexer or the preprocessor.
|
||||
* <p>
|
||||
* {@link #ORIGIN_LEXER}: char-literal, string-literal, number-literal, header-name.
|
||||
* <p>
|
||||
* {@link #ORIGIN_PREPROCESSOR}: preprocessor-directive.
|
||||
* <p>
|
||||
* {@link #ORIGIN_INACTIVE_CODE}: within an inactive branch of conditional compilation.
|
||||
* <p>
|
||||
* {@link #ORIGIN_MACRO_EXPANSION}: within a macro-expansion.
|
||||
*/
|
||||
public class OffsetLimitReachedException extends EndOfFileException {
|
||||
|
||||
private static final long serialVersionUID= -4315255081891716385L;
|
||||
|
||||
public static final int ORIGIN_UNKNOWN = 0;
|
||||
public static final int ORIGIN_LEXER = 1;
|
||||
public static final int ORIGIN_PREPROCESSOR_DIRECTIVE = 2;
|
||||
public static final int ORIGIN_INACTIVE_CODE = 3;
|
||||
public static final int ORIGIN_MACRO_EXPANSION = 4;
|
||||
|
||||
private final IASTCompletionNode node;
|
||||
private final IToken finalToken;
|
||||
private final int fOrigin;
|
||||
|
||||
public OffsetLimitReachedException( IASTCompletionNode node )
|
||||
{
|
||||
this.node = node;
|
||||
finalToken = null;
|
||||
fOrigin= ORIGIN_UNKNOWN;
|
||||
}
|
||||
|
||||
public OffsetLimitReachedException( IToken token )
|
||||
public OffsetLimitReachedException( IToken token )
|
||||
{
|
||||
fOrigin= ORIGIN_UNKNOWN;
|
||||
finalToken = token;
|
||||
node = null;
|
||||
}
|
||||
|
||||
public OffsetLimitReachedException(int origin, IToken lastToken) {
|
||||
fOrigin= origin;
|
||||
finalToken= lastToken;
|
||||
node= null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns one of ORIGIN_...
|
||||
*/
|
||||
public int getOriginator() {
|
||||
return fOrigin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the finalToken.
|
||||
*/
|
||||
|
@ -48,9 +79,4 @@ public class OffsetLimitReachedException extends EndOfFileException {
|
|||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -74,11 +74,18 @@ public class CharArrayIntMap extends CharTable {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param image
|
||||
* @return
|
||||
*/
|
||||
public int get(char[] image) {
|
||||
return get( image, 0, image.length );
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts all mappings of map into this map. The keys are not cloned.
|
||||
* @since 5.0
|
||||
*/
|
||||
public void putAll(CharArrayIntMap map) {
|
||||
resize(size() + map.size());
|
||||
for(int i=0; i<map.currEntry; i++) {
|
||||
put(map.keyTable[i], map.valueTable[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -305,4 +305,17 @@ public class CharArrayUtils {
|
|||
buff[ i + j ] = charImage[j];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an array of chars in an array of arrays of chars.
|
||||
* @return offset where the array was found or <code>-1</code>
|
||||
*/
|
||||
public static int indexOf(final char[] searchFor, final char[][] searchIn) {
|
||||
for (int i=0; i < searchIn.length; i++) {
|
||||
if (equals(searchIn[i], searchFor)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap._FunctionMacroDefinition;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
public class MacroBinding extends PlatformObject implements IMacroBinding {
|
||||
|
@ -53,4 +54,12 @@ public class MacroBinding extends PlatformObject implements IMacroBinding {
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.NO_LINKAGE;
|
||||
}
|
||||
|
||||
public char[] getExpansion() {
|
||||
return definition.getExpansion();
|
||||
}
|
||||
|
||||
public boolean isFunctionStyle() {
|
||||
return definition instanceof _FunctionMacroDefinition;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue