Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e827eee6707fe1b686db74ed4c945c40b652bd6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*******************************************************************************
 *  Copyright (c) 2006, 2009 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.lrparser.tests;

import junit.framework.TestSuite;

import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.tests.ast2.AST2Tests;
import org.eclipse.cdt.internal.core.parser.ParserException;


/**
 * 
 * @author Mike Kucera
 *
 */
@SuppressWarnings({ "nls", "restriction" })
public class LRTests extends AST2Tests {

    public static TestSuite suite() {
    	return suite(LRTests.class);
    }
    
	public LRTests(String name) {
		super(name);
	}
	
	 
    @Override
	protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
    	return parse(code, lang, useGNUExtensions, expectNoProblems, false);
    }
    
    @Override
	protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
    	ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
    	ParseHelper.Options options = new ParseHelper.Options();
    	options.setCheckSyntaxProblems(expectNoProblems);
    	options.setCheckPreprocessorProblems(expectNoProblems);
    	options.setSkipTrivialInitializers(skipTrivialInitializers);
    	return ParseHelper.parse(code, language, options);
	}
    
    protected ILanguage getCLanguage() {
    	return GCCLanguage.getDefault();
    }
    
    protected ILanguage getCPPLanguage() {
    	return GPPLanguage.getDefault();
    }
    
    
    public void testMultipleHashHash() throws Exception {
    	String code = "#define TWICE(a)  int a##tera; int a##ther; \n TWICE(pan)";
    	parseAndCheckBindings(code, ParserLanguage.C);
    }
    
    
    public void testBug191279() throws Exception {
    	StringBuffer sb = new StringBuffer();
    	sb.append(" /**/ \n");
    	sb.append("# define YO 99 /**/ \n");
    	sb.append("# undef YO /**/ ");
    	sb.append(" /* $ */ ");
    	String code = sb.toString();
    	parseAndCheckBindings(code, ParserLanguage.C);
    }
    
    
    public void testBug191324() throws Exception {
    	StringBuffer sb = new StringBuffer();
    	sb.append("int x$y = 99; \n");
    	sb.append("int $q = 100; \n"); // can use $ as first character in identifier
    	sb.append("#ifndef SS$_INVFILFOROP \n");
    	sb.append("int z; \n");
    	sb.append("#endif \n");
    	String code = sb.toString();
    	parseAndCheckBindings(code, ParserLanguage.C);
    }
    

	public void testBug192009_implicitInt() throws Exception {
    	String code = "main() { int x; }";
    	IASTTranslationUnit tu = parse(code, ParserLanguage.C, false, true);
    	
    	IASTDeclaration[] declarations = tu.getDeclarations();
    	assertEquals(1, declarations.length);
    	
    	IASTFunctionDefinition main = (IASTFunctionDefinition) declarations[0];
    	ICASTSimpleDeclSpecifier declSpec = (ICASTSimpleDeclSpecifier) main.getDeclSpecifier();
    	assertEquals(0, declSpec.getType());
    	
    	
    	assertEquals("main", main.getDeclarator().getName().toString());
    }
    
    

	/* I don't care about C98
	 */
	@Override
	public void testBug196468_emptyArrayInitializer() { }
	public void _testBug196468_emptyArrayInitializer() throws Exception { 
		super.testBug196468_emptyArrayInitializer();
	}
	
	
	
	/* LPG holds on to all the tokens as you parse, so I don't think
     * it would be easy to fix this bug.
	 */
	@Override
	public void	testScalabilityOfLargeTrivialInitializer_Bug253690() { }
	public void	_testScalabilityOfLargeTrivialInitializer_Bug253690() throws Exception {
		
		super.testScalabilityOfLargeTrivialInitializer_Bug253690();
	}
	
	
	/* All of the identifiers in the code resolve correctly.
	 * The problem is that some of the expressions parse wrong but
	 * thats not actually a big deal. Fixing this bug will be
	 * difficult so defer it to the future.
	 */
	@Override
	public void testBinaryVsCastAmbiguities_Bug237057() { }
	public void _testBinaryVsCastAmbiguities_Bug237057()  throws Exception { 
		super.testBinaryVsCastAmbiguities_Bug237057();
	}
	
	
	/* All of the identifiers in the code resolve correctly.
	 * The problem is that some of the expressions parse wrong but
	 * thats not actually a big deal. Fixing this bug will be
	 * difficult so defer it to the future.
	 */
	@Override
	public void testCastVsFunctionCallAmbiguities_Bug237057() { }
	public void _testCastVsFunctionCallAmbiguities_Bug237057() throws Exception { 
		super.testCastVsFunctionCallAmbiguities_Bug237057();
	}
	
	
	/* The LR parser generates the AST for switch statements
	 * differently than the DOM parser.
	 */
	@Override
	public void testCaseRange_Bug211882() { }
	public void _testCaseRange_Bug211882() throws Exception { 
		super.testCaseRange_Bug211882();
	}

}

Back to the top