~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2004, 2010 IBM Corporation and others.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     Andrew Niefer (IBM Corporation) - initial API and implementation
 
10
 *     Markus Schorn (Wind River Systems)
 
11
 *******************************************************************************/
 
12
package org.eclipse.cdt.internal.core.dom.parser.c;
 
13
 
 
14
import org.eclipse.cdt.core.dom.ILinkage;
 
15
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
 
16
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
 
17
import org.eclipse.cdt.core.dom.ast.IASTName;
 
18
import org.eclipse.cdt.core.dom.ast.IASTNode;
 
19
import org.eclipse.cdt.core.dom.ast.IBinding;
 
20
import org.eclipse.cdt.core.dom.ast.IEnumerator;
 
21
import org.eclipse.cdt.core.dom.ast.IScope;
 
22
import org.eclipse.cdt.core.dom.ast.IType;
 
23
import org.eclipse.cdt.core.dom.ast.IValue;
 
24
import org.eclipse.cdt.internal.core.dom.Linkage;
 
25
import org.eclipse.cdt.internal.core.dom.parser.ASTEnumerator;
 
26
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
 
27
import org.eclipse.cdt.internal.core.dom.parser.Value;
 
28
import org.eclipse.core.runtime.PlatformObject;
 
29
 
 
30
/**
 
31
 * C-specific binding for enumerators.
 
32
 */
 
33
public class CEnumerator extends PlatformObject implements IEnumerator {
 
34
    public static class CEnumeratorProblem extends ProblemBinding implements IEnumerator {
 
35
        public CEnumeratorProblem(IASTNode node, int id, char[] arg) {
 
36
            super(node, id, arg);
 
37
        }
 
38
                public IValue getValue() {
 
39
                        return Value.UNKNOWN;
 
40
                }
 
41
    }
 
42
 
 
43
    private final IASTName enumeratorName;
 
44
 
 
45
    public CEnumerator(IASTEnumerator enumtor) {
 
46
                this.enumeratorName = enumtor.getName();
 
47
                enumeratorName.setBinding(this);
 
48
        }
 
49
    
 
50
    public IASTNode getPhysicalNode() {
 
51
        return enumeratorName;
 
52
    }
 
53
 
 
54
    /* (non-Javadoc)
 
55
     * @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
 
56
     */
 
57
    public String getName() {
 
58
        return enumeratorName.toString();
 
59
    }
 
60
 
 
61
    public char[] getNameCharArray() {
 
62
        return enumeratorName.toCharArray();
 
63
    }
 
64
 
 
65
    /* (non-Javadoc)
 
66
     * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
 
67
     */
 
68
    public IScope getScope() {
 
69
        return CVisitor.getContainingScope(enumeratorName.getParent());
 
70
    }
 
71
 
 
72
        /* (non-Javadoc)
 
73
         * @see org.eclipse.cdt.core.dom.ast.IEnumerator#getType()
 
74
         */
 
75
        public IType getType() {
 
76
                return (IType) getOwner();
 
77
        }
 
78
 
 
79
        public ILinkage getLinkage() {
 
80
                return Linkage.C_LINKAGE;
 
81
        }
 
82
 
 
83
        public IBinding getOwner() {
 
84
            IASTEnumerator etor = (IASTEnumerator) enumeratorName.getParent();
 
85
                IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) etor.getParent();
 
86
                return enumSpec.getName().resolveBinding();
 
87
        }
 
88
 
 
89
        public IValue getValue() {
 
90
                IASTNode parent= enumeratorName.getParent();
 
91
                if (parent instanceof ASTEnumerator) 
 
92
                        return ((ASTEnumerator) parent).getIntegralValue();
 
93
                
 
94
                return Value.UNKNOWN;
 
95
        }
 
96
 
 
97
        @Override
 
98
        public String toString() {
 
99
                return getName();
 
100
        }
 
101
}