Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2003-03-03 17:04:40 -0500
committerDoug Schaefer2003-03-03 17:04:40 -0500
commit2d8ecfb1b17297e2e11dadd3a012e0e3e58572d9 (patch)
treed208c66a46074149aa01292305b893993006f1f7
parent890defd85d8232383c8610497a236f17cdfc5c22 (diff)
downloadorg.eclipse.cdt-2d8ecfb1b17297e2e11dadd3a012e0e3e58572d9.tar.gz
org.eclipse.cdt-2d8ecfb1b17297e2e11dadd3a012e0e3e58572d9.tar.xz
org.eclipse.cdt-2d8ecfb1b17297e2e11dadd3a012e0e3e58572d9.zip
Patch for John Camelon:
- some of the outline view going with new parser
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/DOMBuilder.java15
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/ParameterDeclaration.java6
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java6
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java22
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/Parameter.java7
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java7
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/IParserCallback.java9
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/NullParserCallback.java9
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Parser.java137
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Scanner.java29
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclSpecifier.java3
-rw-r--r--core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclarationSpecifier.java1
12 files changed, 181 insertions, 70 deletions
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/DOMBuilder.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/DOMBuilder.java
index 6aa799fcc8..f3f70a073c 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/DOMBuilder.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/DOMBuilder.java
@@ -137,7 +137,7 @@ public class DOMBuilder implements IParserCallback
/**
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#inclusionBegin(java.lang.String)
*/
- public void inclusionBegin(String includeFile) {
+ public void inclusionBegin(String includeFile, int offset) {
}
/**
@@ -149,7 +149,7 @@ public class DOMBuilder implements IParserCallback
/**
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#macro(java.lang.String)
*/
- public void macro(String macroName) {
+ public void macro(String macroName, int offset) {
}
/**
@@ -252,4 +252,15 @@ public class DOMBuilder implements IParserCallback
public void parameterDeclarationEnd( Object declaration ){
}
+ /**
+ * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object)
+ */
+ public void declaratorAbort(Object container, Object declarator) {
+ DeclarationSpecifier.Container decl = (DeclarationSpecifier.Container )container;
+ Declarator toBeRemoved = (Declarator)declarator;
+ decl.removeDeclarator( toBeRemoved );
+ currName = null;
+ toBeRemoved = null;
+ }
+
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/ParameterDeclaration.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/ParameterDeclaration.java
index 85e8e4241f..edf4664476 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/ParameterDeclaration.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/ParameterDeclaration.java
@@ -43,4 +43,10 @@ public class ParameterDeclaration extends Declaration implements DeclarationSpec
return declarators;
}
+ /**
+ * @see org.eclipse.cdt.internal.core.newparser.util.DeclarationSpecifier.Container#removeDeclarator(java.lang.Object)
+ */
+ public void removeDeclarator(Object declarator) {
+ declarators.remove( declarator );
+ }
}
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java
index 355bacd249..4dc9bd1afa 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java
@@ -54,4 +54,10 @@ public class SimpleDeclaration extends Declaration implements DeclarationSpecifi
return declarators;
}
+ /**
+ * @see org.eclipse.cdt.internal.core.newparser.util.DeclarationSpecifier.Container#removeDeclarator(java.lang.Object)
+ */
+ public void removeDeclarator(Object declarator) {
+ declarators.remove( declarator );
+ }
}
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java
index 7216d6b17b..3688c969a2 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java
@@ -114,9 +114,13 @@ public class NewModelBuilder implements IParserCallback {
/**
* @see org.eclipse.cdt.core.newparser.IParserCallback#macro(String)
*/
- public void macro(String macroName) {
+ public void macro(String macroName, int offset) {
Macro elem = new Macro((TranslationUnit)translationUnit.getElement(), macroName);
+ elem.setIdPos(offset, macroName.length());
+ elem.setPos(offset, macroName.length());
+
((TranslationUnit)translationUnit.getElement()).addChild(elem);
+
}
private int startPos;
@@ -141,9 +145,12 @@ org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(T
/**
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#beginInclusion(String)
*/
- public void inclusionBegin(String includeFile) {
+ public void inclusionBegin(String includeFile, int offset) {
Include elem = new Include(((TranslationUnit)translationUnit.getElement()), includeFile);
((TranslationUnit)translationUnit.getElement()).addChild(elem);
+ elem.setIdPos(offset, includeFile.length());
+ elem.setPos(offset, includeFile.length());
+
}
/**
@@ -285,4 +292,15 @@ org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(T
public void argumentsEnd(Object parameterDeclarationClause) {
}
+ /**
+ * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object)
+ */
+ public void declaratorAbort(Object container, Object declarator) {
+ DeclarationSpecifier.Container declSpec = (DeclarationSpecifier.Container)container;
+ Declarator toBeRemoved =(Declarator)declarator;
+ declSpec.removeDeclarator( toBeRemoved );
+ toBeRemoved = null;
+ currName = null;
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/Parameter.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/Parameter.java
index b4c24682ef..8492d69943 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/Parameter.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/Parameter.java
@@ -43,4 +43,11 @@ public class Parameter extends DeclSpecifier implements DeclarationSpecifier.Con
public List getDeclarators() {
return declarators;
}
+
+ /**
+ * @see org.eclipse.cdt.internal.core.newparser.util.DeclarationSpecifier.Container#removeDeclarator(java.lang.Object)
+ */
+ public void removeDeclarator(Object declarator) {
+ declarators.remove( declarator );
+ }
}
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java
index 65add198e6..22edcb64ca 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java
@@ -153,4 +153,11 @@ currentDeclarator.getName().getEndOffset(),currentDeclarator.getName().toString(
declSpec = in;
}
+ /**
+ * @see org.eclipse.cdt.internal.core.newparser.util.DeclarationSpecifier.Container#removeDeclarator(java.lang.Object)
+ */
+ public void removeDeclarator(Object declarator) {
+ declarators.remove( declarator );
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/IParserCallback.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/IParserCallback.java
index 5e6b2fb378..d903987683 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/IParserCallback.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/IParserCallback.java
@@ -15,9 +15,9 @@ public interface IParserCallback {
public Object translationUnitBegin();
public void translationUnitEnd(Object unit);
- public void inclusionBegin(String includeFile);
+ public void inclusionBegin(String includeFile, int offset);
public void inclusionEnd();
- public void macro(String macroName);
+ public void macro(String macroName, int offset);
public Object simpleDeclarationBegin(Object Container);
public void simpleDeclarationEnd(Object declaration);
@@ -32,9 +32,12 @@ public interface IParserCallback {
public Object declaratorBegin(Object container);
public void declaratorId(Object declarator);
+ public void declaratorAbort( Object container, Object declarator );
+ public void declaratorEnd(Object declarator);
+
public Object argumentsBegin( Object declarator );
public void argumentsEnd(Object parameterDeclarationClause);
- public void declaratorEnd(Object declarator);
+
public void functionBodyBegin();
public void functionBodyEnd();
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/NullParserCallback.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/NullParserCallback.java
index ce46d1a7d5..6a841aeb3d 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/NullParserCallback.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/NullParserCallback.java
@@ -31,7 +31,7 @@ public class NullParserCallback implements IParserCallback {
/**
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#beginInclusion(String)
*/
- public void inclusionBegin(String includeFile) {
+ public void inclusionBegin(String includeFile, int offset) {
}
/**
@@ -117,7 +117,7 @@ public class NullParserCallback implements IParserCallback {
/**
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#macro(String)
*/
- public void macro(String macroName) {
+ public void macro(String macroName, int offset) {
}
/**
@@ -166,5 +166,10 @@ public class NullParserCallback implements IParserCallback {
public void parameterDeclarationEnd( Object declaration ){
}
+ /**
+ * @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object)
+ */
+ public void declaratorAbort(Object container, Object declarator) {
+ }
}
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Parser.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Parser.java
index 1c6b8e9e5a..f26c23b65d 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Parser.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Parser.java
@@ -248,6 +248,8 @@ c, quick);
* - find template names in name
*/
public void declSpecifierSeq( Object decl ) throws Exception {
+ boolean encounteredTypename = false;
+ boolean encounteredRawType = false;
declSpecifiers:
for (;;) {
switch (LT(1)) {
@@ -274,6 +276,7 @@ c, quick);
case Token.t_float:
case Token.t_double:
case Token.t_void:
+ encounteredRawType = true;
callback.simpleDeclSpecifier(decl, consume());
break;
case Token.t_typename:
@@ -284,18 +287,26 @@ c, quick);
consume();
// handle nested later:
case Token.tIDENTIFIER:
- // handle nested later:
- if (currRegion.get(LA(1).getImage()) != null) {
- consume();
- break;
+ if( ! encounteredRawType )
+ {
+ // handle nested later:
+ if( ! encounteredTypename )
+ {
+ callback.simpleDeclSpecifier(decl,consume());
+ encounteredTypename = true;
+ break;
+ }
+ else
+ return;
}
else
- break declSpecifiers;
+ return;
+
case Token.t_class:
case Token.t_struct:
case Token.t_union:
classSpecifier(decl);
- break;
+ return;
case Token.t_enum:
// enumSpecifier();
break;
@@ -379,60 +390,72 @@ c, quick);
*/
public void declarator( Object container ) throws Exception {
- Object declarator = callback.declaratorBegin( container );
-
- for (;;) {
- try {
- ptrOperator();
- } catch (Backtrack b) {
- break;
+ boolean aborted;
+ do
+ {
+ aborted = false;
+ Object declarator = callback.declaratorBegin( container );
+
+ for (;;) {
+ try {
+ ptrOperator();
+ } catch (Backtrack b) {
+ break;
+ }
}
- }
-
- if (LT(1) == Token.tLPAREN) {
- consume();
- declarator(declarator);
- consume(Token.tRPAREN);
- return;
- }
-
- name();
- callback.declaratorId(declarator);
-
- for (;;) {
- switch (LT(1)) {
- case Token.tLPAREN:
- // parameterDeclarationClause
- Object clause = callback.argumentsBegin(declarator);
- consume();
- parameterDeclarationLoop:
- for (;;) {
- switch (LT(1)) {
- case Token.tRPAREN:
- consume();
- break parameterDeclarationLoop;
- case Token.tELIPSE:
- consume();
- break;
- case Token.tCOMMA:
- consume();
- break;
- default:
- parameterDeclaration( clause );
+
+ if (LT(1) == Token.tLPAREN) {
+ consume();
+ declarator(declarator);
+ consume(Token.tRPAREN);
+ return;
+ }
+
+ name();
+ callback.declaratorId(declarator);
+
+ for (;;) {
+ switch (LT(1)) {
+ case Token.tLPAREN:
+ // parameterDeclarationClause
+ Object clause = callback.argumentsBegin(declarator);
+ consume();
+ parameterDeclarationLoop:
+ for (;;) {
+ switch (LT(1)) {
+ case Token.tRPAREN:
+ consume();
+ break parameterDeclarationLoop;
+ case Token.tELIPSE:
+ consume();
+ break;
+ case Token.tCOMMA:
+ consume();
+ break;
+ default:
+ parameterDeclaration( clause );
+ }
}
- }
- callback.argumentsEnd(clause);
- break;
- case Token.tLBRACKET:
- consume();
- // constantExpression();
- consume(Token.tRBRACKET);
- continue;
+ callback.argumentsEnd(clause);
+ break;
+ case Token.tLBRACKET:
+ consume();
+ // constantExpression();
+ consume(Token.tRBRACKET);
+ continue;
+ }
+ break;
}
- break;
- }
-
- callback.declaratorEnd(declarator);
+
+ if( LA(1).getType() == Token.tIDENTIFIER )
+ {
+ callback.declaratorAbort( container, declarator );
+ declarator = null;
+ aborted = true;
+ }
+ else
+ callback.declaratorEnd(declarator);
+ } while( aborted );
}
/**
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Scanner.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Scanner.java
index a84c0e973b..202b880d84 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Scanner.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/Scanner.java
@@ -1169,6 +1169,7 @@ public class Scanner implements IScanner {
protected void poundInclude() throws ScannerException {
skipOverWhitespace();
int c = getChar();
+ int offset;
StringBuffer fileName = new StringBuffer();
if (c == '<') {
@@ -1177,9 +1178,8 @@ public class Scanner implements IScanner {
fileName.append((char) c);
c = getChar();
}
-
- handleInclusion(fileName.toString().trim());
- } else if (c == '"') {
+ }
+ else if (c == '"') {
c = getChar();
while ((c != '"')) {
fileName.append((char) c);
@@ -1188,14 +1188,31 @@ public class Scanner implements IScanner {
// TO DO: Make sure the directory of the current file is in the
// inclusion paths.
- handleInclusion(fileName.toString().trim());
}
+
+ String f = fileName.toString();
+
+ if( quickScan )
+ {
+ if( callback != null )
+ {
+ offset = currentContext.getOffset() - f.length() - 1; // -1 for the end quote
+
+ callback.inclusionBegin( f, offset );
+ callback.inclusionEnd();
+ }
+ }
+ else
+ handleInclusion(f.trim());
}
protected void poundDefine() throws ScannerException {
skipOverWhitespace();
// definition
String key = getNextIdentifier();
+ int offset = currentContext.getOffset() - key.length();
+ if( currentContext.getUndo() != Scanner.NOCHAR )
+ offset -= 1;
if (throwExceptionOnRedefinition) {
String checkForRedefinition = (String) definitions.get(key);
@@ -1291,6 +1308,10 @@ public class Scanner implements IScanner {
if (throwExceptionOnBadPPDirective)
throw new ScannerException(BAD_PP + currentContext.getOffset());
}
+
+ // call the callback accordingly
+ if( callback != null )
+ callback.macro( key, offset );
}
protected void expandDefinition(String symbol, Object expansion)
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclSpecifier.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclSpecifier.java
index e0d41d6fc9..163008ea0b 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclSpecifier.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclSpecifier.java
@@ -173,6 +173,9 @@ public class DeclSpecifier {
case Token.t_void:
setType(DeclarationSpecifier.t_void);
break;
+ case Token.tIDENTIFIER:
+ setType(DeclarationSpecifier.t_type);
+ break;
}
}
diff --git a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclarationSpecifier.java b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclarationSpecifier.java
index a7188fc17f..f235e68440 100644
--- a/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclarationSpecifier.java
+++ b/core/org.eclipse.cdt.core/newparser/org/eclipse/cdt/internal/core/newparser/util/DeclarationSpecifier.java
@@ -19,6 +19,7 @@ public class DeclarationSpecifier extends DeclSpecifier {
public void setDeclSpecifier( DeclarationSpecifier in );
public void addDeclarator(Object declarator);
+ public void removeDeclarator( Object declarator );
public List getDeclarators();
};

Back to the top