Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: be564321093d52235add70c8040539d26f6b2104 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*******************************************************************************
 * Copyright (c) 2006, 2008 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser;


import lpg.lpgjavaruntime.PrsStream;

/**
 * The CPreprocessor from the CDT core returns tokens that 
 * are of the type org.eclipse.cdt.core.parser.IToken,
 * however LPG wants the tokens to be of the type lpg.lpgjavaruntime.IToken.
 * 
 * So these adapter objects are used to wrap the tokens returned
 * by CPreprocessor so that they can be used with LPG.
 * 
 * @author Mike Kucera
 */
public class LPGTokenAdapter implements lpg.lpgjavaruntime.IToken {
	
	/** The token object that is being wrapped */
	private final org.eclipse.cdt.core.parser.IToken token;
	
	
	private int tokenIndex;
	private int adjunctIndex;
	
	private int kind;
	
	public LPGTokenAdapter(org.eclipse.cdt.core.parser.IToken token, int parserKind) {
		this.token = token;
		this.kind = parserKind;
	}

	public org.eclipse.cdt.core.parser.IToken getWrappedToken() {
		return token;
	}
	
	@Override
	public int getAdjunctIndex() {
		return adjunctIndex;
	}

	@Override
	public int getColumn() {
		return 0;
	}

	@Override
	public int getEndColumn() {
		return 0;
	}

	@Override
	public int getEndLine() {
		return 0;
	}

	@Override
	public int getEndOffset() {
		return token.getEndOffset();
	}

	@Override
	public lpg.lpgjavaruntime.IToken[] getFollowingAdjuncts() {
		return null;
	}

	@Override
	public int getKind() {
		return kind;
	}

	@Override
	public int getLine() {
		return 0;
	}

	@Override
	public lpg.lpgjavaruntime.IToken[] getPrecedingAdjuncts() {
		return null;
	}

	@Override
	public PrsStream getPrsStream() {
		return null;
	}

	@Override
	public int getStartOffset() {
		return token.getOffset();
	}

	@Override
	public int getTokenIndex() {
		return tokenIndex;
	}

	@Override
	@Deprecated
	public String getValue(@SuppressWarnings("unused") char[] arg0) {
		return toString();
	}

	@Override
	public void setAdjunctIndex(int adjunctIndex) {
		this.adjunctIndex = adjunctIndex;
	}

	@Override
	public void setEndOffset(@SuppressWarnings("unused") int arg0) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void setKind(int kind) {
		this.kind = kind;
	}

	@Override
	public void setStartOffset(@SuppressWarnings("unused") int arg0) {
		throw new UnsupportedOperationException();

	}

	@Override
	public void setTokenIndex(int tokenIndex) {
		this.tokenIndex = tokenIndex;
	}

	@Override 
	public String toString() {
		return token.toString();
	}
	
}

Back to the top