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