1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

moved unused code into separate source folder

This commit is contained in:
Mike Kucera 2008-04-07 15:52:01 +00:00
parent 0df76bd7b0
commit b20ba9eac9
37 changed files with 106 additions and 297 deletions

View file

@ -1,29 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 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 API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
import org.eclipse.cdt.core.dom.lrparser.action.c99.SymbolTableTests;
import junit.framework.Test;
import junit.framework.TestSuite;
public class ActionTestSuite extends TestSuite {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(SymbolTableTests.class);
suite.addTestSuite(ResolverActionTests.class);
return suite;
}
}

View file

@ -1,137 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 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 API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
import static org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym.TK_identifier;
import static org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym.TK_int;
import java.util.ArrayList;
import java.util.List;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import lpg.lpgjavaruntime.IToken;
import lpg.lpgjavaruntime.Token;
import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Variable;
@Deprecated
public class ResolverActionTests extends TestCase {
/**
* We are testing the parser actions in isolation without running
* an actual parser, therefore we need to mock out the parser object.
*/
private static class MockParser implements IParserActionTokenProvider {
public List<IToken> ruleTokens;
public MockParser(Object ... tokenTypes) {
this.ruleTokens = tokens(tokenTypes);
}
public List<IToken> getCommentTokens() {
return null;
}
public IToken getEOFToken() {
return null;
}
public IToken getLeftIToken() {
return ruleTokens.get(0);
}
public IToken getRightIToken() {
return ruleTokens.get(ruleTokens.size()-1);
}
public List<IToken> getRuleTokens() {
return ruleTokens;
}
public void setRuleTokens(Object ... tokenTypes) {
this.ruleTokens = tokens(tokenTypes);
}
static List<IToken> tokens(Object[] tokenTypes) {
List<IToken> tokens = new ArrayList<IToken>();
if(tokenTypes == null)
return tokens;
for(final Object o : tokenTypes) {
IToken token;
if(o instanceof Integer)
token = new Token(0, 0, ((Integer)o).intValue());
else if(o instanceof String)
token = new Token(0, 0, TK_identifier) {
@Override public String toString() {
return o.toString();
}
};
else
throw new AssertionFailedError();
tokens.add(token);
}
return tokens;
}
public String[] getOrderedTerminalSymbols() {
return null;
}
public String getName() {
return "Blah"; //$NON-NLS-1$
}
}
/**
* Parsing: int x;, then undo, then parse again
*/
@SuppressWarnings("deprecation")
public void testResolverActions1() {
MockParser mockParser = new MockParser();
C99ResolveParserAction action = new C99ResolveParserAction(mockParser);
mockParser.setRuleTokens(TK_int);
action.openDeclarationScope();
action.consumeDeclSpecToken();
mockParser.setRuleTokens("x");
action.consumeDirectDeclaratorIdentifier();
action.consumeDeclaratorComplete();
action.closeDeclarationScope();
C99SymbolTable symbolTable;
symbolTable = action.getSymbolTable();
assertEquals(1, symbolTable.size());
C99Variable binding = (C99Variable) symbolTable.lookup(CNamespace.IDENTIFIER, "x");
assertEquals("x", binding.getName());
// cool, now undo!
assertEquals(5, action.undoStackSize());
action.undo(5);
assertEquals(0, action.undoStackSize());
assertEquals(0, action.getDeclarationStack().size());
symbolTable = action.getSymbolTable();
assertTrue(symbolTable.isEmpty());
// rerun
mockParser.setRuleTokens(TK_int);
action.openDeclarationScope();
action.consumeDeclSpecToken();
mockParser.setRuleTokens("x");
action.consumeDirectDeclaratorIdentifier();
action.consumeDeclaratorComplete();
action.closeDeclarationScope();
symbolTable = action.getSymbolTable();
assertEquals(1, symbolTable.size());
binding = (C99Variable) symbolTable.lookup(CNamespace.IDENTIFIER, "x");
assertEquals("x", binding.getName());
}
}

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="old"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>

View file

