Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d78e77b5e743188e51d45b1f167cd694c77255b6 (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
/*******************************************************************************
 * Copyright (c) 2007 Wind River Systems, Inc. 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:
 *    Markus Schorn - initial API and implementation
 *******************************************************************************/ 
package org.eclipse.cdt.internal.core.parser.scanner;

class TokenList {
	private Token fFirst;
	private Token fLast;

	final Token removeFirst() {
		final Token first= fFirst;
		if (first == fLast) {
			fFirst= fLast= null;
			return first;
		}
		else {
			fFirst= (Token) first.getNext();
			return first;
		}
	}

	final public void append(Token t) {
		if (fFirst == null) {
			fFirst= fLast= t;
		}
		else {
			fLast.setNext(t);
			fLast= t;
		}
		t.setNext(null);
	}
	
	final public void prepend(TokenList prepend) {
		final Token first= prepend.fFirst;
		if (first != null) {
			final Token last= prepend.fLast;
			last.setNext(fFirst);
			fFirst= first;
			if (fLast == null) {
				fLast= last;
			}
		}
	}
	
	final public TokenList cloneTokens() {
		TokenList result= new TokenList();
		for (Token t= fFirst; t != null; t= (Token) t.getNext()) {
			if (t.getType() != CPreprocessor.tSCOPE_MARKER) {
				result.append((Token) t.clone());
			}
		}
		return result;
	}

	final public Token first() {
		return fFirst;
	}

	final void removeBehind(Token l) {
		if (l == null) {
			Token t= fFirst;
			if (t != null) {
				t= (Token) t.getNext();
				fFirst= t;
				if (t == null) {
					fLast= null;
				}
			}
		}
		else {
			final Token r= (Token) l.getNext();
			if (r != null) {
				l.setNext(r.getNext());
				if (r == fLast) {
					fLast= l;
				}
			}
		}
	}

	void cutAfter(Token l) {
		if (l == null) {
			fFirst= fLast= null;
		}
		else {
			l.setNext(null);
			fLast= l;
		}
	}
}

Back to the top