Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 481c93ff24adb925a97e388e3d96e3ce1bdfe5c0 (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
-----------------------------------------------------------------------------------
-- 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
-----------------------------------------------------------------------------------


$Notice
-- Copied into all files generated by LPG
/./*******************************************************************************
 * 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
 *********************************************************************************/
 
 // This file was generated by LPG
./
$End


$Define
	-- These macros allow the template and header code to be customized by an extending parser.
	$ast_class /.Object./
	$data_class /. Object ./ -- allow anything to be passed between actions
	
	--$additional_interfaces /. , IParserActionTokenProvider, IParser ./
	$additional_interfaces /. ./
	
	$build_action_class /.  ./
	$resolve_action_class /.  ./
	$node_factory_create_expression /.  ./
	
	
	$lexer_class /.  ./
	$action_class /.  ./
	
	
	$UndoResolver /.$Undo action.resolver.undo(); $EndUndo./
	
	$Resolve /. $BeginTrial $resolve.
	./
	$EndResolve /. $EndTrial 
		$UndoResolver
	./ -- undo actions are automatically generated for binding resolution actions
	
	$Builder /. $BeginFinal  $builder.
	./ 
	$EndBuilder /. /*$builder.getASTStack().print();*/ $EndFinal ./

	$Build /. $Action $Builder ./
	$EndBuild /. $EndBuilder $EndAction ./
	
	$resolve /. action.resolver./
	$builder /. action.builder./


-- comment out when using trial/undo
	--$Action /. $BeginAction ./
	--$BeginFinal /. ./
	--$EndFinal /. ./
	--$BeginTrial /. ./
	--$EndTrial /. ./
	--$Undo /. ./
	--$EndUndo /. ./
$End


$Headers
/.
	private $action_class action;	
	
	//public $action_type() {  // constructor
	//}
	
	private void initActions(IASTTranslationUnit tu) {
	    // binding resolution actions need access to IASTName nodes, temporary
	    action = new $action_class();
		action.resolver = new $resolve_action_class(this);
		action.builder  = new $build_action_class($node_factory_create_expression, this, tu);
		action.builder.setTokenMap($sym_class.orderedTerminalSymbols);
		//setParserAction(action);
	}
	
	
	public void addToken(IToken token) {
		token.setKind(mapKind(token.getKind()));
		super.addToken(token);
	}
	
	public void setTokens(List<IToken> tokens) {
		resetTokenStream();
		for(IToken token : tokens) {
			addToken(token);
		}
	}
	
	public IASTCompletionNode parse(IASTTranslationUnit tu) {
		// this has to be done, or... kaboom!
		setStreamLength(getSize());
		initActions(tu);
		
		final int errorRepairCount = -1;  // -1 means full error handling
		parser(null, errorRepairCount); // do the actual parse
		super.resetTokenStream(); // allow tokens to be garbage collected
	
		// the completion node may be null
		IASTCompletionNode compNode = action.builder.getASTCompletionNode();
	
		action = null;
		parserAction = null;
		return compNode;
	}


	public int getKind(int i) {
		int kind = super.getKind(i);
		// lexer feedback hack!
		//if(kind == $sym_class.TK_identifier && action.resolver.isTypedef(getTokenText(i))) {
		//	kind = $sym_class.TK_TypedefName;
		//}
		return kind;
	}
	
./
$End

Back to the top