@ -9,10 +9,8 @@ Require-Bundle: org.eclipse.cdt.core,
org.eclipse.core.runtime
Export-Package: org.eclipse.cdt.core.dom.lrparser,
org.eclipse.cdt.core.dom.lrparser.action,
org.eclipse.cdt.core.dom.lrparser.action.c99,
org.eclipse.cdt.core.dom.lrparser.c99,
org.eclipse.cdt.core.dom.lrparser.cpp,
org.eclipse.cdt.internal.core.dom.lrparser.c99;x-internal:=true,
org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings
org.eclipse.cdt.internal.core.dom.lrparser.c99;x-internal:=true
Bundle-Localization: plugin
Bundle-Vendor: %Bundle-Vendor.0

View file

@ -8,12 +8,10 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
package org.eclipse.cdt.internal.core.dom.lrparser.c99.action.deprecated;
import static org.eclipse.cdt.core.dom.lrparser.action.c99.CNamespace.GOTO_LABEL;
import static org.eclipse.cdt.core.dom.lrparser.action.c99.CNamespace.IDENTIFIER;
import static org.eclipse.cdt.core.dom.lrparser.action.c99.CNamespace.STRUCT_TAG;
import static org.eclipse.cdt.core.parser.util.CollectionUtils.reverseIterable;
import static org.eclipse.cdt.internal.core.dom.lrparser.symboltable.CNamespace.*;
import java.util.LinkedList;
import java.util.List;
@ -57,6 +55,7 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Variable;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Binding;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.ITypeable;
import org.eclipse.cdt.internal.core.dom.lrparser.symboltable.C99SymbolTable;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
/**
* This class was an attempt at doing full binding resolution during the parse

View file

@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
package org.eclipse.cdt.internal.core.dom.lrparser.c99.action.deprecated;
import java.util.LinkedList;
@ -16,6 +16,7 @@ import lpg.lpgjavaruntime.IToken;
import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
import org.eclipse.cdt.core.parser.util.DebugUtil;
import org.eclipse.cdt.internal.core.dom.lrparser.symboltable.TypedefSymbolTable;
/**
* A simple set of trial and undo actions that just keep track
* of typedef names. This information is then fed back to the parser

View file

@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
package org.eclipse.cdt.internal.core.dom.lrparser.c99.action.deprecated;
import static org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym.*;

View file

@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
package org.eclipse.cdt.internal.core.dom.lrparser.c99.action.deprecated;
import java.util.LinkedList;
import java.util.List;

View file

@ -16,8 +16,8 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.lrparser.action.c99.C99SymbolTable;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.internal.core.dom.lrparser.symboltable.C99SymbolTable;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
/**

View file

@ -8,10 +8,9 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
import org.eclipse.cdt.core.dom.lrparser.action.FunctionalMap;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Binding;
/**
@ -23,7 +22,7 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Binding;
*
* @author Mike Kucera
*/
@Deprecated public class C99SymbolTable {
public class C99SymbolTable {
/**
* Adapter objects are used as the keys. The trick here is to implement

View file

@ -8,14 +8,13 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Binding;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
import org.eclipse.cdt.core.dom.ast.IBinding;
/**
@ -27,11 +26,10 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
* of bindings given their names, and a stack used to keep track
* of scopes.
*
* @deprecated Use FunctionalSymbolTable now that undo actions are needed
*
* @author Mike Kucera
*/
@Deprecated public class ImperativeSymbolTable {
public class CImperativeSymbolTable {
private static final int TABLE_SIZE = 256;
@ -52,11 +50,6 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
* symbol table to the state it was in before the scope was opened.
*/
List<Integer> modifiedBuckets = new ArrayList<Integer>();
/**
* List of inner scopes that have been closed.
*/
List<IC99Scope> innerScopes = new ArrayList<IC99Scope>();
}
@ -66,10 +59,10 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
private static class Bucket {
String key;
CNamespace namespace;
IC99Binding binding;
IBinding binding;
Bucket next;
Bucket(Bucket next, CNamespace namespace, String key, IC99Binding binding) {
Bucket(Bucket next, CNamespace namespace, String key, IBinding binding) {
this.key = key;
this.namespace = namespace;
this.binding = binding;
@ -78,7 +71,7 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
}
public ImperativeSymbolTable() {
public CImperativeSymbolTable() {
openScope(); // open the global scope
// TODO populate the global scope with built-ins
}
@ -97,7 +90,7 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
*
* @param mask A bit mask used to identify the namespace of the identifier.
*/
public void put(CNamespace namespace, String ident, IC99Binding b) {
public void put(CNamespace namespace, String ident, IBinding b) {
int index = index(ident);
table[index] = new Bucket(table[index], namespace, ident, b);
@ -105,35 +98,6 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
scope.modifiedBuckets.add(index);
}
/**
* Special version of put that adds the binding to the scope that contains
* the current scope.
*
* This is here because the scope for a function body is opened before
* the function binding is created.
*/
public void putInOuterScope(CNamespace namespace, String ident, IC99Binding b) {
LinkedList<Bucket> poppedBindings = new LinkedList<Bucket>();
SymbolScope scope = scopeStack.removeLast();
for(int index : scope.modifiedBuckets) {
Bucket bucket = table[index];
poppedBindings.add(bucket);
table[index] = bucket.next;
}
put(namespace, ident, b);
for(int index : scope.modifiedBuckets) {
Bucket bucket = poppedBindings.removeFirst();
bucket.next = table[index];
table[index] = bucket;
}
scopeStack.add(scope);
}
/**
* Returns the binding associated with the given identifier, or
@ -141,7 +105,7 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
*
* @param mask A bit mask used to identify the namespace of the identifier.
*/
public IC99Binding get(CNamespace namespace, String ident) {
public IBinding get(CNamespace namespace, String ident) {
Bucket b = table[index(ident)];
while(b != null) {
if(namespace == b.namespace && ident.equals(b.key))
@ -151,11 +115,6 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
return null;
}
List<IC99Scope> getInnerScopes() {
return scopeStack.getLast().innerScopes;
}
/**
* Opens a new inner scope for identifiers.
@ -174,35 +133,25 @@ import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
* @param scope An IScope object that will be used to represent this scope.
* @throws SymbolTableException If the global scope has already been closed or if bindingScope is null.
*/
public void closeScope(IC99Scope bindingScope) {
public void closeScope() {
SymbolScope poppedScope = scopeStack.removeLast(); // pop the scopeStack
for(IC99Scope innerScope : poppedScope.innerScopes) {
innerScope.setParent(bindingScope);
}
if(!scopeStack.isEmpty()) { // would be empty if the global scope was popped
SymbolScope outerScope = scopeStack.getLast();
outerScope.innerScopes.add(bindingScope);
}
// pop each bucket that was modified in the scope
for(int index : poppedScope.modifiedBuckets) {
Bucket bucket = table[index];
bucket.binding.setScope(bindingScope);
table[index] = bucket.next;
}
for(int index : poppedScope.modifiedBuckets)
table[index] = table[index].next;
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder buff = new StringBuilder("[");
StringBuilder buff = new StringBuilder('[');
for(Bucket b : table) {
while(b != null) {
buff.append("<").append(b.key).append(": ").append(b.binding).append(">, ");
buff.append('<').append(b.key).append(": ").append(b.binding).append(">, ");
b = b.next;
}
}
return buff.append("]").toString();
return buff.append(']').toString();
}
}

View file

@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
/**
* The C language has 4 namespaces for identifiers.
@ -20,7 +20,7 @@ package org.eclipse.cdt.core.dom.lrparser.action.c99;
*
* @author Mike Kucera
*/
@Deprecated public enum CNamespace {
public enum CNamespace {
GOTO_LABEL, // goto labels
STRUCT_TAG,// structs, unions, enums

View file

@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action;
package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
/**
@ -41,8 +41,9 @@ package org.eclipse.cdt.core.dom.lrparser.action;
*/
public class FunctionalMap<K extends Comparable<K>, V> {
// better than an enum because enum variables can be null
private static final boolean RED = true, BLACK = false;
private static final boolean
RED = true,
BLACK = false;
private static class Node<K, V> {
@ -60,8 +61,10 @@ public class FunctionalMap<K extends Comparable<K>, V> {
this.color = color;
}
@Override public String toString() {
return "Node(" + key + "," + val + "," + (color ? "R" : "B") + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
@SuppressWarnings("nls")
@Override
public String toString() {
return "Node(" + key + "," + val + "," + (color ? "R" : "B") + ")";
}
}

View file

@ -1,15 +1,14 @@
package org.eclipse.cdt.core.dom.lrparser.action.c99;
package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
import junit.framework.TestCase;
//import junit.framework.TestCase;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.lrparser.action.FunctionalMap;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Label;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Structure;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Variable;
@SuppressWarnings("deprecation")
public class SymbolTableTests extends TestCase {
public class SymbolTableTests {//extends TestCase {
// TODO write tests for imperative symbol table
private final String[] KEYS = { "pantera", "soulfly", "inflames", "megadeth", "archenemy", "carcass" };
@ -43,6 +42,34 @@ public class SymbolTableTests extends TestCase {
private void assertEquals(Integer integer, Integer lookup) {
// TODO Auto-generated method stub
}
private void assertFalse(boolean empty) {
// TODO Auto-generated method stub
}
private void assertNull(Integer lookup) {
// TODO Auto-generated method stub
}
private void assertTrue(boolean empty) {
// TODO Auto-generated method stub
}
public void testOverride() {
FunctionalMap<String,Integer> map1 = FunctionalMap.emptyMap();
for(int i = 0; i < KEYS.length; i++) {
@ -72,6 +99,20 @@ public class SymbolTableTests extends TestCase {
}
private static void assertTrue(String string, boolean containsKey) {
// TODO Auto-generated method stub
}
private static void assertEquals(String string, Object object, Object lookup) {
// TODO Auto-generated method stub
}
public void testFunctionalSymbolTable1() {
C99SymbolTable st = C99SymbolTable.EMPTY_TABLE;
@ -124,6 +165,20 @@ public class SymbolTableTests extends TestCase {
}
private void assertEquals(String key, String name) {
// TODO Auto-generated method stub
}
private void assertNotNull(IBinding b) {
// TODO Auto-generated method stub
}
public void testProperFail() {
FunctionalMap<Integer,Integer> map = FunctionalMap.emptyMap();
try {
@ -149,4 +204,11 @@ public class SymbolTableTests extends TestCase {
}
private void fail() {
// TODO Auto-generated method stub
}
}

View file

@ -8,10 +8,9 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
import org.eclipse.cdt.core.dom.lrparser.action.FunctionalMap;
/**
* A facade for a FunctionalMap that is used just to track typedef

View file

@ -1,36 +0,0 @@
package org.eclipse.cdt.core.dom.lrparser.action.cpp;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
/**
* TODO this functionality should be moved into CPPASTSimpleDeclaration
* @author Mike Kucera
*
*/
@Deprecated
public class ISOCPPASTSimpleDeclaration extends CPPASTSimpleDeclaration implements IASTAmbiguityParent {
public ISOCPPASTSimpleDeclaration() {
}
public ISOCPPASTSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
super(declSpecifier);
}
public void replace(IASTNode child, IASTNode other) {
IASTDeclarator[] declarators = getDeclarators();
for(int i = 0; i < declarators.length; i++) {
if(declarators[i] == child) {
declarators[i] = (IASTDeclarator)other;
other.setParent(child.getParent());
other.setPropertyInParent(child.getPropertyInParent());
break;
}
}
}
}

View file

@ -11,7 +11,7 @@
package org.eclipse.cdt.internal.core.dom.lrparser.c99;
import org.eclipse.cdt.core.dom.lrparser.action.c99.C99BuildASTParserAction;
import org.eclipse.cdt.core.dom.lrparser.action.c99.C99TypedefTrackerParserAction;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.action.deprecated.C99TypedefTrackerParserAction;
class C99ParserAction {