blob: 6ec310b20cd6e2b37f69f7ea2b184babfb5a7147 (
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
|
/*******************************************************************************
* Copyright (c) 2009 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 Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.gnu;
import java.util.List;
import lpg.lpgjavaruntime.IToken;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.INodeFactory;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
import org.eclipse.cdt.core.dom.lrparser.action.AbstractParserAction;
import org.eclipse.cdt.core.dom.lrparser.action.ScopedStack;
import org.eclipse.cdt.core.dom.lrparser.action.TokenMap;
import org.eclipse.cdt.internal.core.dom.lrparser.gcc.GCCParsersym;
public class GNUBuildASTParserAction extends AbstractParserAction {
private final INodeFactory nodeFactory;
private final TokenMap tokenMap;
public GNUBuildASTParserAction(IParserActionTokenProvider parser, ScopedStack<Object> astStack, INodeFactory nodeFactory) {
super(parser, astStack);
this.nodeFactory = nodeFactory;
this.tokenMap = new TokenMap(GCCParsersym.orderedTerminalSymbols, parser.getOrderedTerminalSymbols());
}
@Override
protected IASTName createName(char[] image) {
return nodeFactory.newName(image);
}
@Override
protected boolean isCompletionToken(IToken token) {
return tokenMap.mapKind(token.getKind()) == GCCParsersym.TK_Completion;
}
/**
* Add support for GCC extended ASM declaration syntax.
*
*
* asm_definition -- same as in C++ but its not in C99 spec so we put it here
* ::= 'asm' '(' 'stringlit' ')' ';'
*
* extended_asm_declaration
* ::= 'asm' 'volatile' '(' extended_asm_param_seq ')' ';'
* | 'asm' '(' extended_asm_param_seq ')' ';'
*
*/
public void consumeDeclarationASM() {
List<IToken> tokens = parser.getRuleTokens();
int firstToken = 2;
if(tokenMap.mapKind(tokens.get(1).getKind()) == GCCParsersym.TK_volatile)
firstToken = 3;
StringBuilder sb = new StringBuilder();
boolean first = true;
for(IToken token : tokens.subList(firstToken, tokens.size()-2)) {
if(!first)
sb.append(' ');
sb.append(token.toString());
first = false;
}
IASTASMDeclaration asm = nodeFactory.newASMDeclaration(sb.toString());
setOffsetAndLength(asm);
astStack.push(asm);
}
/**
* primary_expression
* ::= '(' compound_statement ')'
*/
public void consumeCompoundStatementExpression() {
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) astStack.pop();
IGNUASTCompoundStatementExpression expr = nodeFactory.newGNUCompoundStatementExpression(compoundStatement);
setOffsetAndLength(expr);
astStack.push(expr);
}
}
|