ctf: fix Modifier order to always be static final
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / event / metadata / tsdl / TypeDeclarationParser.java
CommitLineData
b1ea73b5
MK
1/*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9package org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl;
10
11import java.util.List;
12
13import org.antlr.runtime.tree.CommonTree;
14import org.eclipse.jdt.annotation.NonNullByDefault;
15import org.eclipse.jdt.annotation.Nullable;
16import org.eclipse.tracecompass.ctf.core.event.metadata.DeclarationScope;
17import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
18import org.eclipse.tracecompass.internal.ctf.core.event.metadata.AbstractScopedCommonTreeParser;
19import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ParseException;
20
21/**
22 * Basic parser for all abstract data types
23 *
24 * @author Matthew Khouzam
25 *
26 */
4055c3a1 27public final class TypeDeclarationParser extends AbstractScopedCommonTreeParser {
b1ea73b5
MK
28
29 /**
30 * Parameter object with a current scope and a list of pointers
31 *
32 * @author Matthew Khouzam
33 *
34 */
35 @NonNullByDefault
36 public static final class Param implements ICommonTreeParserParameter {
37 private final DeclarationScope fDeclarationScope;
38 private final @Nullable List<CommonTree> fPointerList;
39
40 /**
41 * Constructor
42 *
43 * @param pointerList
44 * the list of pointers
45 * @param scope
46 * the current scope
47 */
48 public Param(@Nullable List<CommonTree> pointerList, DeclarationScope scope) {
49 fPointerList = pointerList;
50 fDeclarationScope = scope;
51 }
52 }
53
54 /**
55 * Instance
56 */
5c50e284 57 public static final TypeDeclarationParser INSTANCE = new TypeDeclarationParser();
b1ea73b5
MK
58
59 private TypeDeclarationParser() {
60 }
61
62 /**
63 * Parses a type specifier list as a user-declared type.
64 *
65 * @param typeSpecifierList
66 * A TYPE_SPECIFIER_LIST node containing a user-declared type.
67 * @param param
68 * (pointerList, currentscope) A list of POINTER nodes that apply
69 * to the type specified in typeSpecifierList.
70 *
71 * @return The corresponding declaration.
72 * @throws ParseException
73 * If the type does not exist (has not been found).
74 */
75 @Override
76 public IDeclaration parse(CommonTree typeSpecifierList, ICommonTreeParserParameter param) throws ParseException {
77 if (!(param instanceof Param)) {
78 throw new IllegalArgumentException("Param must be a " + Param.class.getCanonicalName()); //$NON-NLS-1$
79 }
80 DeclarationScope scope = ((Param) param).fDeclarationScope;
81
82 List<CommonTree> pointerList = ((Param) param).fPointerList;
83 /* Create the string representation of the type declaration */
84 String typeStringRepresentation = TypeDeclarationStringParser.INSTANCE.parse(typeSpecifierList, new TypeDeclarationStringParser.Param(pointerList));
85
86 /*
87 * Use the string representation to search the type in the current scope
88 */
89 IDeclaration decl = scope.lookupTypeRecursive(typeStringRepresentation);
90
91 if (decl == null) {
92 throw new ParseException("Type " + typeStringRepresentation //$NON-NLS-1$
93 + " has not been defined."); //$NON-NLS-1$
94 }
95
96 return decl;
97 }
98
99}
This page took 0.029398 seconds and 5 git commands to generate.