Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 746895b3fb31504bb0ff3ecac7f616298ccf356d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
 * Copyright (c) 2000, 2016 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.utils.debug.stabs;

import java.io.IOException;
import java.io.Reader;


public class TypeNumber {

	int typeno;
	int fileno;

	public TypeNumber(int f, int t) {
		fileno = f;
		typeno = t;
	}

	public TypeNumber(Reader reader) {
		parseTypeNumber(reader);
	}

	public int getTypeNo() {
		return typeno;
	}

	public int getFileNo() {
		return fileno;
	} 

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof TypeNumber) {
			TypeNumber tn = (TypeNumber)obj;
			return tn.typeno == typeno && tn.fileno == fileno;
		}
		return super.equals(obj);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return fileno*10 + typeno;
	}

	void parseTypeNumber(Reader reader) {
		try {
			int c = reader.read();
			char ch = (char)c;
			if (c == -1) {
				return;
			} else if (ch == '(') {
				StringBuilder sb = new StringBuilder();
				while ((c = reader.read()) != -1) {
					ch = (char)c;
					if (ch == ')') {
						try {
							typeno = Integer.parseInt(sb.toString());
						} catch (NumberFormatException e) {
						}
						break;
					} else if (ch == ',') {
						try {
							fileno = Integer.parseInt(sb.toString());
						} catch (NumberFormatException e) {
						}
						sb.setLength(0);
					} else if (Character.isDigit(ch)) {
						sb.append(ch);
					} else {
						break;
					}
				}
			} else if (Character.isDigit(ch)) {
				StringBuilder sb = new StringBuilder();
				sb.append(ch);
				reader.mark(1);
				while ((c = reader.read()) != -1) {
					ch = (char)c;
					if (Character.isDigit(ch)) {
						sb.append(ch);
					} else {
						reader.reset();
						break;
					}
				}
				try {
					typeno = Integer.parseInt(sb.toString());
				} catch (NumberFormatException e) {
				}
			}
		} catch (IOException e) {
		}
	}

}

Back to the top