Commit | Line | Data |
---|---|---|
d45d05a1 MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2016 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 | *******************************************************************************/ | |
9 | package org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.callsite; | |
10 | ||
11 | import java.util.List; | |
12 | ||
13 | import org.antlr.runtime.tree.CommonTree; | |
14 | import org.eclipse.jdt.annotation.NonNull; | |
15 | import org.eclipse.tracecompass.ctf.core.event.CTFCallsite; | |
16 | import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ICommonTreeParser; | |
d45d05a1 MK |
17 | |
18 | /** | |
19 | * Callsite as described in section 7.4 of the TSDL spec in CTF 1.8.2 | |
20 | * | |
21 | * <pre> | |
22 | * | |
23 | * callsite { | |
24 | * name = "event_name"; | |
25 | * func = "func_name"; | |
26 | * file = "myfile.c"; | |
27 | * line = 39; | |
28 | * ip = 0x40096c; | |
29 | * }; | |
30 | * </pre> | |
31 | * | |
32 | * @author Matthew Khouzam | |
33 | * | |
34 | */ | |
35 | public final class CallSiteParser implements ICommonTreeParser { | |
36 | ||
37 | /** | |
38 | * Instance of the parser | |
39 | */ | |
40 | public static CallSiteParser INSTANCE = new CallSiteParser(); | |
41 | ||
42 | private static final @NonNull String LINE = "line"; //$NON-NLS-1$ | |
43 | private static final @NonNull String FILE = "file"; //$NON-NLS-1$ | |
44 | private static final @NonNull String IP = "ip"; //$NON-NLS-1$ | |
45 | private static final @NonNull String FUNC = "func"; //$NON-NLS-1$ | |
46 | private static final @NonNull String NAME = "name"; //$NON-NLS-1$ | |
47 | ||
48 | private CallSiteParser() { | |
49 | // do nothing | |
50 | } | |
51 | ||
52 | @Override | |
0c596298 AB |
53 | public @NonNull CTFCallsite parse(CommonTree tree, ICommonTreeParserParameter param) { |
54 | /* | |
55 | * this is to replace the previous quotes with nothing... | |
56 | * effectively deleting them | |
57 | */ | |
58 | final String emptyString = ""; //$NON-NLS-1$ | |
59 | ||
60 | /* this is a regex to find the leading and trailing quotes */ | |
61 | final String regex = "^\"|\"$"; //$NON-NLS-1$ | |
62 | ||
63 | String fileName = null; | |
d45d05a1 | 64 | String funcName = null; |
0c596298 AB |
65 | String name = null; |
66 | long lineNumber =-1; | |
d45d05a1 | 67 | long ip = -1; |
d45d05a1 | 68 | |
0c596298 | 69 | List<CommonTree> children = tree.getChildren(); |
d45d05a1 | 70 | for (CommonTree child : children) { |
0c596298 | 71 | String left = child.getChild(0).getChild(0).getChild(0).getText(); |
d45d05a1 | 72 | if (left.equals(NAME)) { |
0c596298 | 73 | name = child.getChild(1).getChild(0).getChild(0).getText().replaceAll(regex, emptyString); |
d45d05a1 | 74 | } else if (left.equals(FUNC)) { |
0c596298 | 75 | funcName = child.getChild(1).getChild(0).getChild(0).getText().replaceAll(regex, emptyString); |
d45d05a1 MK |
76 | } else if (left.equals(IP)) { |
77 | ip = Long.decode(child.getChild(1).getChild(0).getChild(0).getText()); | |
78 | } else if (left.equals(FILE)) { | |
0c596298 | 79 | fileName = child.getChild(1).getChild(0).getChild(0).getText().replaceAll(regex, emptyString); |
d45d05a1 MK |
80 | } else if (left.equals(LINE)) { |
81 | lineNumber = Long.parseLong(child.getChild(1).getChild(0).getChild(0).getText()); | |
82 | } | |
83 | } | |
0c596298 AB |
84 | |
85 | if (name == null || funcName == null || fileName == null) { | |
86 | throw new NullPointerException("CTFCallsite parameters shouldn't be null!"); //$NON-NLS-1$ | |
87 | } | |
88 | ||
d45d05a1 MK |
89 | return new CTFCallsite(name, funcName, ip, fileName, lineNumber); |
90 | } | |
91 | ||
92 | } |