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
9
* IBM Corporation - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.core.dom.lrparser.action.gnu;
13
import java.util.List;
15
import lpg.lpgjavaruntime.IToken;
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;
28
public class GNUBuildASTParserAction extends AbstractParserAction {
30
private final INodeFactory nodeFactory;
32
private final TokenMap tokenMap;
34
public GNUBuildASTParserAction(ITokenStream parser, ScopedStack<Object> astStack, INodeFactory nodeFactory) {
35
super(parser, astStack);
37
this.nodeFactory = nodeFactory;
38
this.tokenMap = new TokenMap(GCCParsersym.orderedTerminalSymbols, parser.getOrderedTerminalSymbols());
43
protected IASTName createName(char[] image) {
44
return nodeFactory.newName(image);
48
protected boolean isCompletionToken(IToken token) {
49
return tokenMap.mapKind(token.getKind()) == GCCParsersym.TK_Completion;
55
* Add support for GCC extended ASM declaration syntax.
58
* asm_definition -- same as in C++ but its not in C99 spec so we put it here
59
* ::= 'asm' '(' 'stringlit' ')' ';'
61
* extended_asm_declaration
62
* ::= 'asm' 'volatile' '(' extended_asm_param_seq ')' ';'
63
* | 'asm' '(' extended_asm_param_seq ')' ';'
66
public void consumeDeclarationASM() {
67
List<IToken> tokens = stream.getRuleTokens();
70
if(tokenMap.mapKind(tokens.get(1).getKind()) == GCCParsersym.TK_volatile)
73
StringBuilder sb = new StringBuilder();
75
for(IToken token : tokens.subList(firstToken, tokens.size()-2)) {
78
sb.append(token.toString());
82
IASTASMDeclaration asm = nodeFactory.newASMDeclaration(sb.toString());
83
setOffsetAndLength(asm);
90
* ::= '(' compound_statement ')'
92
public void consumeCompoundStatementExpression() {
93
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) astStack.pop();
94
IGNUASTCompoundStatementExpression expr = nodeFactory.newGNUCompoundStatementExpression(compoundStatement);
95
setOffsetAndLength(expr);