~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/gc/boehm/leaksoup/CallTree.java

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * The contents of this file are subject to the Netscape Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/NPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 *
 
13
 * The Original Code is Mozilla Communicator client code, released
 
14
 * March 31, 1998.
 
15
 *
 
16
 * The Initial Developer of the Original Code is Netscape
 
17
 * Communications Corporation.  Portions created by Netscape are
 
18
 * Copyright (C) 1998 Netscape Communications Corporation. All
 
19
 * Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *
 
23
 * Patrick C. Beard <beard@netscape.com>
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the
 
26
 * terms of the GNU Public License (the "GPL"), in which case the
 
27
 * provisions of the GPL are applicable instead of those above.
 
28
 * If you wish to allow use of your version of this file only
 
29
 * under the terms of the GPL and not to allow others to use your
 
30
 * version of this file under the NPL, indicate your decision by
 
31
 * deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL.  If you do not delete
 
33
 * the provisions above, a recipient may use your version of this
 
34
 * file under either the NPL or the GPL.
 
35
 */
 
36
 
 
37
import java.util.Enumeration;
 
38
import java.util.Vector;
 
39
 
 
40
/**
 
41
 * Represents a global tree of calls.
 
42
 */
 
43
public class CallTree {
 
44
        public static class Node {
 
45
            int id;
 
46
            Node parent;
 
47
            String data;
 
48
            
 
49
            public Node(int id, Node parent) {
 
50
                this.id = id;
 
51
                this.parent = parent;
 
52
            }
 
53
        };
 
54
 
 
55
        private Vector nodes = new Vector(16000);
 
56
        private StringTable strings;
 
57
 
 
58
    public CallTree(StringTable strings) {
 
59
        nodes.addElement(null);
 
60
        this.strings = strings;
 
61
    }
 
62
        
 
63
        /**
 
64
         * Parses a line of the form:
 
65
         * <c id=number pid=number>function[file,offset]</c>
 
66
         */
 
67
        public Node parseNode(String line) {
 
68
        try {
 
69
            int start = 1 + line.indexOf('=');
 
70
            int endTag = line.indexOf('>');
 
71
            if (line.charAt(endTag - 1) == '/') {
 
72
                // just references an already parsed node.
 
73
                int id = Integer.parseInt(line.substring(start, endTag - 1));
 
74
                return (Node) nodes.elementAt(id);
 
75
            } else {
 
76
                int end = line.indexOf(' ', start + 1);
 
77
                int id = Integer.parseInt(line.substring(start, end));
 
78
                start = 1 + line.indexOf('=', end + 1);
 
79
                end = line.indexOf('>', start + 1);
 
80
                int pid = Integer.parseInt(line.substring(start, end));
 
81
                Node node = addNode(id, pid);
 
82
                start = end + 1;
 
83
                end = line.lastIndexOf('<');
 
84
                node.data = strings.intern(line.substring(start, end));
 
85
                return node;
 
86
            }
 
87
        } catch (NumberFormatException nfe) {
 
88
        }
 
89
        return null;
 
90
        }
 
91
        
 
92
        public Node addNode(int id, int pid) {
 
93
            Node parent = (Node) nodes.elementAt(pid);
 
94
            Node node = new Node(id, parent);
 
95
            nodes.addElement(node);
 
96
            if (nodes.size() != (id + 1))
 
97
                throw new Error("inconsistent node id");
 
98
            return node;
 
99
        }
 
100
        
 
101
        public Node getNode(int id) {
 
102
            return (Node) nodes.elementAt(id);
 
103
        }
 
104
}