1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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 *******************************************************************************/
9 package org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.tsdl
;
11 import java
.util
.List
;
13 import org
.antlr
.runtime
.tree
.CommonTree
;
14 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
15 import org
.eclipse
.jdt
.annotation
.Nullable
;
16 import org
.eclipse
.tracecompass
.ctf
.core
.event
.metadata
.DeclarationScope
;
17 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.IDeclaration
;
18 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.AbstractScopedCommonTreeParser
;
19 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.metadata
.ParseException
;
22 * Basic parser for all abstract data types
24 * @author Matthew Khouzam
27 public final class TypeDeclarationParser
extends AbstractScopedCommonTreeParser
{
30 * Parameter object with a current scope and a list of pointers
32 * @author Matthew Khouzam
36 public static final class Param
implements ICommonTreeParserParameter
{
37 private final DeclarationScope fDeclarationScope
;
38 private final @Nullable List
<CommonTree
> fPointerList
;
44 * the list of pointers
48 public Param(@Nullable List
<CommonTree
> pointerList
, DeclarationScope scope
) {
49 fPointerList
= pointerList
;
50 fDeclarationScope
= scope
;
57 public final static TypeDeclarationParser INSTANCE
= new TypeDeclarationParser();
59 private TypeDeclarationParser() {
63 * Parses a type specifier list as a user-declared type.
65 * @param typeSpecifierList
66 * A TYPE_SPECIFIER_LIST node containing a user-declared type.
68 * (pointerList, currentscope) A list of POINTER nodes that apply
69 * to the type specified in typeSpecifierList.
71 * @return The corresponding declaration.
72 * @throws ParseException
73 * If the type does not exist (has not been found).
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$
80 DeclarationScope scope
= ((Param
) param
).fDeclarationScope
;
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
));
87 * Use the string representation to search the type in the current scope
89 IDeclaration decl
= scope
.lookupTypeRecursive(typeStringRepresentation
);
92 throw new ParseException("Type " + typeStringRepresentation
//$NON-NLS-1$
93 + " has not been defined."); //$NON-NLS-1$