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

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GNUBuildASTParserAction.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) 2009 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
 
 *     IBM Corporation - initial API and implementation
10
 
 *******************************************************************************/
11
 
package org.eclipse.cdt.core.dom.lrparser.action.gnu;
12
 
 
13
 
import java.util.List;
14
 
 
15
 
import lpg.lpgjavaruntime.IToken;
16
 
 
17
 
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
18
 
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
19
 
import org.eclipse.cdt.core.dom.ast.IASTName;
20
 
import org.eclipse.cdt.core.dom.ast.INodeFactory;
21
 
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
22
 
import org.eclipse.cdt.core.dom.lrparser.action.AbstractParserAction;
23
 
import org.eclipse.cdt.core.dom.lrparser.action.ITokenStream;
24
 
import org.eclipse.cdt.core.dom.lrparser.action.ScopedStack;
25
 
import org.eclipse.cdt.core.dom.lrparser.action.TokenMap;
26
 
import org.eclipse.cdt.internal.core.dom.lrparser.gcc.GCCParsersym;
27
 
 
28
 
public class GNUBuildASTParserAction extends AbstractParserAction {
29
 
 
30
 
        private final INodeFactory nodeFactory;
31
 
        
32
 
        private final TokenMap tokenMap;
33
 
        
34
 
        public GNUBuildASTParserAction(ITokenStream parser, ScopedStack<Object> astStack, INodeFactory nodeFactory) {
35
 
                super(parser, astStack);
36
 
                
37
 
                this.nodeFactory = nodeFactory;
38
 
                this.tokenMap = new TokenMap(GCCParsersym.orderedTerminalSymbols, parser.getOrderedTerminalSymbols());
39
 
        }
40
 
        
41
 
 
42
 
        @Override
43
 
        protected IASTName createName(char[] image) {
44
 
                return nodeFactory.newName(image);
45
 
        }
46
 
 
47
 
        @Override
48
 
        protected boolean isCompletionToken(IToken token) {
49
 
                return tokenMap.mapKind(token.getKind()) == GCCParsersym.TK_Completion;
50
 
        }
51
 
        
52
 
 
53
 
        
54
 
        /**
55
 
         * Add support for GCC extended ASM declaration syntax.
56
 
         * 
57
 
         * 
58
 
         * asm_definition -- same as in C++ but its not in C99 spec so we put it here
59
 
     *     ::= 'asm' '(' 'stringlit' ')' ';'
60
 
     * 
61
 
     * extended_asm_declaration
62
 
     *     ::= 'asm' 'volatile' '(' extended_asm_param_seq ')' ';'
63
 
     *       | 'asm' '(' extended_asm_param_seq ')' ';'
64
 
     *       
65
 
         */
66
 
        public void consumeDeclarationASM() {
67
 
                List<IToken> tokens = stream.getRuleTokens();
68
 
                
69
 
                int firstToken = 2; 
70
 
                if(tokenMap.mapKind(tokens.get(1).getKind()) == GCCParsersym.TK_volatile)
71
 
                        firstToken = 3;
72
 
                
73
 
                StringBuilder sb = new StringBuilder();
74
 
                boolean first = true;
75
 
                for(IToken token : tokens.subList(firstToken, tokens.size()-2)) {
76
 
                        if(!first)
77
 
                                sb.append(' ');
78
 
                        sb.append(token.toString());
79
 
                        first = false;
80
 
                }
81
 
                
82
 
                IASTASMDeclaration asm = nodeFactory.newASMDeclaration(sb.toString());
83
 
                setOffsetAndLength(asm);
84
 
                astStack.push(asm);
85
 
        }
86
 
 
87
 
 
88
 
        /**
89
 
         * primary_expression
90
 
     *     ::= '(' compound_statement ')'
91
 
         */
92
 
        public void consumeCompoundStatementExpression() {
93
 
                IASTCompoundStatement compoundStatement = (IASTCompoundStatement) astStack.pop();
94
 
                IGNUASTCompoundStatementExpression expr = nodeFactory.newGNUCompoundStatementExpression(compoundStatement);
95
 
                setOffsetAndLength(expr);
96
 
                astStack.push(expr);
97
 
        }
98
 
}