Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 97fa5a02e640114e750d823026327bc8ceba9ab3 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*******************************************************************************
 * Copyright (c) 2004, 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
 *******************************************************************************/
package org.eclipse.cdt.core.parser.tests;

import java.io.StringWriter;
import java.io.Writer;
import java.util.Iterator;

import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTVariable;

/**
 * @author jcamelon
 *
 */
public class GCCQuickParseExtensionsTest extends BaseASTTest {

	/**
	 * @param a
	 */
	public GCCQuickParseExtensionsTest(String a) {
		super(a);
		// TODO Auto-generated constructor stub
	}

    public void testBug39694() throws Exception
    {
        IASTVariable variable = (IASTVariable)parse("int ab$cd = 1;").getDeclarations().next(); //$NON-NLS-1$
        assertEquals( variable.getName(), "ab$cd"); //$NON-NLS-1$
    }
    
    public void testBug39704A() throws Exception
    {
        IASTVariable foo = (IASTVariable) assertSoleDeclaration("__declspec (dllimport) int foo;"); //$NON-NLS-1$
        assertEquals( foo.getName(), "foo"); //$NON-NLS-1$
    } 
    public void testBug39704D() throws Exception
    {
        IASTFunction func1 = (IASTFunction) assertSoleDeclaration("__declspec(dllexport) int func1 (int a) {}"); //$NON-NLS-1$
        assertEquals( func1.getName(), "func1"); //$NON-NLS-1$
    }
    
    public void testBug39695() throws Exception
    {
        parse("int a = __alignof__ (int);"); //$NON-NLS-1$
    }
    
    public void testBug39684() throws Exception
    {
        parse("typeof(foo(1)) bar () { return foo(1); }"); //$NON-NLS-1$
    }
    
    public void testBug39703() throws Exception
    {
        Writer code = new StringWriter();
        code.write("/* __extension__ enables GNU C mode for the duration of the declaration.  */\n"); //$NON-NLS-1$
        code.write("__extension__ struct G {\n"); //$NON-NLS-1$
        code.write("  struct { char z; };\n"); //$NON-NLS-1$
        code.write("  char g;\n"); //$NON-NLS-1$
        code.write("};\n"); //$NON-NLS-1$
       	IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString());
       	IASTClassSpecifier G = ((IASTClassSpecifier)abs.getTypeSpecifier());
       	assertEquals( G.getName(), "G" ); //$NON-NLS-1$
       	assertEquals( G.getClassKind(), ASTClassKind.STRUCT );
       	Iterator i = G.getDeclarations();
       	assertEquals( ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier()).getName(), "" ); //$NON-NLS-1$
       	assertEquals( ((IASTField)i.next()).getName(), "g" ); //$NON-NLS-1$
       	assertFalse( i.hasNext() );
    }

    public void testBug39698A() throws Exception
    {
        parse("int c = a <? b;"); //$NON-NLS-1$
    }
    public void testBug39698B() throws Exception
    {
    	parse("int c = a >? b;"); //$NON-NLS-1$
    }

	public void testBug39554() throws Exception
	{
		 parse("_Pragma(\"foobar\")", true, true, ParserLanguage.C ); //$NON-NLS-1$
	}

    public void testBug39704B() throws Exception
    {
		IASTVariable d = (IASTVariable)assertSoleDeclaration("extern int (* import) (void) __attribute__((dllimport));"); //$NON-NLS-1$
		assertEquals( d.getName(), "import"); // false assertion  //$NON-NLS-1$
    }
    public void testBug39704C() throws Exception
    {
 		IASTFunction f = (IASTFunction)assertSoleDeclaration("int func2 (void) __attribute__((dllexport));"); //$NON-NLS-1$
		assertEquals( f.getName(), "func2"); //$NON-NLS-1$
    }
    
    public void testBug39704E() throws Exception
    {
		IASTVariable d = (IASTVariable)assertSoleDeclaration("extern int * __attribute__((dllimport)) (* import) (void);"); //$NON-NLS-1$
		assertEquals( d.getName(), "import"); // false assertion  //$NON-NLS-1$
    }
    
    public void testBug39704F() throws Exception
    {
		IASTVariable d = (IASTVariable)assertSoleDeclaration("extern int __attribute__((dllimport)) (* import) (void);"); //$NON-NLS-1$
		assertEquals( d.getName(), "import"); // false assertion  //$NON-NLS-1$
    }

    public void testBug39704G() throws Exception
    {
		IASTVariable d = (IASTVariable)assertSoleDeclaration("int x __attribute__ ((aligned (16))) = 0;"); //$NON-NLS-1$
		assertEquals( d.getName(), "x"); // false assertion  //$NON-NLS-1$
    }
    
    public void testBug39686() throws Exception
    {
        Writer code = new StringWriter();
        code.write("__complex__ double x; // complex double\n"); //$NON-NLS-1$
        code.write("__complex__ short int a; // complex short int\n"); //$NON-NLS-1$
        code.write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); //$NON-NLS-1$
        code.write("__complex__ int a = 3i; // imaginary intege r literal\n"); //$NON-NLS-1$
        code.write("double v = __real__ x; // real part of expression\n"); //$NON-NLS-1$
        code.write("double w = __imag__ x; // imaginary part of expression\n"); //$NON-NLS-1$
        parse(code.toString());
    }
    
    public void testBug39681() throws Exception
    {
        Writer code = new StringWriter();
        code.write("double\n"); //$NON-NLS-1$
        code.write("foo (double a, double b)\n"); //$NON-NLS-1$
        code.write("{\n"); //$NON-NLS-1$
        code.write("  double square (double z) { return z * z; }\n"); //$NON-NLS-1$
        code.write("  return square (a) + square (b);\n"); //$NON-NLS-1$
        code.write("}\n"); //$NON-NLS-1$
        parse(code.toString());
    }
    
    public void testBug39677() throws Exception
    {
        parse("B::B() : a(({ 1; })) {}"); //$NON-NLS-1$
        Writer writer = new StringWriter();
        writer.write( "B::B() : a(( { int y = foo (); int z;\n" ); //$NON-NLS-1$
        writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
        writer.write( "else z = - y;\n" );//$NON-NLS-1$
        writer.write( "z; }))\n" );//$NON-NLS-1$
        parse( writer.toString() );
        writer = new StringWriter();
        writer.write( "int x = ({ int y = foo (); int z;\n" ); //$NON-NLS-1$
        writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
        writer.write( "else z = - y;\n" );//$NON-NLS-1$
        writer.write( "z; });\n" );//$NON-NLS-1$
        writer = new StringWriter();
        writer.write( "typeof({ int y = foo (); int z;\n" ); //$NON-NLS-1$
        writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
        writer.write( "else z = - y;\n" );//$NON-NLS-1$
        writer.write( "z; }) zoot;\n" );//$NON-NLS-1$
    }
    
    public void testBug39701A() throws Exception
    {
    	parse("extern template int max (int, int);"); //$NON-NLS-1$
    }
    public void testBug39701B() throws Exception
    {
    	parse("inline template class Foo<int>;"); //$NON-NLS-1$
    }
    public void testBug39701C() throws Exception
    {
        parse("static template class Foo<int>;"); //$NON-NLS-1$
    }
}

Back to the top