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
106
107
108
109
110
111
|
/*******************************************************************************
* Copyright (c) 2009, 2010 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.lrparser.xlc.action;
import lpg.lpgjavaruntime.IToken;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
import org.eclipse.cdt.core.dom.lrparser.action.ITokenMap;
import org.eclipse.cdt.core.dom.lrparser.action.ITokenStream;
import org.eclipse.cdt.core.dom.lrparser.action.ScopedStack;
import org.eclipse.cdt.core.dom.lrparser.action.TokenMap;
import org.eclipse.cdt.core.dom.lrparser.action.cpp.ICPPSecondaryParserFactory;
import org.eclipse.cdt.core.dom.lrparser.action.gnu.GPPBuildASTParserAction;
import org.eclipse.cdt.core.lrparser.xlc.ast.ICPPASTStaticAssertDeclaration;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCPPASTModifiedArrayModifier;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCPPASTVectorTypeSpecifier;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCPPNodeFactory;
import org.eclipse.cdt.internal.core.lrparser.xlc.cpp.XlcCPPParsersym;
public class XlcCPPBuildASTParserAction extends GPPBuildASTParserAction {
private IXlcCPPNodeFactory nodeFactory;
private final ITokenMap tokenMap;
public XlcCPPBuildASTParserAction(ITokenStream parser,
ScopedStack<Object> astStack, IXlcCPPNodeFactory nodeFactory,
ICPPSecondaryParserFactory parserFactory) {
super(parser, astStack, nodeFactory, parserFactory);
this.nodeFactory = nodeFactory;
this.tokenMap = new TokenMap(XlcCPPParsersym.orderedTerminalSymbols, parser.getOrderedTerminalSymbols());
}
/*
* vector_type
* ::= <openscope-ast> sqlist_op 'vector' vector_type_specifier all_specifier_qualifier_list
*/
public void consumeVectorTypeSpecifier() {
IXlcCPPASTVectorTypeSpecifier declSpec = nodeFactory.newVectorTypeSpecifier();
for(Object specifier : astStack.closeScope()) {
if(specifier instanceof IToken) {
switch(tokenMap.mapKind(((IToken)specifier).getKind())) {
case XlcCPPParsersym.TK_pixel :
declSpec.setPixel(true);
continue;
case XlcCPPParsersym.TK_vector :
continue;
}
}
setSpecifier(declSpec, specifier);
}
setOffsetAndLength(declSpec);
astStack.push(declSpec);
}
public void consumeDirectDeclaratorModifiedArrayModifier(boolean isStatic,
boolean isVarSized, boolean hasTypeQualifierList, boolean hasAssignmentExpr) {
assert isStatic || isVarSized || hasTypeQualifierList;
IXlcCPPASTModifiedArrayModifier arrayModifier = nodeFactory.newModifiedArrayModifier(null);
// consume all the stuff between the square brackets into an array modifier
arrayModifier.setStatic(isStatic);
arrayModifier.setVariableSized(isVarSized);
if(hasAssignmentExpr)
arrayModifier.setConstantExpression((IASTExpression)astStack.pop());
if(hasTypeQualifierList)
collectArrayModifierTypeQualifiers(arrayModifier);
setOffsetAndLength(arrayModifier);
astStack.push(arrayModifier);
}
private void collectArrayModifierTypeQualifiers(IXlcCPPASTModifiedArrayModifier arrayModifier) {
for(Object o : astStack.closeScope()) {
switch(tokenMap.mapKind(((IToken)o).getKind())) {
case XlcCPPParsersym.TK_const: arrayModifier.setConst(true); break;
case XlcCPPParsersym.TK_restrict: arrayModifier.setRestrict(true); break;
case XlcCPPParsersym.TK_volatile: arrayModifier.setVolatile(true); break;
}
}
}
/**
* staticAssertDeclaration ::= '__static_assert' '(' expression ',' literal ')' ';'
*/
public void consumeCPPASTStaticAssertDeclaration() {
ICPPASTLiteralExpression message = (ICPPASTLiteralExpression) astStack.pop();
IASTExpression condition = (IASTExpression) astStack.pop();
ICPPASTStaticAssertDeclaration assertDeclaration = nodeFactory.newStaticAssertion(condition, message);
setOffsetAndLength(assertDeclaration);
astStack.push(assertDeclaration);
}
}
|