Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3d3e9f4a3546d9b353743a930f55a433417f6651 (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
/*******************************************************************************
 * Copyright (c) 2008, 2012 IBM Wind River Systems, Inc. and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Markus Schorn - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;

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.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousParameterDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
import org.eclipse.core.runtime.Assert;

/**
 * Handles ambiguities for parameter declarations.
 * <br>
 * void function(const D*); // is D a type?
 * @since 5.0.1
 */
public class CASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implements IASTAmbiguousParameterDeclaration {

    private IASTParameterDeclaration[] paramDecls = new IASTParameterDeclaration[2];
    private int declPos=-1;


    public CASTAmbiguousParameterDeclaration(IASTParameterDeclaration... decls) {
		for (IASTParameterDeclaration d : decls)
			addParameterDeclaration(d);
	}

	@Override
	public void addParameterDeclaration(IASTParameterDeclaration d) {
        assertNotFrozen();
    	if (d != null) {
    		paramDecls = ArrayUtil.appendAt(IASTParameterDeclaration.class, paramDecls, ++declPos, d);
    		d.setParent(this);
			d.setPropertyInParent(SUBDECLARATION);
    	}
    }

	@Override
	protected void beforeResolution() {
		// populate containing scope, so that it will not be affected by the alternative branches.
		IScope scope= CVisitor.getContainingScope(this);
		if (scope instanceof IASTInternalScope) {
			((IASTInternalScope) scope).populateCache();
		}
	}

    @Override
	public IASTParameterDeclaration[] getParameterDeclarations() {
    	paramDecls = ArrayUtil.trimAt(IASTParameterDeclaration.class, paramDecls, declPos);
        return paramDecls;
    }

    @Override
	public IASTNode[] getNodes() {
        return getParameterDeclarations();
    }

	@Override
	public IASTDeclSpecifier getDeclSpecifier() {
		return paramDecls[0].getDeclSpecifier();
	}

	@Override
	public IASTDeclarator getDeclarator() {
		return paramDecls[0].getDeclarator();
	}

	@Override
	public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
        assertNotFrozen();
		Assert.isLegal(false);
	}

	@Override
	public void setDeclarator(IASTDeclarator declarator) {
        assertNotFrozen();
		Assert.isLegal(false);
	}

	@Override
	public IASTParameterDeclaration copy() {
		throw new UnsupportedOperationException();
	}

	@Override
	public IASTParameterDeclaration copy(CopyStyle style) {
		throw new UnsupportedOperationException();
	}
}

Back to the top