nescobjecttreebuildercontext.java

来自「plugin for eclipse」· Java 代码 · 共 67 行

JAVA
67
字号
/*
 * Created on May 9, 2005
 *
 */
package isis.anp.nesc.common;

import isis.anp.common.CodeLocation;
import isis.anp.common.ObjectTreeBuilderContext;
import isis.anp.common.ParserConfiguration;
import isis.anp.common.ParserContext;
import isis.anp.common.ParserMessage;
import isis.anp.common.TNode;
import isis.anp.nesc.NesCObjectTreeBuilder;
import isis.anp.nesc.ot.NesCFile;
import isis.commons.fs.CanonicalPath;
import antlr.RecognitionException;
import antlr.collections.AST;

/**
 * @author sallai NesC Object tree builder context.
 */
public class NesCObjectTreeBuilderContext extends ObjectTreeBuilderContext {

	/**
	 * Create a new nesC object tree builder.
	 * 
	 * @param parserConfig
	 *            the parser configuration
	 * @param messageContainer
	 *            message container where the parser messages will be put.
	 */
	public NesCObjectTreeBuilderContext(ParserConfiguration parserConfig) {
		super(parserConfig);
		ParserContext parserCtx = new NesCParserContext(parserConfig);
		parserCtx.setMessageContainerStack(this.getMessageContainerStack());
		this.setParserCtx(parserCtx);
	}

	/**
	 * Parses a file and generates an object tree.
	 * 
	 * @param cp
	 *            the canonical path of the file to parse (relative to the
	 *            search path list)
	 * @throws ParserMessage 
	 */
	public NesCFile parseFile(CanonicalPath cp) throws ParserMessage {

		// get the file's AST from the parser
		AST ast = getParserCtx().getAST(cp);

		// create a new OT builder
		NesCObjectTreeBuilder otb = new NesCObjectTreeBuilder();
		otb.setContext(this);
		otb.setASTNodeClass(TNode.class.getName());

		// build OT from AST
		System.out.println("Building OT for " + cp.getText());

		try {
			return otb.translationUnit(ast, cp);
		} catch (RecognitionException e) {
			throw new ParserMessage(ParserMessage.ERROR, e.getMessage(), new CodeLocation(e.getFilename(), e.getLine(), e.getColumn()), e);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?