diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index e422474df69..50acfbe3b29 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 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 @@ -42,6 +42,16 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; +import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; @@ -52,23 +62,13 @@ import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; -import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; -import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; /** * @author aniefer diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java index fe2324790d6..1dab1ee80a7 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 @@ -14,6 +14,16 @@ import org.eclipse.cdt.core.dom.CDOM; import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; +import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; @@ -22,23 +32,13 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.tests.FileBasePluginTest; -import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; -import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; import org.eclipse.core.resources.IFile; /** diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java index 5e927f215f1..c0de688eae0 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 @@ -19,6 +19,16 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; +import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; @@ -26,23 +36,13 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; -import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; import junit.framework.TestCase; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index 313c1cd83fa..8f0708bc786 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -63,6 +63,16 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; +import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.NullLogService; @@ -70,23 +80,13 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; -import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; -import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; import org.eclipse.core.runtime.Platform; /** diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java index b1edc751aa0..5505c1173f0 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 @@ -18,6 +18,16 @@ import junit.framework.TestCase; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; +import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -25,23 +35,13 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; -import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; /** * @author jcamelon diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java index f9837163669..82243bc5174 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 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 @@ -17,6 +17,16 @@ import junit.framework.TestCase; import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; +import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; @@ -24,21 +34,11 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; public class CompletionTestBase extends TestCase { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java index f0c8018d6ed..2624be9a0b2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. + * Copyright (c) 2001, 2007 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 @@ -17,6 +17,9 @@ import java.util.List; import junit.framework.ComparisonFailure; import junit.framework.TestCase; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IParserLogService; @@ -31,9 +34,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro; import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java index 037622b2977..42298d74e54 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 @@ -17,6 +17,9 @@ import java.util.Map; import junit.framework.TestCase; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParserLogService; @@ -29,9 +32,6 @@ import org.eclipse.cdt.core.parser.ParserFactoryError; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2; // A test that just calculates the speed of the parser diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 04a7b1ced98..09200e0bbf6 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -16,6 +16,9 @@ Export-Package: org.eclipse.cdt.core, org.eclipse.cdt.core.dom.ast.gnu, org.eclipse.cdt.core.dom.ast.gnu.c, org.eclipse.cdt.core.dom.ast.gnu.cpp, + org.eclipse.cdt.core.dom.parser, + org.eclipse.cdt.core.dom.parser.c, + org.eclipse.cdt.core.dom.parser.cpp, org.eclipse.cdt.core.envvar, org.eclipse.cdt.core.formatter, org.eclipse.cdt.core.index, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBuiltinSymbolProvider.java index 381f6b73207..6708e0a727b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBuiltinSymbolProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBuiltinSymbolProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -15,6 +16,8 @@ package org.eclipse.cdt.core.dom.ast; * provided by a Built-in Symbol Provider that implements this interface. * * @author dsteffle + * + * @deprecated Use {@link org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider} instead */ public interface IASTBuiltinSymbolProvider { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java index 0c21d886669..f13b39355e4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java @@ -9,50 +9,27 @@ * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) * IBM Corporation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.gnu.c; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ICodeReaderFactory; -import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; -import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.gnu.Messages; -import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.model.AbstractLanguage; -import org.eclipse.cdt.core.model.IContributedModelBuilder; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.DefaultLogService; -import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IScanner; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; -import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; -import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory; -import org.eclipse.core.runtime.CoreException; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.AbstractCLanguage; +import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; /** * @author Doug Schaefer * */ -public class GCCLanguage extends AbstractLanguage { +public class GCCLanguage extends AbstractCLanguage { protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration(); + protected static final GCCParserExtensionConfiguration C_GNU_PARSER_EXTENSION = new GCCParserExtensionConfiguration(); // Must match the id in the extension public static final String ID = CCorePlugin.PLUGIN_ID + ".gcc"; //$NON-NLS-1$ @@ -67,83 +44,21 @@ public class GCCLanguage extends AbstractLanguage { } public String getName() { - return new String(Messages.getString("GCCLanguage.name")); //$NON-NLS-1$ - } - - public Object getAdapter(Class adapter) { - if (adapter == IPDOMLinkageFactory.class) - return new PDOMCLinkageFactory(); - else - return super.getAdapter(adapter); - } - - public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, - IScannerInfo scanInfo, ICodeReaderFactory codeReaderFactory, IIndex index, IParserLogService log) throws CoreException { - IScannerExtensionConfiguration scannerExtensionConfiguration= C_GNU_SCANNER_EXTENSION; - IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, - ParserLanguage.C, new DefaultLogService(), scannerExtensionConfiguration, codeReaderFactory); - //assume GCC - ISourceCodeParser parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, log, - new GCCParserExtensionConfiguration(), index); - - // Parse - IASTTranslationUnit ast = parser.parse(); - return ast; - } - - public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException { - IScannerExtensionConfiguration scannerExtensionConfiguration - = C_GNU_SCANNER_EXTENSION; - IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, - ParserLanguage.C, new DefaultLogService(), scannerExtensionConfiguration, fileCreator ); - scanner.setContentAssistMode(offset); - - ISourceCodeParser parser = new GNUCSourceParser( - scanner, - ParserMode.COMPLETION_PARSE, - ParserUtil.getParserLogService(), - new GCCParserExtensionConfiguration(), - index); - - // Run the parse and return the completion node - parser.parse(); - ASTCompletionNode node = parser.getCompletionNode(); - if (node != null) { - node.count = scanner.getCount(); - } - return node; + return Messages.getString("GCCLanguage.name"); //$NON-NLS-1$ } - private static class NameCollector extends CASTVisitor { - { - shouldVisitNames = true; - } - private List nameList = new ArrayList(); - public int visit( IASTName name ){ - nameList.add( name ); - return PROCESS_CONTINUE; - } - public IASTName[] getNames() { - return (IASTName[])nameList.toArray(new IASTName[nameList.size()]); - } + /* + * @see org.eclipse.cdt.core.parser.AbstractCLanguage#getParserExtensionConfiguration() + */ + protected ICParserExtensionConfiguration getParserExtensionConfiguration() { + return C_GNU_PARSER_EXTENSION; + } + + /* + * @see org.eclipse.cdt.core.parser.AbstractCLanguage#getScannerExtensionConfiguration() + */ + protected IScannerExtensionConfiguration getScannerExtensionConfiguration() { + return C_GNU_SCANNER_EXTENSION; } - public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) { - IASTNode selectedNode = ast.selectNodeForLocation(ast.getFilePath(), start, length); - - if (selectedNode == null) - return new IASTName[0]; - - if (selectedNode instanceof IASTName) - return new IASTName[] { (IASTName)selectedNode }; - - NameCollector collector = new NameCollector(); - selectedNode.accept(collector); - return collector.getNames(); - } - - public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) { - // Use the default CDT model builder - return null; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java index 9eae2d58025..5f9eeeae0e2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java @@ -9,50 +9,26 @@ * QNX - Initial API and implementation * Markus Schorn (Wind River Systems) * IBM Corporation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.core.dom.ast.gnu.cpp; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ICodeReaderFactory; -import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; -import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.gnu.Messages; -import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.model.AbstractLanguage; -import org.eclipse.cdt.core.model.IContributedModelBuilder; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.DefaultLogService; -import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IScanner; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; -import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory; -import org.eclipse.core.runtime.CoreException; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPLanguage; +import org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; /** * @author Doug Schaefer * */ -public class GPPLanguage extends AbstractLanguage { +public class GPPLanguage extends AbstractCPPLanguage { protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration(); + protected static final GPPParserExtensionConfiguration CPP_GNU_PARSER_EXTENSION = new GPPParserExtensionConfiguration(); public static final String ID = CCorePlugin.PLUGIN_ID + ".g++"; //$NON-NLS-1$ private static final GPPLanguage myDefault = new GPPLanguage(); @@ -66,84 +42,21 @@ public class GPPLanguage extends AbstractLanguage { } public String getName() { - return new String(Messages.getString("GPPLanguage.name")); //$NON-NLS-1$ - } - - public Object getAdapter(Class adapter) { - if (adapter == IPDOMLinkageFactory.class) - return new PDOMCPPLinkageFactory(); - else - return super.getAdapter(adapter); - } - - - public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, - ICodeReaderFactory codeReaderFactory, IIndex index, IParserLogService log) throws CoreException { - IScannerExtensionConfiguration scannerExtensionConfiguration= CPP_GNU_SCANNER_EXTENSION; - IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, - ParserLanguage.CPP, new DefaultLogService(), scannerExtensionConfiguration, codeReaderFactory); - //assume GCC - ISourceCodeParser parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, log, - new GPPParserExtensionConfiguration(), index ); - - // Parse - IASTTranslationUnit ast= parser.parse(); - return ast; + return Messages.getString("GPPLanguage.name"); //$NON-NLS-1$ } - public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException { - IScannerExtensionConfiguration scannerExtensionConfiguration - = CPP_GNU_SCANNER_EXTENSION; - IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, - ParserLanguage.CPP, new DefaultLogService(), scannerExtensionConfiguration, fileCreator ); - scanner.setContentAssistMode(offset); - - ISourceCodeParser parser = new GNUCPPSourceParser( - scanner, - ParserMode.COMPLETION_PARSE, - ParserUtil.getParserLogService(), - new GPPParserExtensionConfiguration(), - index); - - // Run the parse and return the completion node - parser.parse(); - ASTCompletionNode node = parser.getCompletionNode(); - if (node != null) { - node.count = scanner.getCount(); - } - return node; + /* + * @see org.eclipse.cdt.core.dom.ast.gnu.cpp.AbstractCPPLanguage#getScannerExtensionConfiguration() + */ + protected IScannerExtensionConfiguration getScannerExtensionConfiguration() { + return CPP_GNU_SCANNER_EXTENSION; } - - private static class NameCollector extends CPPASTVisitor { - { - shouldVisitNames = true; - } - private List nameList = new ArrayList(); - public int visit( IASTName name ){ - nameList.add( name ); - return PROCESS_CONTINUE; - } - public IASTName[] getNames() { - return (IASTName[])nameList.toArray(new IASTName[nameList.size()]); - } - } - - public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) { - IASTNode selectedNode = ast.selectNodeForLocation(ast.getFilePath(), start, length); - - if (selectedNode == null) - return new IASTName[0]; - - if (selectedNode instanceof IASTName) - return new IASTName[] { (IASTName)selectedNode }; - - NameCollector collector = new NameCollector(); - selectedNode.accept(collector); - return collector.getNames(); - } - - public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) { - // Use the default CDT model builder - return null; + + /* + * @see org.eclipse.cdt.core.dom.ast.gnu.cpp.AbstractCPPLanguage#getParserExtensionConfiguration() + */ + protected AbstractCPPParserExtensionConfiguration getParserExtensionConfiguration() { + return CPP_GNU_PARSER_EXTENSION; } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java new file mode 100644 index 00000000000..6041949acc7 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * 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: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser; + +import org.eclipse.cdt.core.parser.util.CharArrayIntMap; +import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; +import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro; +import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro; + +/** + * Abstract scanner extension configuration to help model C/C++ dialects. + * + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @since 4.0 + */ +public abstract class AbstractScannerExtensionConfiguration implements IScannerExtensionConfiguration { + + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#getAdditionalKeywords() + */ + public CharArrayIntMap getAdditionalKeywords() { + return null; + } + + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#getAdditionalMacros() + */ + public CharArrayObjectMap getAdditionalMacros() { + return null; + } + + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#getAdditionalPreprocessorKeywords() + */ + public CharArrayIntMap getAdditionalPreprocessorKeywords() { + return null; + } + + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#initializeMacroValuesTo1() + */ + public boolean initializeMacroValuesTo1() { + return false; + } + + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#support$InIdentifiers() + */ + public boolean support$InIdentifiers() { + return false; + } + + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#supportAdditionalNumericLiteralSuffixes() + */ + public char[] supportAdditionalNumericLiteralSuffixes() { + return null; + } + + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#supportMinAndMaxOperators() + */ + public boolean supportMinAndMaxOperators() { + return false; + } + + /** + * Helper method to add an object style macro to the given map. + * + * @param macros the macro map + * @param name the macro name + * @param value the macro value + */ + protected void addObjectStyleMacro(CharArrayObjectMap macros, String name, String value) { + char[] nameChars= name.toCharArray(); + macros.put(nameChars, new ObjectStyleMacro(nameChars, value.toCharArray())); + } + + /** + * Helper method to add a function style macro to the given map. + * + * @param macros the macro map + * @param name the macro name + * @param value the macro value + * @param arguments the macro arguments + */ + protected void addFunctionStyleMacro(CharArrayObjectMap macros, String name, String value, String[] arguments) { + char[] nameChars= name.toCharArray(); + char[][] argumentsArray= new char[arguments.length][]; + for (int i = 0; i < arguments.length; i++) { + argumentsArray[i]= arguments[i].toCharArray(); + } + macros.put(nameChars, new FunctionStyleMacro(nameChars, value.toCharArray(), argumentsArray)); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java similarity index 76% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerExtensionConfiguration.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java index f0169566922..6d20f3d4af4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 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 @@ -7,15 +7,21 @@ * * Contributors: * IBM - Initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.scanner2; +package org.eclipse.cdt.core.dom.parser; +import org.eclipse.cdt.core.parser.IPreprocessorDirective; +import org.eclipse.cdt.core.parser.Keywords; +import org.eclipse.cdt.core.parser.util.CharArrayIntMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; +import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro; +import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro; /** * @author jcamelon */ -public abstract class GNUScannerExtensionConfiguration implements IScannerExtensionConfiguration { +public abstract class GNUScannerExtensionConfiguration extends AbstractScannerExtensionConfiguration { protected static final char[] emptyCharArray = "".toCharArray(); //$NON-NLS-1$ @@ -105,4 +111,18 @@ public abstract class GNUScannerExtensionConfiguration implements IScannerExtens return realDefinitions; } + /* + * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#getAdditionalPreprocessorKeywords() + */ + public CharArrayIntMap getAdditionalPreprocessorKeywords() { + CharArrayIntMap additionalPPKeywords= new CharArrayIntMap(8, IPreprocessorDirective.ppInvalid); + additionalPPKeywords.put(Keywords.cINCLUDE_NEXT, IPreprocessorDirective.ppInclude_next); + additionalPPKeywords.put(Keywords.cIMPORT, IPreprocessorDirective.ppImport); + additionalPPKeywords.put(Keywords.cWARNING, IPreprocessorDirective.ppWarning); + additionalPPKeywords.put(Keywords.cIDENT, IPreprocessorDirective.ppIgnore); + additionalPPKeywords.put(Keywords.cSCCS, IPreprocessorDirective.ppIgnore); + additionalPPKeywords.put(Keywords.cASSERT, IPreprocessorDirective.ppIgnore); + additionalPPKeywords.put(Keywords.cUNASSERT, IPreprocessorDirective.ppIgnore); + return additionalPPKeywords; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IBuiltinBindingsProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IBuiltinBindingsProvider.java new file mode 100644 index 00000000000..f806e1676f5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IBuiltinBindingsProvider.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser; + +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IScope; + +/** + * Provides built-in symbols to the parser. + * + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @since 4.0 + */ +public interface IBuiltinBindingsProvider { + + /** + * Get additional built-in bindings for the given scope. + * + * @param scope the scope the bindings are added to + * @return an array of {@link IBinding}s, may not return null + */ + public IBinding[] getBuiltinBindings(IScope scope); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IExtensionToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IExtensionToken.java new file mode 100644 index 00000000000..17601d55bb8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IExtensionToken.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser; + +import org.eclipse.cdt.core.parser.IToken; + +/** + * Token types for parser extensions. + *

+ * This interface is not intended to be implemented. + *

+ *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @since 4.0 + */ +public interface IExtensionToken { + + int t__otherDeclSpecModifierFirst= IToken.tLAST + 100; + int t__otherDeclSpecModifierLast= IToken.tLAST + 110; + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java similarity index 70% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerExtensionConfiguration.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java index 2c399cc2754..2e319c7b593 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 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 @@ -7,8 +7,9 @@ * * Contributors: * IBM - Initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.scanner2; +package org.eclipse.cdt.core.dom.parser; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; @@ -26,4 +27,12 @@ public interface IScannerExtensionConfiguration { public char [] supportAdditionalNumericLiteralSuffixes(); public CharArrayObjectMap getAdditionalMacros(); + + /** + * @return a mapping of preprocessor directive keyword to one of the constants defined in + * {@link org.eclipse.cdt.core.parser.IPreprocessorDirective IPreprocessorDirective}. + * + * @since 4.0 + */ + public CharArrayIntMap getAdditionalPreprocessorKeywords(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/ISourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/ISourceCodeParser.java new file mode 100644 index 00000000000..dc252f2e423 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/ISourceCodeParser.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser; + +import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; + +/** + * Interface for an AST source code parser. + *

+ * This interface is not intended to be implemented directly. + *

+ *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @author jcamelon + */ +public interface ISourceCodeParser { + + /** + * Compute an abstract syntax tree (AST). + * @return the AST, should not return null + * + * @throws ParseError if parsing has been cancelled or for other reasons + */ + public IASTTranslationUnit parse(); + + /** + * Cancel the parsing. + */ + public void cancel(); + + /** + * Check whether there were errors. + * @return true if there were errors + */ + public boolean encounteredError(); + + /** + * Compute an {@link ASTCompletionNode} for code completion. + * @return a completion node or null if none could be computed + * + * @throws ParseError if parsing has been cancelled or for other reasons + */ + public ASTCompletionNode getCompletionNode(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ISourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ANSICParserExtensionConfiguration.java similarity index 55% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ISourceCodeParser.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ANSICParserExtensionConfiguration.java index a6c95e98f86..c32b4b31100 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ISourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ANSICParserExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2002, 2007 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 @@ -7,23 +7,15 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ -package org.eclipse.cdt.internal.core.dom.parser; +package org.eclipse.cdt.core.dom.parser.c; -import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; /** * @author jcamelon */ -public interface ISourceCodeParser { - - public void cancel(); - - public IASTTranslationUnit parse(); - - public boolean encounteredError(); - - public ASTCompletionNode getCompletionNode(); - +public class ANSICParserExtensionConfiguration extends AbstractCParserExtensionConfiguration { + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java new file mode 100644 index 00000000000..5557b4b69cc --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * 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: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.c; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.dom.ICodeReaderFactory; +import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; +import org.eclipse.cdt.core.dom.parser.AbstractScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.model.AbstractLanguage; +import org.eclipse.cdt.core.model.IContributedModelBuilder; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.IParserLogService; +import org.eclipse.cdt.core.parser.IScanner; +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; +import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; +import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; +import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory; +import org.eclipse.core.runtime.CoreException; + +/** + * Abstract C language. Derived classes need only implement + * {@link getScannerExtensionConfiguration()} and + * {@link getParserExtensionConfiguration()}. + * + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @see AbstractScannerExtensionConfiguration + * @see AbstractCParserExtensionConfiguration + * + * @since 4.0 + */ +public abstract class AbstractCLanguage extends AbstractLanguage { + + protected static class NameCollector extends CASTVisitor { + { + shouldVisitNames= true; + } + + private List nameList= new ArrayList(); + + public int visit(IASTName name) { + nameList.add(name); + return PROCESS_CONTINUE; + } + + public IASTName[] getNames() { + return (IASTName[]) nameList.toArray(new IASTName[nameList.size()]); + } + } + + public Object getAdapter(Class adapter) { + if (adapter == IPDOMLinkageFactory.class) + return new PDOMCLinkageFactory(); + else + return super.getAdapter(adapter); + } + + public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory codeReaderFactory, IIndex index, IParserLogService log) throws CoreException { + + IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log); + ISourceCodeParser parser= createParser(scanner, log, index, false); + + // Parse + IASTTranslationUnit ast= parser.parse(); + return ast; + } + + public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException { + + IScanner scanner= createScanner(reader, scanInfo, fileCreator, log); + scanner.setContentAssistMode(offset); + + ISourceCodeParser parser= createParser(scanner, log, index, true); + + // Run the parse and return the completion node + parser.parse(); + ASTCompletionNode node= parser.getCompletionNode(); + if (node != null) { + node.count= scanner.getCount(); + } + return node; + } + + + public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) { + IASTNode selectedNode= ast.selectNodeForLocation(ast.getFilePath(), start, length); + + if (selectedNode == null) + return new IASTName[0]; + + if (selectedNode instanceof IASTName) + return new IASTName[] { (IASTName) selectedNode }; + + NameCollector collector= new NameCollector(); + selectedNode.accept(collector); + return collector.getNames(); + } + + public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) { + // Use the default CDT model builder + return null; + } + + /** + * Create the scanner to be used with the parser. + * + * @param reader the code reader for the main file + * @param scanInfo the scanner information (macros, include pathes) + * @param fileCreator the code reader factory for inclusions + * @param log the log for debugging + * @return an instance of IScanner + */ + protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) { + return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.C, + log, getScannerExtensionConfiguration(), fileCreator); + } + + /** + * Create the parser. + * + * @param scanner the IScanner to get tokens from + * @param log the parser log service + * @param index the index to help resolve bindings + * @param forCompletion whether the parser is used for code completion + * @return an instance of ISourceCodeParser + */ + protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion) { + ParserMode mode= forCompletion ? ParserMode.COMPLETION_PARSE : ParserMode.COMPLETE_PARSE; + return new GNUCSourceParser(scanner, mode, log, getParserExtensionConfiguration(), index); + } + + /** + * @return the scanner extension configuration for this language, may not + * return null + */ + protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration(); + + /** + * @return the parser extension configuration for this language, may not + * return null + */ + protected abstract ICParserExtensionConfiguration getParserExtensionConfiguration(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java new file mode 100644 index 00000000000..dc04f787875 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * 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: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; + + +/** + * Abstract C parser extension configuration to help model C dialects. + * + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @since 4.0 + */ +public abstract class AbstractCParserExtensionConfiguration implements ICParserExtensionConfiguration { + + /* + * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#supportAlignOfUnaryExpression() + */ + public boolean supportAlignOfUnaryExpression() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#supportAttributeSpecifiers() + */ + public boolean supportAttributeSpecifiers() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#supportDeclspecSpecifiers() + */ + public boolean supportDeclspecSpecifiers() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#supportGCCOtherBuiltinSymbols() + */ + public boolean supportGCCOtherBuiltinSymbols() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#supportGCCStyleDesignators() + */ + public boolean supportGCCStyleDesignators() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#supportKnRC() + */ + public boolean supportKnRC() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#supportStatementsInExpressions() + */ + public boolean supportStatementsInExpressions() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#supportTypeofUnaryExpressions() + */ + public boolean supportTypeofUnaryExpressions() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#getBuiltinSymbolProvider() + */ + public IBuiltinBindingsProvider getBuiltinBindingsProvider() { + if (supportGCCOtherBuiltinSymbols()) { + return new GCCBuiltinSymbolProvider(ParserLanguage.C); + } + return null; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java new file mode 100644 index 00000000000..aa2ba353965 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2007 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; +import org.eclipse.core.runtime.Platform; + +/** + * @author jcamelon + */ +public class GCCParserExtensionConfiguration extends AbstractCParserExtensionConfiguration { + + /* + * @see org.eclipse.cdt.core.dom.parser.c.AbstractCParserExtensionConfiguration#supportStatementsInExpressions() + */ + public boolean supportStatementsInExpressions() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.AbstractCParserExtensionConfiguration#supportGCCStyleDesignators() + */ + public boolean supportGCCStyleDesignators() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.AbstractCParserExtensionConfiguration#supportTypeofUnaryExpressions() + */ + public boolean supportTypeofUnaryExpressions() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.AbstractCParserExtensionConfiguration#supportAlignOfUnaryExpression() + */ + public boolean supportAlignOfUnaryExpression() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.AbstractCParserExtensionConfiguration#supportKnRC() + */ + public boolean supportKnRC() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.AbstractCParserExtensionConfiguration#supportAttributeSpecifiers() + */ + public boolean supportAttributeSpecifiers() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.AbstractCParserExtensionConfiguration#supportDeclspecSpecifiers() + */ + public boolean supportDeclspecSpecifiers() { + // XXX Yes, this is a hack -- should use the target platform + if (Platform.getOS().equals(Platform.OS_WIN32)) + return true; + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.c.AbstractCParserExtensionConfiguration#getBuiltinSymbolProvider() + */ + public IBuiltinBindingsProvider getBuiltinBindingsProvider() { + return new GCCBuiltinSymbolProvider(ParserLanguage.C); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java similarity index 87% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCScannerExtensionConfiguration.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java index 3a946e1540c..83366f2aafd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 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 @@ -9,18 +9,21 @@ * IBM - Initial API and implementation * Ed Swartz (Nokia) *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.scanner2; +package org.eclipse.cdt.core.dom.parser.c; +import org.eclipse.cdt.core.dom.parser.GNUScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.GCCKeywords; import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner.ExpressionEvaluator; +import org.eclipse.cdt.internal.core.parser.scanner2.DynamicFunctionStyleMacro; +import org.eclipse.cdt.internal.core.parser.scanner2.ExpressionEvaluator; +import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro; /** * @author jcamelon */ -public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfiguration implements IScannerExtensionConfiguration { +public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfiguration { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#supportMinAndMaxOperators() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ICParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ICParserExtensionConfiguration.java new file mode 100644 index 00000000000..344de50f588 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/ICParserExtensionConfiguration.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2002, 2007 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + * Anton Leherbauer (Wind River Systems) + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; + + +/** + * C parser extension configuration interface. + * + *

+ * This interface is not intended to be implemented directly. + * Clients should subclass {@link AbstractCParserExtensionConfiguration} instead. + *

+ *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @see http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html + * + * @author jcamelon + * @since 4.0 + */ +public interface ICParserExtensionConfiguration { + + /** + * Support for GNU extension "Statements and Declarations in Expressions". + * @see http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html + * @return true if support for the extension should be enabled + */ + public boolean supportStatementsInExpressions(); + + /** + * Support for GNU extension "Designated Initializers". + * @see http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html + * @return true if support for the extension should be enabled + */ + public boolean supportGCCStyleDesignators(); + + /** + * Support for GNU extension "Referring to a Type with typeof". + * @see http://gcc.gnu.org/onlinedocs/gcc/Typeof.html + * @return true if support for the extension should be enabled + */ + public boolean supportTypeofUnaryExpressions(); + + /** + * Support for GNU extension "Inquiring on Alignment of Types or Variables". + * @see http://gcc.gnu.org/onlinedocs/gcc/Alignment.html + * @return true if support for the extension should be enabled + */ + public boolean supportAlignOfUnaryExpression(); + + /** + * Support for Kernighan and Richie (K&R) C. + * @return true if support for K&R C should be enabled + */ + public boolean supportKnRC(); + + /** + * See http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html + * for more information on GCC's Other Built-in Symbols. + * @return true if support for the extension should be enabled + * @deprecated use {@link #getBuiltinBindingsProvider()} instead. + */ + public boolean supportGCCOtherBuiltinSymbols(); + + /** + * See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html + * for more information on GCC's Attribute Specifiers. + * @return true if support for the extension should be enabled + */ + public boolean supportAttributeSpecifiers(); + + /** + * Win32 compiler extensions also supported by GCC on Win32 + * @return true if support for the extension should be enabled + */ + public boolean supportDeclspecSpecifiers(); + + /** + * Provide additional built-in bindings. + * @return an instance of {@link IBuiltinBindingsProvider} or null + */ + public IBuiltinBindingsProvider getBuiltinBindingsProvider(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ANSICPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ANSICPPParserExtensionConfiguration.java new file mode 100644 index 00000000000..975c4a049c8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ANSICPPParserExtensionConfiguration.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2002, 2007 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + * Anton Leherbauer (Wind River Systems) + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.cpp; + +/** + * @author jcamelon + */ +public class ANSICPPParserExtensionConfiguration extends AbstractCPPParserExtensionConfiguration { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java new file mode 100644 index 00000000000..d62207ff02d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * 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: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.cpp; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.dom.ICodeReaderFactory; +import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.model.AbstractLanguage; +import org.eclipse.cdt.core.model.IContributedModelBuilder; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.IParserLogService; +import org.eclipse.cdt.core.parser.IScanner; +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; +import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; +import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; +import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory; +import org.eclipse.core.runtime.CoreException; + +/** + * Abstract C++ language. Derived classes need only implement + * {@link getScannerExtensionConfiguration()} and + * {@link getParserExtensionConfiguration()}. + * + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @see IScannerExtensionConfiguration + * @see ICPPParserExtensionConfiguration + * + * @since 4.0 + */ +public abstract class AbstractCPPLanguage extends AbstractLanguage { + + protected static class NameCollector extends CPPASTVisitor { + { + shouldVisitNames= true; + } + + private List nameList= new ArrayList(); + + public int visit(IASTName name) { + nameList.add(name); + return PROCESS_CONTINUE; + } + + public IASTName[] getNames() { + return (IASTName[]) nameList.toArray(new IASTName[nameList.size()]); + } + } + + public Object getAdapter(Class adapter) { + if (adapter == IPDOMLinkageFactory.class) + return new PDOMCPPLinkageFactory(); + else + return super.getAdapter(adapter); + } + + public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory codeReaderFactory, IIndex index, IParserLogService log) throws CoreException { + + IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log); + ISourceCodeParser parser= createParser(scanner, log, index, false); + + // Parse + IASTTranslationUnit ast= parser.parse(); + return ast; + } + + public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException { + IScanner scanner= createScanner(reader, scanInfo, fileCreator, log); + scanner.setContentAssistMode(offset); + + ISourceCodeParser parser= createParser(scanner, log, index, true); + + // Run the parse and return the completion node + parser.parse(); + ASTCompletionNode node= parser.getCompletionNode(); + if (node != null) { + node.count= scanner.getCount(); + } + return node; + } + + public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) { + IASTNode selectedNode= ast.selectNodeForLocation(ast.getFilePath(), start, length); + + if (selectedNode == null) + return new IASTName[0]; + + if (selectedNode instanceof IASTName) + return new IASTName[] { (IASTName) selectedNode }; + + NameCollector collector= new NameCollector(); + selectedNode.accept(collector); + return collector.getNames(); + } + + public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) { + // Use the default CDT model builder + return null; + } + + /** + * Create the scanner to be used with the parser. + * + * @param reader the code reader for the main file + * @param scanInfo the scanner information (macros, include pathes) + * @param fileCreator the code reader factory for inclusions + * @param log the log for debugging + * @return an instance of IScanner + */ + protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) { + return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.C, + log, getScannerExtensionConfiguration(), fileCreator); + } + + /** + * Create the parser. + * + * @param scanner the IScanner to get tokens from + * @param log the parser log service + * @param index the index to help resolve bindings + * @param forCompletion whether the parser is used for code completion + * @return an instance of ISourceCodeParser + */ + protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion) { + ParserMode mode= forCompletion ? ParserMode.COMPLETION_PARSE : ParserMode.COMPLETE_PARSE; + return new GNUCPPSourceParser(scanner, mode, log, getParserExtensionConfiguration(), index); + } + + /** + * @return the scanner extension configuration for this language, may not + * return null + */ + protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration(); + + /** + * @return the parser extension configuration for this language, may not + * return null + */ + protected abstract AbstractCPPParserExtensionConfiguration getParserExtensionConfiguration(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java new file mode 100644 index 00000000000..5bd847a0f25 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * 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: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; + + +/** + * Abstract C++ parser extension configuration to help model C++ dialects. + * + *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @since 4.0 + */ +public abstract class AbstractCPPParserExtensionConfiguration implements ICPPParserExtensionConfiguration { + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#allowRestrictPointerOperators() + */ + public boolean allowRestrictPointerOperators() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportAlignOfUnaryExpression() + */ + public boolean supportAlignOfUnaryExpression() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportAttributeSpecifiers() + */ + public boolean supportAttributeSpecifiers() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportComplexNumbers() + */ + public boolean supportComplexNumbers() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportDeclspecSpecifiers() + */ + public boolean supportDeclspecSpecifiers() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportExtendedTemplateSyntax() + */ + public boolean supportExtendedTemplateSyntax() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportGCCOtherBuiltinSymbols() + */ + public boolean supportGCCOtherBuiltinSymbols() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportKnRC() + */ + public boolean supportKnRC() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportLongLongs() + */ + public boolean supportLongLongs() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportMinAndMaxOperators() + */ + public boolean supportMinAndMaxOperators() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportRestrictKeyword() + */ + public boolean supportRestrictKeyword() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportStatementsInExpressions() + */ + public boolean supportStatementsInExpressions() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportTypeofUnaryExpressions() + */ + public boolean supportTypeofUnaryExpressions() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#getBuiltinBindingsProvider() + */ + public IBuiltinBindingsProvider getBuiltinBindingsProvider() { + if (supportGCCOtherBuiltinSymbols()) { + return new GCCBuiltinSymbolProvider(ParserLanguage.CPP); + } + return null; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java new file mode 100644 index 00000000000..b3e82a2a1e7 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2002, 2007 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; +import org.eclipse.core.runtime.Platform; + +/** + * @author jcamelon + */ +public class GPPParserExtensionConfiguration extends AbstractCPPParserExtensionConfiguration { + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#allowRestrictPointerOperators() + */ + public boolean allowRestrictPointerOperators() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportTypeofUnaryExpressions() + */ + public boolean supportTypeofUnaryExpressions() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportAlignOfUnaryExpression() + */ + public boolean supportAlignOfUnaryExpression() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportExtendedTemplateSyntax() + */ + public boolean supportExtendedTemplateSyntax() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportMinAndMaxOperators() + */ + public boolean supportMinAndMaxOperators() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportStatementsInExpressions() + */ + public boolean supportStatementsInExpressions() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportComplexNumbers() + */ + public boolean supportComplexNumbers() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportRestrictKeyword() + */ + public boolean supportRestrictKeyword() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportLongLongs() + */ + public boolean supportLongLongs() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportKnRC() + */ + public boolean supportKnRC() { + return false; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportAttributeSpecifiers() + */ + public boolean supportAttributeSpecifiers() { + return true; + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#supportDeclspecSpecifiers() + */ + public boolean supportDeclspecSpecifiers() { + // XXX: a hack, should use the target's platform + return Platform.getOS().equals(Platform.OS_WIN32); + } + + /* + * @see org.eclipse.cdt.core.dom.parser.cpp.AbstractCPPParserExtensionConfiguration#getBuiltinBindingsProvider() + */ + public IBuiltinBindingsProvider getBuiltinBindingsProvider() { + return new GCCBuiltinSymbolProvider(ParserLanguage.CPP); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java similarity index 91% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPScannerExtensionConfiguration.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java index 5c799a02e4f..2984be5df35 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java @@ -9,8 +9,10 @@ * IBM - Initial API and implementation * Ed Swartz (Nokia) *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.scanner2; +package org.eclipse.cdt.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.parser.GNUScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.GCCKeywords; import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IToken; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPParserExtensionConfiguration.java new file mode 100644 index 00000000000..56bfe54aded --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPParserExtensionConfiguration.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2002, 2007 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) + * Anton Leherbauer (Wind River Systems) + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; + + +/** + * C++ parser extension configuration interface. + * + *

+ * This interface is not intended to be implemented directly. + * Clients should subclass {@link AbstractCPPParserExtensionConfiguration} instead. + *

+ *

+ * EXPERIMENTAL. This class or interface has been added as + * part of a work in progress. There is no guarantee that this API will work or + * that it will remain the same. Please do not use this API without consulting + * with the CDT team. + *

+ * + * @see http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html + * @see http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Extensions.html + * + * @author jcamelon + * @since 4.0 + */ +public interface ICPPParserExtensionConfiguration { + + /** + * Support for GNU extension "Restricting Pointer Aliasing". + * @see http://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html + * @return true if support for the extension should be enabled + */ + public boolean allowRestrictPointerOperators(); + + /** + * Support for GNU extension "Extended Syntax for Template Instantiation". + * @see http://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html + * @return true if support for the extension should be enabled + */ + public boolean supportExtendedTemplateSyntax(); + + /** + * Support for (deprecated) GNU minimum and maximum operators (`?'). + * @see http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html + * @return true if support for the extension should be enabled + */ + public boolean supportMinAndMaxOperators(); + + /** + * Support for GNU extension "Data types for complex numbers". + * @see http://gcc.gnu.org/onlinedocs/gcc/Complex.html#Complex + * @return true if support for the extension should be enabled + */ + public boolean supportComplexNumbers(); + + /** + * Support for the GNU __restrict__ keyword. + * @return true if support for the extension should be enabled + */ + public boolean supportRestrictKeyword(); + + /** + * Support for GNU long long types. + * @see http://gcc.gnu.org/onlinedocs/gcc/Long-Long.html + * @return true if support for the extension should be enabled + */ + public boolean supportLongLongs(); + + /** + * Support for GNU extension "Statements and Declarations in Expressions". + * @see http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html + * @return true if support for the extension should be enabled + */ + public boolean supportStatementsInExpressions(); + + /** + * Support for GNU extension "Referring to a Type with typeof". + * @see http://gcc.gnu.org/onlinedocs/gcc/Typeof.html + * @return true if support for the extension should be enabled + */ + public boolean supportTypeofUnaryExpressions(); + + /** + * Support for GNU extension "Inquiring on Alignment of Types or Variables". + * @see http://gcc.gnu.org/onlinedocs/gcc/Alignment.html + * @return true if support for the extension should be enabled + */ + public boolean supportAlignOfUnaryExpression(); + + /** + * Support for Kernighan and Richie (K&R) C. + * @return true if support for K&R C should be enabled + */ + public boolean supportKnRC(); + + /** + * See http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html + * for more information on GCC's Other Built-in Symbols. + * @return true if support for the extension should be enabled + * @deprecated use {@link #getBuiltinSymbolProvider(IScope)} instead. + */ + public boolean supportGCCOtherBuiltinSymbols(); + + /** + * See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html + * for more information on GCC's Attribute Specifiers. + * @return true if support for the extension should be enabled + */ + public boolean supportAttributeSpecifiers(); + + /** + * Win32 compiler extensions also supported by GCC on Win32 + * @return true if support for the extension should be enabled + */ + public boolean supportDeclspecSpecifiers(); + + /** + * Provide additional built-in bindings. + * @return an instance of {@link IBuiltinBindingsProvider} or null + */ + public IBuiltinBindingsProvider getBuiltinBindingsProvider(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java index ecd407f0653..31f399850e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. + * Copyright (c) 2002, 2007 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 @@ -14,6 +14,7 @@ import java.io.IOException; import java.util.List; import java.util.Set; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.ast.IASTFactory; import org.eclipse.cdt.core.parser.extension.ExtensionDialect; import org.eclipse.cdt.core.parser.extension.IParserExtension; @@ -26,7 +27,6 @@ import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory; import org.eclipse.cdt.internal.core.parser.scanner2.GCCOldScannerExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.scanner2.GPPOldScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2; import org.eclipse.cdt.internal.core.parser.token.KeywordSets; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 6ed751465ff..6bb1731b037 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -60,6 +60,8 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; 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; +import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.core.parser.AbstractParserLogService; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IGCCToken; @@ -89,18 +91,19 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected final boolean supportKnRC; - protected final boolean supportGCCOtherBuiltinSymbols; - protected final boolean supportAttributeSpecifiers; protected final boolean supportDeclspecSpecifiers; + protected final IBuiltinBindingsProvider builtinBindingsProvider; + protected AbstractGNUSourceCodeParser(IScanner scanner, IParserLogService logService, ParserMode parserMode, boolean supportStatementsInExpressions, boolean supportTypeOfUnaries, boolean supportAlignOfUnaries, - boolean supportKnRC, boolean supportGCCOtherBuiltinSymbols, - boolean supportAttributeSpecifiers, boolean supportDeclspecSpecifiers) { + boolean supportKnRC, boolean supportAttributeSpecifiers, + boolean supportDeclspecSpecifiers, + IBuiltinBindingsProvider builtinBindingsProvider) { this.scanner = scanner; this.log = wrapLogService(logService); this.mode = parserMode; @@ -108,9 +111,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { this.supportTypeOfUnaries = supportTypeOfUnaries; this.supportAlignOfUnaries = supportAlignOfUnaries; this.supportKnRC = supportKnRC; - this.supportGCCOtherBuiltinSymbols = supportGCCOtherBuiltinSymbols; this.supportAttributeSpecifiers = supportAttributeSpecifiers; this.supportDeclspecSpecifiers = supportDeclspecSpecifiers; + this.builtinBindingsProvider= builtinBindingsProvider; } protected boolean parsePassed = true; @@ -2303,7 +2306,36 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } } } - + + /** + * Hook method to support (skip) additional declspec modifiers. + * @throws BacktrackException + * @throws EndOfFileException + */ + protected void handleOtherDeclSpecModifier() throws BacktrackException, EndOfFileException { + // default action: consume keyword plus optional parenthesised "something" + consume(); + + IToken token = LA(1); + + if (token.getType() == IToken.tLPAREN) { + consume(); + int openParen= 1; + while(true) { + token = LA(1); + consume(); + if (token.getType() == IToken.tLPAREN) { + ++openParen; + } else if (token.getType() == IToken.tRPAREN) { + --openParen; + if (openParen == 0) { + break; + } + } + } + } + } + /** * In case a cast expression is followed by +/- or & we should avoid it: * (a)+1 vs. (int)+1; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java index fd7f132cab4..1ca22d324fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 @@ -8,12 +8,12 @@ * Contributors: * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; -import org.eclipse.cdt.core.dom.ast.IASTBuiltinSymbolProvider; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunctionType; @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; +import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.Linkage; @@ -42,12 +43,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPPointerType; import org.eclipse.core.runtime.PlatformObject; /** - * This is the IASTBuiltinSymbolProvider used to implement the "Other" built-in GCC symbols defined: + * This is the IBuiltinBindingsProvider used to implement the "Other" built-in GCC symbols defined: * http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#Other-Builtins * * @author dsteffle */ -public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider { +public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { /** * BUILTIN_GCC_SYMBOL is a built-in GCC symbol. */ @@ -290,12 +291,11 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider { private IBinding[] bindings=new IBinding[NUM_OTHER_GCC_BUILTINS]; private IScope scope=null; private ParserLanguage lang=null; - public GCCBuiltinSymbolProvider(IScope scope, ParserLanguage lang) { - this.scope = scope; + public GCCBuiltinSymbolProvider(ParserLanguage lang) { this.lang = lang; } - public void initialize() { + private void initialize() { __builtin_va_list(); __builtin_expect(); __builtin_prefetch(); @@ -913,7 +913,7 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider { bindings = (IBinding[])ArrayUtil.append(IBinding.class, bindings, temp); } - public void __builtin_exit() { + private void __builtin_exit() { // void __builtin_abort(void) IBinding temp = null; if (lang == ParserLanguage.C) { @@ -2148,7 +2148,7 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider { bindings = (IBinding[])ArrayUtil.append(IBinding.class, bindings, temp); } - public void __builtin_less_greater() { + private void __builtin_less_greater() { IBinding temp = null; // int __builtin_isgreater(real-floating, real-floating) if (lang == ParserLanguage.C) { @@ -2294,7 +2294,8 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider { bindings = (IBinding[])ArrayUtil.append(IBinding.class, bindings, temp); } - public IBinding[] getBuiltinBindings() { + public IBinding[] getBuiltinBindings(IScope scope) { + this.scope= scope; initialize(); return (IBinding[])ArrayUtil.trim(IBinding.class, bindings); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ANSICParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ANSICParserExtensionConfiguration.java deleted file mode 100644 index 15441b2015d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ANSICParserExtensionConfiguration.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - * Ed Swartz (Nokia) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.dom.parser.c; - -/** - * @author jcamelon - */ -public class ANSICParserExtensionConfiguration implements - ICParserExtensionConfiguration { - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportStatementsInExpressions() - */ - public boolean supportStatementsInExpressions() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportGCCStyleDesignators() - */ - public boolean supportGCCStyleDesignators() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportTypeofUnaryExpressions() - */ - public boolean supportTypeofUnaryExpressions() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportAlignOfUnaryExpression() - */ - public boolean supportAlignOfUnaryExpression() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportKnRC() - */ - public boolean supportKnRC() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportGCCBuiltinSymbols() - */ - public boolean supportGCCOtherBuiltinSymbols() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportAttributeSpecifiers() - */ - public boolean supportAttributeSpecifiers() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration#supportDeclspecSpecifiers() - */ - public boolean supportDeclspecSpecifiers() { - return false; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 8ef0ac4a401..abc5489c71a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -40,10 +40,7 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; -import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage; import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.util.ArrayUtil; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCParserExtensionConfiguration.java deleted file mode 100644 index 307a702fdd5..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GCCParserExtensionConfiguration.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - * Ed Swartz (Nokia) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.dom.parser.c; - -import org.eclipse.core.runtime.Platform; - -/** - * @author jcamelon - */ -public class GCCParserExtensionConfiguration implements - ICParserExtensionConfiguration { - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportStatementsInExpressions() - */ - public boolean supportStatementsInExpressions() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportGCCStyleDesignators() - */ - public boolean supportGCCStyleDesignators() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportTypeofUnaryExpressions() - */ - public boolean supportTypeofUnaryExpressions() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportAlignOfUnaryExpression() - */ - public boolean supportAlignOfUnaryExpression() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration#supportKRCSyntax() - */ - public boolean supportKnRC() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportGCCOtherBuiltinSymbols() - */ - public boolean supportGCCOtherBuiltinSymbols() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportAttributeSpecifiers() - */ - public boolean supportAttributeSpecifiers() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration#supportDeclspecSpecifiers() - */ - public boolean supportDeclspecSpecifiers() { - // XXX Yes, this is a hack -- should use the target platform - if (Platform.getOS().equals(Platform.OS_WIN32)) - return true; - return false; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 914b3b98b87..dba24e9a19e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -94,6 +94,8 @@ import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.parser.IExtensionToken; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IGCCToken; @@ -101,7 +103,6 @@ import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ParseError; -import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -109,7 +110,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.BacktrackException; -import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement; @@ -143,13 +143,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { public GNUCSourceParser(IScanner scanner, ParserMode parserMode, IParserLogService logService, ICParserExtensionConfiguration config, IIndex index) { - super(scanner, logService, parserMode, config - .supportStatementsInExpressions(), config - .supportTypeofUnaryExpressions(), config - .supportAlignOfUnaryExpression(), config - .supportKnRC(), config.supportGCCOtherBuiltinSymbols(), - config.supportAttributeSpecifiers(), - config.supportDeclspecSpecifiers()); + super(scanner, logService, parserMode, + config.supportStatementsInExpressions(), + config.supportTypeofUnaryExpressions(), + config.supportAlignOfUnaryExpression(), + config.supportKnRC(), + config.supportAttributeSpecifiers(), + config.supportDeclspecSpecifiers(), + config.getBuiltinBindingsProvider()); supportGCCStyleDesignators = config.supportGCCStyleDesignators(); this.index= index; } @@ -593,10 +594,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { translationUnit.setIndex(index); // add built-in names to the scope - if (supportGCCOtherBuiltinSymbols) { + if (builtinBindingsProvider != null) { IScope tuScope = translationUnit.getScope(); - IBinding[] bindings = new GCCBuiltinSymbolProvider(translationUnit.getScope(), ParserLanguage.C).getBuiltinBindings(); + IBinding[] bindings = builtinBindingsProvider.getBuiltinBindings(tuScope); for(int i=0; i= IExtensionToken.t__otherDeclSpecModifierFirst && LT(1) <= IExtensionToken.t__otherDeclSpecModifierLast) { + handleOtherDeclSpecModifier(); + break; + } + if (supportTypeOfUnaries && LT(1) == IGCCToken.t_typeof) { typeofExpression = unaryTypeofExpression(); if (typeofExpression != null) { flags.setEncounteredTypename(true); @@ -1694,7 +1699,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return declSpec; } - /** + /** * @return */ protected ICASTSimpleDeclSpecifier createSimpleTypeSpecifier() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICParserExtensionConfiguration.java deleted file mode 100644 index 03b29f55249..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICParserExtensionConfiguration.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - * Ed Swartz (Nokia) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.dom.parser.c; - -/** - * @author jcamelon - */ -public interface ICParserExtensionConfiguration { - - public boolean supportStatementsInExpressions(); - public boolean supportGCCStyleDesignators(); - public boolean supportTypeofUnaryExpressions(); - public boolean supportAlignOfUnaryExpression(); - public boolean supportKnRC(); - - /** - * See http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#Other-Builtins - * for more information on GCC's Other Built-in Symbols. - * @return - */ - public boolean supportGCCOtherBuiltinSymbols(); - - /** - * See http://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Attribute-Syntax.html#Attribute-Syntax - * for more information on GCC's Attribute Specifiers. - * @return - */ - public boolean supportAttributeSpecifiers(); - - /** - * Win32 compiler extensions also supported by GCC on Win32 - * @return - */ - public boolean supportDeclspecSpecifiers(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ANSICPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ANSICPPParserExtensionConfiguration.java deleted file mode 100644 index effdae80de3..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ANSICPPParserExtensionConfiguration.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - * Ed Swartz (Nokia) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.dom.parser.cpp; - -/** - * @author jcamelon - */ -public class ANSICPPParserExtensionConfiguration implements - ICPPParserExtensionConfiguration { - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#allowRestrictPointerOperators() - */ - public boolean allowRestrictPointerOperators() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportTypeofUnaryExpressions() - */ - public boolean supportTypeofUnaryExpressions() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportAlignOfUnaryExpression() - */ - public boolean supportAlignOfUnaryExpression() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportExtendedTemplateSyntax() - */ - public boolean supportExtendedTemplateSyntax() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportMinAndMaxOperators() - */ - public boolean supportMinAndMaxOperators() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportStatementsInExpressions() - */ - public boolean supportStatementsInExpressions() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportComplexNumbers() - */ - public boolean supportComplexNumbers() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportRestrictKeyword() - */ - public boolean supportRestrictKeyword() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportLongLongs() - */ - public boolean supportLongLongs() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportGCCOtherBuiltinSymbols() - */ - public boolean supportGCCOtherBuiltinSymbols() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportKnRC() - */ - public boolean supportKnRC() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportAttributeSpecifiers() - */ - public boolean supportAttributeSpecifiers() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportDeclspecSpecifiers() - */ - public boolean supportDeclspecSpecifiers() { - return false; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 35fd26b535e..ac5d8721f8b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -54,10 +54,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; -import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.util.ArrayUtil; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 7790de72fc6..90a74213efa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -134,6 +134,8 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.parser.IExtensionToken; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IGCCToken; @@ -142,14 +144,12 @@ import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ParseError; -import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.BacktrackException; -import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement; @@ -1993,11 +1993,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { public GNUCPPSourceParser(IScanner scanner, ParserMode mode, IParserLogService log, ICPPParserExtensionConfiguration config, IIndex index) { - super(scanner, log, mode, config.supportStatementsInExpressions(), - config.supportTypeofUnaryExpressions(), config - .supportAlignOfUnaryExpression(), config.supportKnRC(), - config.supportGCCOtherBuiltinSymbols(), config.supportAttributeSpecifiers(), - config.supportDeclspecSpecifiers()); + super(scanner, log, mode, + config.supportStatementsInExpressions(), + config.supportTypeofUnaryExpressions(), + config.supportAlignOfUnaryExpression(), + config.supportKnRC(), + config.supportAttributeSpecifiers(), + config.supportDeclspecSpecifiers(), + config.getBuiltinBindingsProvider()); allowCPPRestrict = config.allowRestrictPointerOperators(); supportExtendedTemplateSyntax = config.supportExtendedTemplateSyntax(); supportMinAndMaxOperators = config.supportMinAndMaxOperators(); @@ -3504,7 +3507,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break; default: - if (supportTypeOfUnaries && LT(1) == IGCCToken.t_typeof) { + if (LT(1) >= IExtensionToken.t__otherDeclSpecModifierFirst && LT(1) <= IExtensionToken.t__otherDeclSpecModifierLast) { + handleOtherDeclSpecModifier(); + break; + } + if (supportTypeOfUnaries && LT(1) == IGCCToken.t_typeof) { typeofExpression = unaryTypeofExpression(); if (typeofExpression != null) { flags.setEncounteredTypename(true); @@ -4674,16 +4681,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { translationUnit.setIndex(index); // add built-in names to the scope - if (supportGCCOtherBuiltinSymbols) { - IScope tuScope = translationUnit.getScope(); - - IBinding[] bindings = new GCCBuiltinSymbolProvider( - translationUnit.getScope(), ParserLanguage.CPP) - .getBuiltinBindings(); - for (int i = 0; i < bindings.length; i++) { - ASTInternal.addBinding(tuScope, bindings[i]); - } - } + // add built-in names to the scope + if (builtinBindingsProvider != null) { + IScope tuScope = translationUnit.getScope(); + + IBinding[] bindings = builtinBindingsProvider.getBuiltinBindings(tuScope); + for(int i=0; i= 0) - popContext(); - - return r; - } - - private static class EvalException extends Exception { - private static final long serialVersionUID = 0; - public EvalException(String msg) { - super(msg); - } - } - - private long expression() throws EvalException { - return conditionalExpression(); - } - - private long conditionalExpression() throws EvalException { - long r1 = logicalOrExpression(); - if (LA() == tQUESTION) { - consume(); - long r2 = expression(); - if (LA() == tCOLON) - consume(); - else { - handleProblem(IProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION, - pos); - throw new EvalException("bad conditional expression"); //$NON-NLS-1$ - } - long r3 = conditionalExpression(); - return r1 != 0 ? r2 : r3; - } - return r1; - } - - private long logicalOrExpression() throws EvalException { - long r1 = logicalAndExpression(); - while (LA() == tOR) { - consume(); - long r2 = logicalAndExpression(); - r1 = ((r1 != 0) || (r2 != 0)) ? 1 : 0; - } - return r1; - } - - private long logicalAndExpression() throws EvalException { - long r1 = inclusiveOrExpression(); - while (LA() == tAND) { - consume(); - long r2 = inclusiveOrExpression(); - r1 = ((r1 != 0) && (r2 != 0)) ? 1 : 0; - } - return r1; - } - - private long inclusiveOrExpression() throws EvalException { - long r1 = exclusiveOrExpression(); - while (LA() == tBITOR) { - consume(); - long r2 = exclusiveOrExpression(); - r1 = r1 | r2; - } - return r1; - } - - private long exclusiveOrExpression() throws EvalException { - long r1 = andExpression(); - while (LA() == tBITXOR) { - consume(); - long r2 = andExpression(); - r1 = r1 ^ r2; - } - return r1; - } - - private long andExpression() throws EvalException { - long r1 = equalityExpression(); - while (LA() == tBITAND) { - consume(); - long r2 = equalityExpression(); - r1 = r1 & r2; - } - return r1; - } - - private long equalityExpression() throws EvalException { - long r1 = relationalExpression(); - for (int t = LA(); t == tEQUAL || t == tNOTEQUAL; t = LA()) { - consume(); - long r2 = relationalExpression(); - if (t == tEQUAL) - r1 = (r1 == r2) ? 1 : 0; - else - // t == tNOTEQUAL - r1 = (r1 != r2) ? 1 : 0; - } - return r1; - } - - private long relationalExpression() throws EvalException { - long r1 = shiftExpression(); - for (int t = LA(); t == tLT || t == tLTEQUAL || t == tGT - || t == tGTEQUAL; t = LA()) { - consume(); - long r2 = shiftExpression(); - switch (t) { - case tLT: - r1 = (r1 < r2) ? 1 : 0; - break; - case tLTEQUAL: - r1 = (r1 <= r2) ? 1 : 0; - break; - case tGT: - r1 = (r1 > r2) ? 1 : 0; - break; - case tGTEQUAL: - r1 = (r1 >= r2) ? 1 : 0; - break; - } - } - return r1; - } - - private long shiftExpression() throws EvalException { - long r1 = additiveExpression(); - for (int t = LA(); t == tSHIFTL || t == tSHIFTR; t = LA()) { - consume(); - long r2 = additiveExpression(); - if (t == tSHIFTL) - r1 = r1 << r2; - else - // t == tSHIFTR - r1 = r1 >> r2; - } - return r1; - } - - private long additiveExpression() throws EvalException { - long r1 = multiplicativeExpression(); - for (int t = LA(); t == tPLUS || t == tMINUS; t = LA()) { - consume(); - long r2 = multiplicativeExpression(); - if (t == tPLUS) - r1 = r1 + r2; - else - // t == tMINUS - r1 = r1 - r2; - } - return r1; - } - - private long multiplicativeExpression() throws EvalException { - long r1 = unaryExpression(); - for (int t = LA(); t == tMULT || t == tDIV || t == tMOD; t = LA()) { - int position = pos; // for IProblem /0 below, need position - // before - // consume() - consume(); - long r2 = unaryExpression(); - if (t == tMULT) - r1 = r1 * r2; - else if (r2 != 0) { - if (t == tDIV) - r1 = r1 / r2; - else - r1 = r1 % r2; //tMOD - } else { - handleProblem(IProblem.SCANNER_DIVIDE_BY_ZERO, position); - throw new EvalException("Divide by 0 encountered"); //$NON-NLS-1$ - } - } - return r1; - } - - private long unaryExpression() throws EvalException { - switch (LA()) { - case tPLUS: - consume(); - return unaryExpression(); - case tMINUS: - consume(); - return -unaryExpression(); - case tNOT: - consume(); - return unaryExpression() == 0 ? 1 : 0; - case tCOMPL: - consume(); - return ~unaryExpression(); - case tNUMBER: - return consume(); - case t_defined: - return handleDefined(); - case tLPAREN: - consume(); - long r1 = expression(); - if (LA() == tRPAREN) { - consume(); - return r1; - } - handleProblem(IProblem.SCANNER_MISSING_R_PAREN, pos); - throw new EvalException("missing )"); //$NON-NLS-1$ - case tCHAR: - return getChar(); - default: - handleProblem(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, pos); - throw new EvalException("expression syntax error"); //$NON-NLS-1$ - } - } - - private long handleDefined() throws EvalException { - // We need to do some special handline to get the identifier without - // it - // being - // expanded by macro expansion - skipWhiteSpace(); - - char[] buffer = bufferStack[bufferStackPos]; - int limit = bufferLimit[bufferStackPos]; - if (++bufferPos[bufferStackPos] >= limit) - return 0; - - // check first character - char c = buffer[bufferPos[bufferStackPos]]; - boolean inParens = false; - if (c == '(') { - inParens = true; - skipWhiteSpace(); - if (++bufferPos[bufferStackPos] >= limit) - return 0; - c = buffer[bufferPos[bufferStackPos]]; - } - - if (!((c >= 'A' && c <= 'Z') || c == '_' || (c >= 'a' && c <= 'z'))) { - handleProblem(IProblem.SCANNER_ILLEGAL_IDENTIFIER, pos); - throw new EvalException("illegal identifier in defined()"); //$NON-NLS-1$ - } - - // consume rest of identifier - int idstart = bufferPos[bufferStackPos]; - int idlen = 1; - while (++bufferPos[bufferStackPos] < limit) { - c = buffer[bufferPos[bufferStackPos]]; - if ((c >= 'A' && c <= 'Z') || c == '_' - || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) { - ++idlen; - continue; - } - break; - } - --bufferPos[bufferStackPos]; - - // consume to the closing paren; - if (inParens) { - skipWhiteSpace(); - if (++bufferPos[bufferStackPos] <= limit - && buffer[bufferPos[bufferStackPos]] != ')') { - handleProblem(IProblem.SCANNER_MISSING_R_PAREN, pos); - throw new EvalException("missing ) on defined"); //$NON-NLS-1$ - } - } - - // Set up the lookahead to whatever comes next - nextToken(); - - return definitions.get(buffer, idstart, idlen) != null ? 1 : 0; - } - - // Scanner part - int tokenType = tNULL; - - long tokenValue; - - private int LA() throws EvalException { - if (tokenType == tNULL) - nextToken(); - return tokenType; - } - - private long consume() throws EvalException { - long value = tokenValue; - if (tokenType != tEOF) - nextToken(); - return value; - } - - private long getChar() throws EvalException { - long value = 0; - - // if getting a character then make sure it's in '' otherwise leave - // it - // as 0 - if (bufferPos[bufferStackPos] - 1 >= 0 - && bufferPos[bufferStackPos] + 1 < bufferStack[bufferStackPos].length - && bufferStack[bufferStackPos][bufferPos[bufferStackPos] - 1] == '\'' - && bufferStack[bufferStackPos][bufferPos[bufferStackPos] + 1] == '\'') - value = bufferStack[bufferStackPos][bufferPos[bufferStackPos]]; - - if (tokenType != tEOF) - nextToken(); - return value; - } - - private static char[] _defined = "defined".toCharArray(); //$NON-NLS-1$ - - private void nextToken() throws EvalException { - boolean isHex = false; - boolean isOctal = false; - boolean isDecimal = false; - - contextLoop: while (bufferStackPos >= 0) { - - // Find the first thing we would care about - skipWhiteSpace(); - - while (++bufferPos[bufferStackPos] >= bufferLimit[bufferStackPos]) { - // We're at the end of a context, pop it off and try again - popContext(); - continue contextLoop; - } - - // Tokens don't span buffers, stick to our current one - char[] buffer = bufferStack[bufferStackPos]; - int limit = bufferLimit[bufferStackPos]; - pos = bufferPos[bufferStackPos]; - - if (buffer[pos] >= '1' && buffer[pos] <= '9') - isDecimal = true; - else if (buffer[pos] == '0' && pos + 1 < limit) - if (buffer[pos + 1] == 'x' || buffer[pos + 1] == 'X') { - isHex = true; - ++bufferPos[bufferStackPos]; - if (pos + 2 < limit) - if ((buffer[pos + 2] < '0' || buffer[pos + 2] > '9') - && (buffer[pos + 2] < 'a' || buffer[pos + 2] > 'f') - && (buffer[pos + 2] < 'A' || buffer[pos + 2] > 'F')) - handleProblem(IProblem.SCANNER_BAD_HEX_FORMAT, - pos); - } else - isOctal = true; - - switch (buffer[pos]) { - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - int start = bufferPos[bufferStackPos]; - int len = 1; - - while (++bufferPos[bufferStackPos] < limit) { - char c = buffer[bufferPos[bufferStackPos]]; - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') - || c == '_' || (c >= '0' && c <= '9')) { - ++len; - continue; - } - break; - } - - --bufferPos[bufferStackPos]; - - // Check for defined( - pos = bufferPos[bufferStackPos]; - if (CharArrayUtils.equals(buffer, start, len, _defined)) { - tokenType = t_defined; - return; - } - - // Check for macro expansion - Object expObject = null; - if (bufferData[bufferStackPos] instanceof FunctionStyleMacro.Expansion) { - // first check if name is a macro arg - expObject = ((FunctionStyleMacro.Expansion) bufferData[bufferStackPos]).definitions - .get(buffer, start, len); - } - - if (expObject == null) - // now check regular macros - expObject = definitions.get(buffer, start, len); - - if (expObject != null) { - if (expObject instanceof FunctionStyleMacro) { - handleFunctionStyleMacro((FunctionStyleMacro) expObject); - } else if (expObject instanceof ObjectStyleMacro) { - ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject; - char[] expText = expMacro.getExpansion(); - if (expText.length > 0 ) - { - if (shouldExpandMacro(expMacro, bufferStackPos, bufferData, -1, bufferPos, bufferStack )) - pushContext(expText, new MacroData(start, start + len, expMacro)); - else - { - if (len == 1) { // is a character - tokenType = tCHAR; - return; - } - // undefined macro, assume 0 - tokenValue = 0; - tokenType = tNUMBER; - return; - - } - - } - } else if (expObject instanceof char[]) { - char[] expText = (char[]) expObject; - if (expText.length > 0) - pushContext(expText, null); - } - continue; - } - - if (len == 1) { // is a character - tokenType = tCHAR; - return; - } - - // undefined macro, assume 0 - tokenValue = 0; - tokenType = tNUMBER; - return; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - tokenValue = buffer[pos] - '0'; - tokenType = tNUMBER; - - while (++bufferPos[bufferStackPos] < limit) { - char c = buffer[bufferPos[bufferStackPos]]; - if (isHex) { - if (c >= '0' && c <= '9') { - tokenValue *= 16; - tokenValue += c - '0'; - continue; - } else if (c >= 'a' && c <= 'f') { - tokenValue = (tokenValue == 0 ? 10 - : (tokenValue * 16) + 10); - tokenValue += c - 'a'; - continue; - } else if (c >= 'A' && c <= 'F') { - tokenValue = (tokenValue == 0 ? 10 - : (tokenValue * 16) + 10); - tokenValue += c - 'A'; - continue; - } else { - if (bufferPos[bufferStackPos] + 1 < limit) - if (!isValidTokenSeparator( - c, - buffer[bufferPos[bufferStackPos] + 1])) - handleProblem( - IProblem.SCANNER_BAD_HEX_FORMAT, - pos); - } - } else if (isOctal) { - if (c >= '0' && c <= '7') { - tokenValue *= 8; - tokenValue += c - '0'; - continue; - } - if (bufferPos[bufferStackPos] + 1 < limit) - if (!isValidTokenSeparator(c, - buffer[bufferPos[bufferStackPos] + 1])) - handleProblem( - IProblem.SCANNER_BAD_OCTAL_FORMAT, - pos); - } else if (isDecimal) { - if (c >= '0' && c <= '9') { - tokenValue *= 10; - tokenValue += c - '0'; - continue; - } - if (bufferPos[bufferStackPos] + 1 < limit - && !(c == 'L' || c == 'l' || c == 'U' || c == 'u')) - if (!isValidTokenSeparator(c, - buffer[bufferPos[bufferStackPos] + 1])) - handleProblem( - IProblem.SCANNER_BAD_DECIMAL_FORMAT, - pos); - } - - // end of number - if (c == 'L' || c == 'l' || c == 'U' || c == 'u') { - // eat the long/unsigned - ++bufferPos[bufferStackPos]; - } - - // done - break; - } - --bufferPos[bufferStackPos]; - return; - case '(': - tokenType = tLPAREN; - return; - - case ')': - tokenType = tRPAREN; - return; - - case ':': - tokenType = tCOLON; - return; - - case '?': - tokenType = tQUESTION; - return; - - case '+': - tokenType = tPLUS; - return; - - case '-': - tokenType = tMINUS; - return; - - case '*': - tokenType = tMULT; - return; - - case '/': - tokenType = tDIV; - return; - - case '%': - tokenType = tMOD; - return; - - case '^': - tokenType = tBITXOR; - return; - - case '&': - if (pos + 1 < limit && buffer[pos + 1] == '&') { - ++bufferPos[bufferStackPos]; - tokenType = tAND; - return; - } - tokenType = tBITAND; - return; - - case '|': - if (pos + 1 < limit && buffer[pos + 1] == '|') { - ++bufferPos[bufferStackPos]; - tokenType = tOR; - return; - } - tokenType = tBITOR; - return; - - case '~': - tokenType = tCOMPL; - return; - - case '!': - if (pos + 1 < limit && buffer[pos + 1] == '=') { - ++bufferPos[bufferStackPos]; - tokenType = tNOTEQUAL; - return; - } - tokenType = tNOT; - return; - - case '=': - if (pos + 1 < limit && buffer[pos + 1] == '=') { - ++bufferPos[bufferStackPos]; - tokenType = tEQUAL; - return; - } - handleProblem(IProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED, pos); - throw new EvalException("assignment not allowed"); //$NON-NLS-1$ - - case '<': - if (pos + 1 < limit) { - if (buffer[pos + 1] == '=') { - ++bufferPos[bufferStackPos]; - tokenType = tLTEQUAL; - return; - } else if (buffer[pos + 1] == '<') { - ++bufferPos[bufferStackPos]; - tokenType = tSHIFTL; - return; - } - } - tokenType = tLT; - return; - - case '>': - if (pos + 1 < limit) { - if (buffer[pos + 1] == '=') { - ++bufferPos[bufferStackPos]; - tokenType = tGTEQUAL; - return; - } else if (buffer[pos + 1] == '>') { - ++bufferPos[bufferStackPos]; - tokenType = tSHIFTR; - return; - } - } - tokenType = tGT; - return; - - default: - // skip over anything we don't handle - } - } - - // We've run out of contexts, our work is done here - tokenType = tEOF; - return; - } - - private void handleFunctionStyleMacro(FunctionStyleMacro macro) { - char[] buffer = bufferStack[bufferStackPos]; - int limit = bufferLimit[bufferStackPos]; - - skipWhiteSpace(); - if (++bufferPos[bufferStackPos] >= limit - || buffer[bufferPos[bufferStackPos]] != '(') - return; - - FunctionStyleMacro.Expansion exp = macro.new Expansion(); - char[][] arglist = macro.arglist; - int currarg = -1; - int parens = 0; - - while (bufferPos[bufferStackPos] < limit) { - if (++currarg >= arglist.length || arglist[currarg] == null) - // too many args - break; - - skipWhiteSpace(); - - int p = ++bufferPos[bufferStackPos]; - char c = buffer[p]; - if (c == ')') { - if (parens == 0) - // end of macro - break; - --parens; - continue; - } else if (c == ',') { - // empty arg - exp.definitions.put(arglist[currarg], emptyCharArray); - continue; - } else if (c == '(') { - ++parens; - continue; - } - - // peel off the arg - int argstart = p; - int argend = argstart - 1; - - // Loop looking for end of argument - while (bufferPos[bufferStackPos] < limit) { - skipOverMacroArg(); - argend = bufferPos[bufferStackPos]; - skipWhiteSpace(); - - if (++bufferPos[bufferStackPos] >= limit) - break; - c = buffer[bufferPos[bufferStackPos]]; - if (c == ',' || c == ')') - break; - } - - char[] arg = emptyCharArray; - int arglen = argend - argstart + 1; - if (arglen > 0) { - arg = new char[arglen]; - System.arraycopy(buffer, argstart, arg, 0, arglen); - } - exp.definitions.put(arglist[currarg], arg); - - if (c == ')') - break; - } - - char[] expText = macro.getExpansion(); - if (expText.length > 0) - pushContext(expText, exp); - } - - private void skipOverMacroArg() { - char[] buffer = bufferStack[bufferStackPos]; - int limit = bufferLimit[bufferStackPos]; - - while (++bufferPos[bufferStackPos] < limit) { - switch (buffer[bufferPos[bufferStackPos]]) { - case ' ': - case '\t': - case '\r': - case ',': - case ')': - --bufferPos[bufferStackPos]; - return; - case '\n': - lineNumber++; - --bufferPos[bufferStackPos]; - return; - case '\\': - int p = bufferPos[bufferStackPos]; - if (p + 1 < limit && buffer[p + 1] == '\n') { - // \n is whitespace - lineNumber++; - --bufferPos[bufferStackPos]; - return; - } - break; - case '"': - boolean escaped = false; - loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) { - switch (buffer[bufferPos[bufferStackPos]]) { - case '\\': - escaped = !escaped; - continue; - case '"': - if (escaped) { - escaped = false; - continue; - } - break loop; - default: - escaped = false; - } - } - break; - } - } - --bufferPos[bufferStackPos]; - } - - private void skipWhiteSpace() { - char[] buffer = bufferStack[bufferStackPos]; - int limit = bufferLimit[bufferStackPos]; - - while (++bufferPos[bufferStackPos] < limit) { - int p = bufferPos[bufferStackPos]; - switch (buffer[p]) { - case ' ': - case '\t': - case '\r': - continue; - case '/': - if (p + 1 < limit) { - if (buffer[p + 1] == '/') { - // C++ comment, skip rest of line - for (bufferPos[bufferStackPos] += 2; bufferPos[bufferStackPos] < limit; ++bufferPos[bufferStackPos]) { - p = bufferPos[bufferStackPos]; - if (buffer[p] == '\\' && p + 1 < limit - && buffer[p + 1] == '\n') { - bufferPos[bufferStackPos] += 2; - continue; - } - if (buffer[p] == '\\' && p + 1 < limit - && buffer[p + 1] == '\r' - && p + 2 < limit - && buffer[p + 2] == '\n') { - bufferPos[bufferStackPos] += 3; - continue; - } - - if (buffer[p] == '\n') - break; // break when find non-escaped - // newline - } - continue; - } else if (buffer[p + 1] == '*') { // C comment, find - // closing */ - for (bufferPos[bufferStackPos] += 2; bufferPos[bufferStackPos] < limit; ++bufferPos[bufferStackPos]) { - p = bufferPos[bufferStackPos]; - if (buffer[p] == '*' && p + 1 < limit - && buffer[p + 1] == '/') { - ++bufferPos[bufferStackPos]; - break; - } - } - continue; - } - } - break; - case '\\': - if (p + 1 < limit && buffer[p + 1] == '\n') { - // \n is a whitespace - lineNumber++; - ++bufferPos[bufferStackPos]; - continue; - } - } - - // fell out of switch without continuing, we're done - --bufferPos[bufferStackPos]; - return; - } - - // fell out of while without continuing, we're done - --bufferPos[bufferStackPos]; - return; - } - - private static final int tNULL = 0; - - private static final int tEOF = 1; - - private static final int tNUMBER = 2; - - private static final int tLPAREN = 3; - - private static final int tRPAREN = 4; - - private static final int tNOT = 5; - - private static final int tCOMPL = 6; - - private static final int tMULT = 7; - - private static final int tDIV = 8; - - private static final int tMOD = 9; - - private static final int tPLUS = 10; - - private static final int tMINUS = 11; - - private static final int tSHIFTL = 12; - - private static final int tSHIFTR = 13; - - private static final int tLT = 14; - - private static final int tGT = 15; - - private static final int tLTEQUAL = 16; - - private static final int tGTEQUAL = 17; - - private static final int tEQUAL = 18; - - private static final int tNOTEQUAL = 19; - - private static final int tBITAND = 20; - - private static final int tBITXOR = 21; - - private static final int tBITOR = 22; - - private static final int tAND = 23; - - private static final int tOR = 24; - - private static final int tQUESTION = 25; - - private static final int tCOLON = 26; - - private static final int t_defined = 27; - - private static final int tCHAR = 28; - - private void pushContext(char[] buffer, Object data) { - if (++bufferStackPos == bufferStack.length) { - int size = bufferStack.length * 2; - - char[][] oldBufferStack = bufferStack; - bufferStack = new char[size][]; - System.arraycopy(oldBufferStack, 0, bufferStack, 0, - oldBufferStack.length); - - Object[] oldBufferData = bufferData; - bufferData = new Object[size]; - System.arraycopy(oldBufferData, 0, bufferData, 0, - oldBufferData.length); - - int[] oldBufferPos = bufferPos; - bufferPos = new int[size]; - System.arraycopy(oldBufferPos, 0, bufferPos, 0, - oldBufferPos.length); - - int[] oldBufferLimit = bufferLimit; - bufferLimit = new int[size]; - System.arraycopy(oldBufferLimit, 0, bufferLimit, 0, - oldBufferLimit.length); - } - - bufferStack[bufferStackPos] = buffer; - bufferPos[bufferStackPos] = -1; - bufferLimit[bufferStackPos] = buffer.length; - bufferData[bufferStackPos] = data; - } - - private void popContext() { - bufferStack[bufferStackPos] = null; - bufferData[bufferStackPos] = null; - --bufferStackPos; - } - - private void handleProblem(int id, int startOffset) { - if (callbackManager != null && problemFactory != null) - callbackManager - .pushCallback(problemFactory - .createProblem( - id, - startOffset, - bufferPos[(bufferStackPos == -1 ? 0 - : bufferStackPos)], - lineNumber, - (fileName == null ? "".toCharArray() : fileName), emptyCharArray, false, true)); //$NON-NLS-1$ - } - - private boolean isValidTokenSeparator(char c, char c2) - throws EvalException { - switch (c) { - case '\t': - case '\r': - case '\n': - case ' ': - case '(': - case ')': - case ':': - case '?': - case '+': - case '-': - case '*': - case '/': - case '%': - case '^': - case '&': - case '|': - case '~': - case '!': - case '<': - case '>': - return true; - case '=': - if (c2 == '=') - return true; - return false; - } - - return false; - } - } - public BaseScanner(CodeReader reader, IScannerInfo info, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtensionConfiguration configuration) { @@ -1266,16 +208,7 @@ abstract class BaseScanner implements IScanner { keywords = cppkeywords; additionalKeywords = configuration.getAdditionalKeywords(); -// additionalPPKeywords= configuration.getAdditionalPreprocessorKeywords(); - // add default GNU extensions (will be paramameterized) - additionalPPKeywords= new CharArrayIntMap(8, IPreprocessorDirective.ppInvalid); - additionalPPKeywords.put(Keywords.cINCLUDE_NEXT, IPreprocessorDirective.ppInclude_next); - additionalPPKeywords.put(Keywords.cIMPORT, IPreprocessorDirective.ppImport); - additionalPPKeywords.put(Keywords.cWARNING, IPreprocessorDirective.ppWarning); - additionalPPKeywords.put(Keywords.cIDENT, IPreprocessorDirective.ppIgnore); - additionalPPKeywords.put(Keywords.cSCCS, IPreprocessorDirective.ppIgnore); - additionalPPKeywords.put(Keywords.cASSERT, IPreprocessorDirective.ppIgnore); - additionalPPKeywords.put(Keywords.cUNASSERT, IPreprocessorDirective.ppIgnore); + additionalPPKeywords= configuration.getAdditionalPreprocessorKeywords(); setupBuiltInMacros(configuration); @@ -2667,7 +1600,7 @@ abstract class BaseScanner implements IScanner { int end; int type = ppKeywords.get(buffer, start, len); - if (type == ppKeywords.undefined) { + if (type == ppKeywords.undefined && additionalPPKeywords != null) { type= additionalPPKeywords.get(buffer, start, len); } if (type != IPreprocessorDirective.ppInvalid) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java index 543ac867134..e5ebe1445e6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java @@ -17,6 +17,7 @@ import java.util.List; import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IMacro; import org.eclipse.cdt.core.parser.IParserLogService; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java new file mode 100644 index 00000000000..0dd6408838e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java @@ -0,0 +1,1078 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial implementation + * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=151207 + * Anton Leherbauer (Wind River Systems) + *******************************************************************************/ +package org.eclipse.cdt.internal.core.parser.scanner2; + +import org.eclipse.cdt.core.parser.IProblem; +import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner.MacroData; + +public class ExpressionEvaluator { + + private static char[] emptyCharArray = new char[0]; + + // The context stack + private static final int initSize = 8; + + private int bufferStackPos = -1; + + private char[][] bufferStack = new char[initSize][]; + + private Object[] bufferData = new Object[initSize]; + + private int[] bufferPos = new int[initSize]; + + private int[] bufferLimit = new int[initSize]; + + private ScannerCallbackManager callbackManager = null; + + private ScannerProblemFactory problemFactory = null; + + private int lineNumber = 1; + + private char[] fileName = null; + + private int pos = 0; + + // The macros + CharArrayObjectMap definitions; + + public ExpressionEvaluator() { + super(); + } + + public ExpressionEvaluator(ScannerCallbackManager manager, + ScannerProblemFactory spf) { + this.callbackManager = manager; + this.problemFactory = spf; + } + + public long evaluate(char[] buffer, int p, int length, + CharArrayObjectMap defs) { + return evaluate(buffer, p, length, defs, 0, "".toCharArray()); //$NON-NLS-1$ + } + + public long evaluate(char[] buffer, int p, int length, + CharArrayObjectMap defs, int ln, char[] fn) { + this.lineNumber = ln; + this.fileName = fn; + bufferStack[++bufferStackPos] = buffer; + bufferPos[bufferStackPos] = p - 1; + bufferLimit[bufferStackPos] = p + length; + this.definitions = defs; + tokenType = 0; + + long r = 0; + try { + r = expression(); + } catch (ExpressionEvaluator.EvalException e) { + } + + while (bufferStackPos >= 0) + popContext(); + + return r; + } + + private static class EvalException extends Exception { + private static final long serialVersionUID = 0; + public EvalException(String msg) { + super(msg); + } + } + + private long expression() throws EvalException { + return conditionalExpression(); + } + + private long conditionalExpression() throws EvalException { + long r1 = logicalOrExpression(); + if (LA() == tQUESTION) { + consume(); + long r2 = expression(); + if (LA() == tCOLON) + consume(); + else { + handleProblem(IProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION, + pos); + throw new EvalException("bad conditional expression"); //$NON-NLS-1$ + } + long r3 = conditionalExpression(); + return r1 != 0 ? r2 : r3; + } + return r1; + } + + private long logicalOrExpression() throws EvalException { + long r1 = logicalAndExpression(); + while (LA() == tOR) { + consume(); + long r2 = logicalAndExpression(); + r1 = ((r1 != 0) || (r2 != 0)) ? 1 : 0; + } + return r1; + } + + private long logicalAndExpression() throws EvalException { + long r1 = inclusiveOrExpression(); + while (LA() == tAND) { + consume(); + long r2 = inclusiveOrExpression(); + r1 = ((r1 != 0) && (r2 != 0)) ? 1 : 0; + } + return r1; + } + + private long inclusiveOrExpression() throws EvalException { + long r1 = exclusiveOrExpression(); + while (LA() == tBITOR) { + consume(); + long r2 = exclusiveOrExpression(); + r1 = r1 | r2; + } + return r1; + } + + private long exclusiveOrExpression() throws EvalException { + long r1 = andExpression(); + while (LA() == tBITXOR) { + consume(); + long r2 = andExpression(); + r1 = r1 ^ r2; + } + return r1; + } + + private long andExpression() throws EvalException { + long r1 = equalityExpression(); + while (LA() == tBITAND) { + consume(); + long r2 = equalityExpression(); + r1 = r1 & r2; + } + return r1; + } + + private long equalityExpression() throws EvalException { + long r1 = relationalExpression(); + for (int t = LA(); t == tEQUAL || t == tNOTEQUAL; t = LA()) { + consume(); + long r2 = relationalExpression(); + if (t == tEQUAL) + r1 = (r1 == r2) ? 1 : 0; + else + // t == tNOTEQUAL + r1 = (r1 != r2) ? 1 : 0; + } + return r1; + } + + private long relationalExpression() throws EvalException { + long r1 = shiftExpression(); + for (int t = LA(); t == tLT || t == tLTEQUAL || t == tGT + || t == tGTEQUAL; t = LA()) { + consume(); + long r2 = shiftExpression(); + switch (t) { + case tLT: + r1 = (r1 < r2) ? 1 : 0; + break; + case tLTEQUAL: + r1 = (r1 <= r2) ? 1 : 0; + break; + case tGT: + r1 = (r1 > r2) ? 1 : 0; + break; + case tGTEQUAL: + r1 = (r1 >= r2) ? 1 : 0; + break; + } + } + return r1; + } + + private long shiftExpression() throws EvalException { + long r1 = additiveExpression(); + for (int t = LA(); t == tSHIFTL || t == tSHIFTR; t = LA()) { + consume(); + long r2 = additiveExpression(); + if (t == tSHIFTL) + r1 = r1 << r2; + else + // t == tSHIFTR + r1 = r1 >> r2; + } + return r1; + } + + private long additiveExpression() throws EvalException { + long r1 = multiplicativeExpression(); + for (int t = LA(); t == tPLUS || t == tMINUS; t = LA()) { + consume(); + long r2 = multiplicativeExpression(); + if (t == tPLUS) + r1 = r1 + r2; + else + // t == tMINUS + r1 = r1 - r2; + } + return r1; + } + + private long multiplicativeExpression() throws EvalException { + long r1 = unaryExpression(); + for (int t = LA(); t == tMULT || t == tDIV || t == tMOD; t = LA()) { + int position = pos; // for IProblem /0 below, need position + // before + // consume() + consume(); + long r2 = unaryExpression(); + if (t == tMULT) + r1 = r1 * r2; + else if (r2 != 0) { + if (t == tDIV) + r1 = r1 / r2; + else + r1 = r1 % r2; //tMOD + } else { + handleProblem(IProblem.SCANNER_DIVIDE_BY_ZERO, position); + throw new EvalException("Divide by 0 encountered"); //$NON-NLS-1$ + } + } + return r1; + } + + private long unaryExpression() throws EvalException { + switch (LA()) { + case tPLUS: + consume(); + return unaryExpression(); + case tMINUS: + consume(); + return -unaryExpression(); + case tNOT: + consume(); + return unaryExpression() == 0 ? 1 : 0; + case tCOMPL: + consume(); + return ~unaryExpression(); + case tNUMBER: + return consume(); + case t_defined: + return handleDefined(); + case tLPAREN: + consume(); + long r1 = expression(); + if (LA() == tRPAREN) { + consume(); + return r1; + } + handleProblem(IProblem.SCANNER_MISSING_R_PAREN, pos); + throw new EvalException("missing )"); //$NON-NLS-1$ + case tCHAR: + return getChar(); + default: + handleProblem(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, pos); + throw new EvalException("expression syntax error"); //$NON-NLS-1$ + } + } + + private long handleDefined() throws EvalException { + // We need to do some special handline to get the identifier without + // it + // being + // expanded by macro expansion + skipWhiteSpace(); + + char[] buffer = bufferStack[bufferStackPos]; + int limit = bufferLimit[bufferStackPos]; + if (++bufferPos[bufferStackPos] >= limit) + return 0; + + // check first character + char c = buffer[bufferPos[bufferStackPos]]; + boolean inParens = false; + if (c == '(') { + inParens = true; + skipWhiteSpace(); + if (++bufferPos[bufferStackPos] >= limit) + return 0; + c = buffer[bufferPos[bufferStackPos]]; + } + + if (!((c >= 'A' && c <= 'Z') || c == '_' || (c >= 'a' && c <= 'z'))) { + handleProblem(IProblem.SCANNER_ILLEGAL_IDENTIFIER, pos); + throw new EvalException("illegal identifier in defined()"); //$NON-NLS-1$ + } + + // consume rest of identifier + int idstart = bufferPos[bufferStackPos]; + int idlen = 1; + while (++bufferPos[bufferStackPos] < limit) { + c = buffer[bufferPos[bufferStackPos]]; + if ((c >= 'A' && c <= 'Z') || c == '_' + || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) { + ++idlen; + continue; + } + break; + } + --bufferPos[bufferStackPos]; + + // consume to the closing paren; + if (inParens) { + skipWhiteSpace(); + if (++bufferPos[bufferStackPos] <= limit + && buffer[bufferPos[bufferStackPos]] != ')') { + handleProblem(IProblem.SCANNER_MISSING_R_PAREN, pos); + throw new EvalException("missing ) on defined"); //$NON-NLS-1$ + } + } + + // Set up the lookahead to whatever comes next + nextToken(); + + return definitions.get(buffer, idstart, idlen) != null ? 1 : 0; + } + + // Scanner part + int tokenType = tNULL; + + long tokenValue; + + private int LA() throws EvalException { + if (tokenType == tNULL) + nextToken(); + return tokenType; + } + + private long consume() throws EvalException { + long value = tokenValue; + if (tokenType != tEOF) + nextToken(); + return value; + } + + private long getChar() throws EvalException { + long value = 0; + + // if getting a character then make sure it's in '' otherwise leave + // it + // as 0 + if (bufferPos[bufferStackPos] - 1 >= 0 + && bufferPos[bufferStackPos] + 1 < bufferStack[bufferStackPos].length + && bufferStack[bufferStackPos][bufferPos[bufferStackPos] - 1] == '\'' + && bufferStack[bufferStackPos][bufferPos[bufferStackPos] + 1] == '\'') + value = bufferStack[bufferStackPos][bufferPos[bufferStackPos]]; + + if (tokenType != tEOF) + nextToken(); + return value; + } + + private static char[] _defined = "defined".toCharArray(); //$NON-NLS-1$ + + private void nextToken() throws EvalException { + boolean isHex = false; + boolean isOctal = false; + boolean isDecimal = false; + + contextLoop: while (bufferStackPos >= 0) { + + // Find the first thing we would care about + skipWhiteSpace(); + + while (++bufferPos[bufferStackPos] >= bufferLimit[bufferStackPos]) { + // We're at the end of a context, pop it off and try again + popContext(); + continue contextLoop; + } + + // Tokens don't span buffers, stick to our current one + char[] buffer = bufferStack[bufferStackPos]; + int limit = bufferLimit[bufferStackPos]; + pos = bufferPos[bufferStackPos]; + + if (buffer[pos] >= '1' && buffer[pos] <= '9') + isDecimal = true; + else if (buffer[pos] == '0' && pos + 1 < limit) + if (buffer[pos + 1] == 'x' || buffer[pos + 1] == 'X') { + isHex = true; + ++bufferPos[bufferStackPos]; + if (pos + 2 < limit) + if ((buffer[pos + 2] < '0' || buffer[pos + 2] > '9') + && (buffer[pos + 2] < 'a' || buffer[pos + 2] > 'f') + && (buffer[pos + 2] < 'A' || buffer[pos + 2] > 'F')) + handleProblem(IProblem.SCANNER_BAD_HEX_FORMAT, + pos); + } else + isOctal = true; + + switch (buffer[pos]) { + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + int start = bufferPos[bufferStackPos]; + int len = 1; + + while (++bufferPos[bufferStackPos] < limit) { + char c = buffer[bufferPos[bufferStackPos]]; + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') + || c == '_' || (c >= '0' && c <= '9')) { + ++len; + continue; + } + break; + } + + --bufferPos[bufferStackPos]; + + // Check for defined( + pos = bufferPos[bufferStackPos]; + if (CharArrayUtils.equals(buffer, start, len, _defined)) { + tokenType = t_defined; + return; + } + + // Check for macro expansion + Object expObject = null; + if (bufferData[bufferStackPos] instanceof FunctionStyleMacro.Expansion) { + // first check if name is a macro arg + expObject = ((FunctionStyleMacro.Expansion) bufferData[bufferStackPos]).definitions + .get(buffer, start, len); + } + + if (expObject == null) + // now check regular macros + expObject = definitions.get(buffer, start, len); + + if (expObject != null) { + if (expObject instanceof FunctionStyleMacro) { + handleFunctionStyleMacro((FunctionStyleMacro) expObject); + } else if (expObject instanceof ObjectStyleMacro) { + ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject; + char[] expText = expMacro.getExpansion(); + if (expText.length > 0 ) + { + if (BaseScanner.shouldExpandMacro(expMacro, bufferStackPos, bufferData, -1, bufferPos, bufferStack )) + pushContext(expText, new MacroData(start, start + len, expMacro)); + else + { + if (len == 1) { // is a character + tokenType = tCHAR; + return; + } + // undefined macro, assume 0 + tokenValue = 0; + tokenType = tNUMBER; + return; + + } + + } + } else if (expObject instanceof char[]) { + char[] expText = (char[]) expObject; + if (expText.length > 0) + pushContext(expText, null); + } + continue; + } + + if (len == 1) { // is a character + tokenType = tCHAR; + return; + } + + // undefined macro, assume 0 + tokenValue = 0; + tokenType = tNUMBER; + return; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + tokenValue = buffer[pos] - '0'; + tokenType = tNUMBER; + + while (++bufferPos[bufferStackPos] < limit) { + char c = buffer[bufferPos[bufferStackPos]]; + if (isHex) { + if (c >= '0' && c <= '9') { + tokenValue *= 16; + tokenValue += c - '0'; + continue; + } else if (c >= 'a' && c <= 'f') { + tokenValue = (tokenValue == 0 ? 10 + : (tokenValue * 16) + 10); + tokenValue += c - 'a'; + continue; + } else if (c >= 'A' && c <= 'F') { + tokenValue = (tokenValue == 0 ? 10 + : (tokenValue * 16) + 10); + tokenValue += c - 'A'; + continue; + } else { + if (bufferPos[bufferStackPos] + 1 < limit) + if (!isValidTokenSeparator( + c, + buffer[bufferPos[bufferStackPos] + 1])) + handleProblem( + IProblem.SCANNER_BAD_HEX_FORMAT, + pos); + } + } else if (isOctal) { + if (c >= '0' && c <= '7') { + tokenValue *= 8; + tokenValue += c - '0'; + continue; + } + if (bufferPos[bufferStackPos] + 1 < limit) + if (!isValidTokenSeparator(c, + buffer[bufferPos[bufferStackPos] + 1])) + handleProblem( + IProblem.SCANNER_BAD_OCTAL_FORMAT, + pos); + } else if (isDecimal) { + if (c >= '0' && c <= '9') { + tokenValue *= 10; + tokenValue += c - '0'; + continue; + } + if (bufferPos[bufferStackPos] + 1 < limit + && !(c == 'L' || c == 'l' || c == 'U' || c == 'u')) + if (!isValidTokenSeparator(c, + buffer[bufferPos[bufferStackPos] + 1])) + handleProblem( + IProblem.SCANNER_BAD_DECIMAL_FORMAT, + pos); + } + + // end of number + if (c == 'L' || c == 'l' || c == 'U' || c == 'u') { + // eat the long/unsigned + ++bufferPos[bufferStackPos]; + } + + // done + break; + } + --bufferPos[bufferStackPos]; + return; + case '(': + tokenType = tLPAREN; + return; + + case ')': + tokenType = tRPAREN; + return; + + case ':': + tokenType = tCOLON; + return; + + case '?': + tokenType = tQUESTION; + return; + + case '+': + tokenType = tPLUS; + return; + + case '-': + tokenType = tMINUS; + return; + + case '*': + tokenType = tMULT; + return; + + case '/': + tokenType = tDIV; + return; + + case '%': + tokenType = tMOD; + return; + + case '^': + tokenType = tBITXOR; + return; + + case '&': + if (pos + 1 < limit && buffer[pos + 1] == '&') { + ++bufferPos[bufferStackPos]; + tokenType = tAND; + return; + } + tokenType = tBITAND; + return; + + case '|': + if (pos + 1 < limit && buffer[pos + 1] == '|') { + ++bufferPos[bufferStackPos]; + tokenType = tOR; + return; + } + tokenType = tBITOR; + return; + + case '~': + tokenType = tCOMPL; + return; + + case '!': + if (pos + 1 < limit && buffer[pos + 1] == '=') { + ++bufferPos[bufferStackPos]; + tokenType = tNOTEQUAL; + return; + } + tokenType = tNOT; + return; + + case '=': + if (pos + 1 < limit && buffer[pos + 1] == '=') { + ++bufferPos[bufferStackPos]; + tokenType = tEQUAL; + return; + } + handleProblem(IProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED, pos); + throw new EvalException("assignment not allowed"); //$NON-NLS-1$ + + case '<': + if (pos + 1 < limit) { + if (buffer[pos + 1] == '=') { + ++bufferPos[bufferStackPos]; + tokenType = tLTEQUAL; + return; + } else if (buffer[pos + 1] == '<') { + ++bufferPos[bufferStackPos]; + tokenType = tSHIFTL; + return; + } + } + tokenType = tLT; + return; + + case '>': + if (pos + 1 < limit) { + if (buffer[pos + 1] == '=') { + ++bufferPos[bufferStackPos]; + tokenType = tGTEQUAL; + return; + } else if (buffer[pos + 1] == '>') { + ++bufferPos[bufferStackPos]; + tokenType = tSHIFTR; + return; + } + } + tokenType = tGT; + return; + + default: + // skip over anything we don't handle + } + } + + // We've run out of contexts, our work is done here + tokenType = tEOF; + return; + } + + private void handleFunctionStyleMacro(FunctionStyleMacro macro) { + char[] buffer = bufferStack[bufferStackPos]; + int limit = bufferLimit[bufferStackPos]; + + skipWhiteSpace(); + if (++bufferPos[bufferStackPos] >= limit + || buffer[bufferPos[bufferStackPos]] != '(') + return; + + FunctionStyleMacro.Expansion exp = macro.new Expansion(); + char[][] arglist = macro.arglist; + int currarg = -1; + int parens = 0; + + while (bufferPos[bufferStackPos] < limit) { + if (++currarg >= arglist.length || arglist[currarg] == null) + // too many args + break; + + skipWhiteSpace(); + + int p = ++bufferPos[bufferStackPos]; + char c = buffer[p]; + if (c == ')') { + if (parens == 0) + // end of macro + break; + --parens; + continue; + } else if (c == ',') { + // empty arg + exp.definitions.put(arglist[currarg], emptyCharArray); + continue; + } else if (c == '(') { + ++parens; + continue; + } + + // peel off the arg + int argstart = p; + int argend = argstart - 1; + + // Loop looking for end of argument + while (bufferPos[bufferStackPos] < limit) { + skipOverMacroArg(); + argend = bufferPos[bufferStackPos]; + skipWhiteSpace(); + + if (++bufferPos[bufferStackPos] >= limit) + break; + c = buffer[bufferPos[bufferStackPos]]; + if (c == ',' || c == ')') + break; + } + + char[] arg = emptyCharArray; + int arglen = argend - argstart + 1; + if (arglen > 0) { + arg = new char[arglen]; + System.arraycopy(buffer, argstart, arg, 0, arglen); + } + exp.definitions.put(arglist[currarg], arg); + + if (c == ')') + break; + } + + char[] expText = macro.getExpansion(); + if (expText.length > 0) + pushContext(expText, exp); + } + + private void skipOverMacroArg() { + char[] buffer = bufferStack[bufferStackPos]; + int limit = bufferLimit[bufferStackPos]; + + while (++bufferPos[bufferStackPos] < limit) { + switch (buffer[bufferPos[bufferStackPos]]) { + case ' ': + case '\t': + case '\r': + case ',': + case ')': + --bufferPos[bufferStackPos]; + return; + case '\n': + lineNumber++; + --bufferPos[bufferStackPos]; + return; + case '\\': + int p = bufferPos[bufferStackPos]; + if (p + 1 < limit && buffer[p + 1] == '\n') { + // \n is whitespace + lineNumber++; + --bufferPos[bufferStackPos]; + return; + } + break; + case '"': + boolean escaped = false; + loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) { + switch (buffer[bufferPos[bufferStackPos]]) { + case '\\': + escaped = !escaped; + continue; + case '"': + if (escaped) { + escaped = false; + continue; + } + break loop; + default: + escaped = false; + } + } + break; + } + } + --bufferPos[bufferStackPos]; + } + + private void skipWhiteSpace() { + char[] buffer = bufferStack[bufferStackPos]; + int limit = bufferLimit[bufferStackPos]; + + while (++bufferPos[bufferStackPos] < limit) { + int p = bufferPos[bufferStackPos]; + switch (buffer[p]) { + case ' ': + case '\t': + case '\r': + continue; + case '/': + if (p + 1 < limit) { + if (buffer[p + 1] == '/') { + // C++ comment, skip rest of line + for (bufferPos[bufferStackPos] += 2; bufferPos[bufferStackPos] < limit; ++bufferPos[bufferStackPos]) { + p = bufferPos[bufferStackPos]; + if (buffer[p] == '\\' && p + 1 < limit + && buffer[p + 1] == '\n') { + bufferPos[bufferStackPos] += 2; + continue; + } + if (buffer[p] == '\\' && p + 1 < limit + && buffer[p + 1] == '\r' + && p + 2 < limit + && buffer[p + 2] == '\n') { + bufferPos[bufferStackPos] += 3; + continue; + } + + if (buffer[p] == '\n') + break; // break when find non-escaped + // newline + } + continue; + } else if (buffer[p + 1] == '*') { // C comment, find + // closing */ + for (bufferPos[bufferStackPos] += 2; bufferPos[bufferStackPos] < limit; ++bufferPos[bufferStackPos]) { + p = bufferPos[bufferStackPos]; + if (buffer[p] == '*' && p + 1 < limit + && buffer[p + 1] == '/') { + ++bufferPos[bufferStackPos]; + break; + } + } + continue; + } + } + break; + case '\\': + if (p + 1 < limit && buffer[p + 1] == '\n') { + // \n is a whitespace + lineNumber++; + ++bufferPos[bufferStackPos]; + continue; + } + } + + // fell out of switch without continuing, we're done + --bufferPos[bufferStackPos]; + return; + } + + // fell out of while without continuing, we're done + --bufferPos[bufferStackPos]; + return; + } + + private static final int tNULL = 0; + + private static final int tEOF = 1; + + private static final int tNUMBER = 2; + + private static final int tLPAREN = 3; + + private static final int tRPAREN = 4; + + private static final int tNOT = 5; + + private static final int tCOMPL = 6; + + private static final int tMULT = 7; + + private static final int tDIV = 8; + + private static final int tMOD = 9; + + private static final int tPLUS = 10; + + private static final int tMINUS = 11; + + private static final int tSHIFTL = 12; + + private static final int tSHIFTR = 13; + + private static final int tLT = 14; + + private static final int tGT = 15; + + private static final int tLTEQUAL = 16; + + private static final int tGTEQUAL = 17; + + private static final int tEQUAL = 18; + + private static final int tNOTEQUAL = 19; + + private static final int tBITAND = 20; + + private static final int tBITXOR = 21; + + private static final int tBITOR = 22; + + private static final int tAND = 23; + + private static final int tOR = 24; + + private static final int tQUESTION = 25; + + private static final int tCOLON = 26; + + private static final int t_defined = 27; + + private static final int tCHAR = 28; + + private void pushContext(char[] buffer, Object data) { + if (++bufferStackPos == bufferStack.length) { + int size = bufferStack.length * 2; + + char[][] oldBufferStack = bufferStack; + bufferStack = new char[size][]; + System.arraycopy(oldBufferStack, 0, bufferStack, 0, + oldBufferStack.length); + + Object[] oldBufferData = bufferData; + bufferData = new Object[size]; + System.arraycopy(oldBufferData, 0, bufferData, 0, + oldBufferData.length); + + int[] oldBufferPos = bufferPos; + bufferPos = new int[size]; + System.arraycopy(oldBufferPos, 0, bufferPos, 0, + oldBufferPos.length); + + int[] oldBufferLimit = bufferLimit; + bufferLimit = new int[size]; + System.arraycopy(oldBufferLimit, 0, bufferLimit, 0, + oldBufferLimit.length); + } + + bufferStack[bufferStackPos] = buffer; + bufferPos[bufferStackPos] = -1; + bufferLimit[bufferStackPos] = buffer.length; + bufferData[bufferStackPos] = data; + } + + private void popContext() { + bufferStack[bufferStackPos] = null; + bufferData[bufferStackPos] = null; + --bufferStackPos; + } + + private void handleProblem(int id, int startOffset) { + if (callbackManager != null && problemFactory != null) + callbackManager + .pushCallback(problemFactory + .createProblem( + id, + startOffset, + bufferPos[(bufferStackPos == -1 ? 0 + : bufferStackPos)], + lineNumber, + (fileName == null ? "".toCharArray() : fileName), emptyCharArray, false, true)); //$NON-NLS-1$ + } + + private boolean isValidTokenSeparator(char c, char c2) + throws EvalException { + switch (c) { + case '\t': + case '\r': + case '\n': + case ' ': + case '(': + case ')': + case ':': + case '?': + case '+': + case '-': + case '*': + case '/': + case '%': + case '^': + case '&': + case '|': + case '~': + case '!': + case '<': + case '>': + return true; + case '=': + if (c2 == '=') + return true; + return false; + } + + return false; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCOldScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCOldScannerExtensionConfiguration.java index 68201a56a05..98588311ee2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCOldScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCOldScannerExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. + * Copyright (c) 2002, 2007 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 @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.parser.scanner2; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPOldScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPOldScannerExtensionConfiguration.java index 2c7e31627b7..462a897bc1b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPOldScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPOldScannerExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. + * Copyright (c) 2002, 2007 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 @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.parser.scanner2; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java index 086ac219c14..08a87548eb5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.parser.scanner2; import java.util.Iterator; import java.util.List; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IProblem; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java index d4fd71e3510..50113667040 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 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 @@ -16,6 +16,16 @@ import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.IParserConfiguration; import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; +import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -25,19 +35,9 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource;