Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 51238 Details for
Bug 106279
DOM Parser parses parenthesized expressions incorrectly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch to fix incorrect identification of cast
org.eclipse.cdt.core_patch_typecast_fix_1.txt (text/plain), 13.92 KB, created by
Jason Brown
on 2006-10-02 03:34:25 EDT
(
hide
)
Description:
patch to fix incorrect identification of cast
Filename:
MIME Type:
Creator:
Jason Brown
Created:
2006-10-02 03:34:25 EDT
Size:
13.92 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.cdt.core >Index: parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java >=================================================================== >RCS file: /home/tools/org.eclipse.cdt/all/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java,v >retrieving revision 1.109 >diff -u -r1.109 GNUCPPSourceParser.java >--- parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java 14 Jun 2006 12:16:08 -0000 1.109 >+++ parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java 29 Sep 2006 16:21:45 -0000 >@@ -915,6 +915,10 @@ > // If this isn't a type name, then we shouldn't be here > typeId = typeId(false); > if (typeId != null && LT(1) == IToken.tRPAREN) { >+ //check that the typeId contains a type and >+ //not a variable >+ if (!isValidTypeId(typeId)) >+ throw backtrack; > consume(); > startCastExpression=mark(); > if (templateIdScopes.size() > 0) { >Index: parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java >=================================================================== >RCS file: /home/tools/org.eclipse.cdt/all/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java,v >retrieving revision 1.72 >diff -u -r1.72 AbstractGNUSourceCodeParser.java >--- parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java 14 Jun 2006 12:16:10 -0000 1.72 >+++ parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java 29 Sep 2006 16:21:23 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2006 IBM Corporation and others. >+ * Copyright (c) 2005 IBM Corporation 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 >@@ -10,6 +10,9 @@ > *******************************************************************************/ > package org.eclipse.cdt.internal.core.dom.parser; > >+import java.util.HashMap; >+import java.util.LinkedList; >+ > import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; > import org.eclipse.cdt.core.dom.ast.ASTVisitor; > import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; >@@ -55,6 +58,11 @@ > import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; > import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; > import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; >+import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; >+import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; >+import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; >+import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; >+import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; > import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; > import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression; > import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression; >@@ -66,6 +74,7 @@ > import org.eclipse.cdt.core.parser.OffsetLimitReachedException; > import org.eclipse.cdt.core.parser.ParseError; > import org.eclipse.cdt.core.parser.ParserMode; >+import org.eclipse.cdt.internal.core.dom.parser.c.CASTTypeId; > > /** > * @author jcamelon >@@ -105,6 +114,7 @@ > this.supportKnRC = supportKnRC; > this.supportGCCOtherBuiltinSymbols = supportGCCOtherBuiltinSymbols; > this.supportAttributeSpecifiers = supportAttributeSpecifiers; >+ this.typeScopeStack = new TypeScopeStack(); > } > > protected boolean parsePassed = true; >@@ -141,6 +151,182 @@ > } > > /** >+ * A scope class for holding type names as the source parsed and AST is constructed. >+ * In the process of the AST it is not possible to use the CScope lookup names since >+ * often the AST is not yet correctly connected. As a consequence it is difficult >+ * to determine when an IASTName represents a type or variable. This is an important >+ * property to be able to check in the case of cast expressions (see: castExpression()). >+ * >+ * Due to CScope not being available this TypeScope is used to store known types as >+ * we go along so that it is possible to check typedness of an IASTName. >+ * >+ * @author jason >+ */ >+ protected class TypeScope { >+ private TypeScope parentScope; >+ private HashMap types; >+ public TypeScope(TypeScope parent) { >+ parentScope = parent; >+ types = new HashMap(); >+ } >+ >+ public boolean addType(IASTName name) { >+ if (!types.containsKey(name)) { >+ types.put(name.toString(),null); >+ return true; >+ } >+ else >+ return false; >+ } >+ >+ public boolean isType(IASTName name) { >+ if (name != null) { >+ if (types.containsKey(name.toString())) >+ return true; >+ else if (parentScope != null) >+ return parentScope.isType(name); >+ else >+ return false; >+ } >+ else >+ return false; >+ } >+ } >+ >+ /** >+ * A stack of TypeScopes >+ * >+ * @author jason >+ */ >+ protected class TypeScopeStack { >+ private LinkedList scopes; >+ public TypeScopeStack() { >+ scopes = new LinkedList(); >+ } >+ >+ public void push(TypeScope typeScope) { >+ if (typeScope != null) >+ scopes.addFirst(typeScope); >+ } >+ >+ public TypeScope top() { >+ if (scopes.size() > 0) >+ return (TypeScope)scopes.getFirst(); >+ else >+ return null; >+ } >+ >+ public TypeScope pop() { >+ if (scopes.size() > 0) >+ return (TypeScope)scopes.removeFirst(); >+ else >+ return null; >+ } >+ >+ public boolean isType(IASTName name) { >+ if (scopes.size() > 0) >+ return top().isType(name); >+ else >+ return false; >+ } >+ >+ public boolean addType(IASTName name) { >+ if (scopes.size() > 0) >+ return top().addType(name); >+ else >+ return false; >+ } >+ } >+ >+ /** >+ * @author jason >+ */ >+ protected TypeScopeStack typeScopeStack; >+ >+ /** >+ * @author jason >+ * @param typeId >+ * @return >+ */ >+ protected boolean isValidTypeId(IASTTypeId typeId) { >+ if (typeId instanceof CASTTypeId) { >+ IASTDeclSpecifier declSpecifier = (IASTDeclSpecifier)typeId.getDeclSpecifier(); >+ if (declSpecifier instanceof ICASTTypedefNameSpecifier) { >+ ICASTTypedefNameSpecifier typedefNameDeclSpecifier = (ICASTTypedefNameSpecifier)declSpecifier; >+ IASTName typedefName = typedefNameDeclSpecifier.getName(); >+ // if the name is in the type scope then the typeId is valid, otherwise the >+ // name is a variable and is not a typeid but an expression >+ if (typeScopeStack.isType(typedefName)) >+ return true; >+ else >+ return false; >+ } >+ else if (declSpecifier instanceof ICASTCompositeTypeSpecifier) >+ return true; >+ else if (declSpecifier instanceof ICASTSimpleDeclSpecifier) { >+ ICASTSimpleDeclSpecifier simpleDeclSpecifier = (ICASTSimpleDeclSpecifier)declSpecifier; >+ switch (simpleDeclSpecifier.getType()) >+ { >+ case IASTSimpleDeclSpecifier.t_char: >+ case IASTSimpleDeclSpecifier.t_double: >+ case IASTSimpleDeclSpecifier.t_float: >+ case IASTSimpleDeclSpecifier.t_int: >+ case IASTSimpleDeclSpecifier.t_void: >+ break; >+ case IASTSimpleDeclSpecifier.t_unspecified: >+ if (!simpleDeclSpecifier.isLong() >+ && !simpleDeclSpecifier.isLongLong() >+ && !simpleDeclSpecifier.isComplex() >+ && !simpleDeclSpecifier.isShort() >+ && !simpleDeclSpecifier.isSigned() >+ && !simpleDeclSpecifier.isUnsigned()) { >+ return false; >+ } >+ break; >+ default: >+ return false; >+ } >+ return true; >+ } >+ else if (declSpecifier instanceof ICASTElaboratedTypeSpecifier) >+ return true; >+ else if (declSpecifier instanceof ICASTEnumerationSpecifier) { >+ return true; >+ } >+ else >+ return false; >+ } >+ else >+ return false; >+ } >+ >+ /** >+ * @param simpleDeclaration >+ * @author jason >+ */ >+ protected void extractTypeNamesToStack(IASTSimpleDeclaration simpleDeclaration) { >+ IASTDeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier(); >+ IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); >+ if (declSpecifier.getStorageClass() == IASTDeclSpecifier.sc_typedef){ >+ for(int i = 0; i < declarators.length; i++) { >+ IASTDeclarator declarator = declarators[i]; >+ IASTName declaratorName = declarators[i].getName(); >+ if (declaratorName == null || declaratorName.toCharArray().length == 0) { >+ // look at any nested declarators >+ IASTDeclarator nestedDeclarator = declarators[i].getNestedDeclarator(); >+ if (nestedDeclarator != null) { >+ declaratorName = nestedDeclarator.getName(); >+ } >+ } >+ >+ if (declaratorName != null && (declaratorName.toCharArray().length > 0)) >+ typeScopeStack.addType(declaratorName); >+ } >+ } >+ } >+ >+ >+ /** > * Look Ahead in the token list to see what is coming. > * > * @param i >@@ -405,6 +591,9 @@ > private static final IASTNode[] EMPTY_NODE_ARRAY = new IASTNode[0]; > > public IASTTranslationUnit parse() { >+ // push a type scope for the file on to the type scope stack >+ typeScopeStack.push(new TypeScope(null)); >+ > long startTime = System.currentTimeMillis(); > translationUnit(); > log.traceLog("Parse " //$NON-NLS-1$ >@@ -418,6 +607,9 @@ > ); //$NON-NLS-1$ //$NON-NLS-2$ > IASTTranslationUnit result = getTranslationUnit(); > nullifyTranslationUnit(); >+ >+ // pop the file type scope stack before exiting >+ typeScopeStack.pop(); > return result; > } > >@@ -511,6 +703,9 @@ > > int startingOffset = consume(IToken.tLBRACE).getOffset(); > >+ // push a type scope for the compound statement >+ typeScopeStack.push(new TypeScope(typeScopeStack.top())); >+ > ((ASTNode) result).setOffset(startingOffset); > result.setPropertyInParent(IASTFunctionDefinition.FUNCTION_BODY); > while (LT(1) != IToken.tRBRACE && LT(1) != IToken.tEOC) { >@@ -540,6 +735,13 @@ > int lastOffset = token.getEndOffset(); > ((ASTNode) result).setLength(lastOffset - startingOffset); > >+ // NOTE: need to move this pop IF a backtrack exception can occur in processing. >+ // currently such an exception only occurs when trying to consume 'tLBRACE' on >+ // entering this method. >+ >+ // pop compound statement type scope >+ typeScopeStack.pop(); >+ > return result; > } > >@@ -1587,6 +1789,12 @@ > } > > if (expressionStatement == null && ds != null) { >+ >+ // ADDED: jason >+ // a declaration statement has been found. process this declaration and add >+ // any type names to the type scope >+ if (ds.getDeclaration() instanceof IASTSimpleDeclaration) >+ extractTypeNamesToStack((IASTSimpleDeclaration)ds.getDeclaration()); > return ds; > } > if (expressionStatement != null && ds == null) { >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /home/tools/org.eclipse.cdt/all/org.eclipse.cdt.core/META-INF/MANIFEST.MF,v >retrieving revision 1.15 >diff -u -r1.15 MANIFEST.MF >--- META-INF/MANIFEST.MF 29 Sep 2006 07:19:44 -0000 1.15 >+++ META-INF/MANIFEST.MF 29 Sep 2006 16:21:17 -0000 >@@ -2,7 +2,7 @@ > Bundle-ManifestVersion: 2 > Bundle-Name: %pluginName > Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true >-Bundle-Version: 3.1.0.qualifier >+Bundle-Version: 3.1.1.1 > Bundle-Activator: org.eclipse.cdt.core.CCorePlugin > Bundle-Vendor: %providerName > Bundle-Localization: plugin >Index: parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java >=================================================================== >RCS file: /home/tools/org.eclipse.cdt/all/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java,v >retrieving revision 1.78 >diff -u -r1.78 GNUCSourceParser.java >--- parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java 14 Jun 2006 12:16:12 -0000 1.78 >+++ parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java 29 Sep 2006 16:21:30 -0000 >@@ -535,6 +535,12 @@ > declarator.setParent(simpleDeclaration); > declarator.setPropertyInParent(IASTSimpleDeclaration.DECLARATOR); > } >+ >+ //ADDED: jason >+ // a simple declaration has been found, process it and add any new type >+ // names to the type scope >+ extractTypeNamesToStack(simpleDeclaration); >+ > return simpleDeclaration; > } > >@@ -827,7 +833,11 @@ > typeId = typeId(false); > if (typeId != null) { > switch (LT(1)) { >- case IToken.tRPAREN: >+ case IToken.tRPAREN: >+ //check that the typeId contains a type and >+ //not a variable >+ if (!isValidTypeId(typeId)) >+ throw backtrack; > consume(); > proper=true; > startCastExpression=mark(); >@@ -989,6 +999,10 @@ > int offset = consume().getOffset(); > IASTTypeId t = typeId(false); > if (t != null) { >+ //check that the typeId contains a type and >+ //not a variable >+ if (!isValidTypeId(t)) >+ throw backtrack; > consume(IToken.tRPAREN).getEndOffset(); > IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST); > firstExpression = buildTypeIdInitializerExpression(t, i,
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 106279
:
51238