nescobjecttreebuilder.java

来自「plugin for eclipse」· Java 代码 · 共 2,529 行 · 第 1/5 页

JAVA
2,529
字号
// $ANTLR : "NesCObjectTreeBuilder.g" -> "NesCObjectTreeBuilder.java"$

package isis.anp.nesc;

import antlr.TreeParser;
import antlr.Token;
import antlr.collections.AST;
import antlr.RecognitionException;
import antlr.ANTLRException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.collections.impl.BitSet;
import antlr.ASTPair;
import antlr.collections.impl.ASTArray;

import isis.anp.common.CodeLocation;
import isis.anp.common.ParserMessage;
import isis.anp.common.TNode;
import isis.anp.nesc.common.NesCObjectTreeBuilderContext;
import isis.anp.nesc.ot.AbstractDeclarator;
import isis.anp.nesc.ot.ArrayConstructor;
import isis.anp.nesc.ot.AsmExpr;
import isis.anp.nesc.ot.Attribute;
import isis.anp.nesc.ot.BreakStatement;
import isis.anp.nesc.ot.CaseStatement;
import isis.anp.nesc.ot.ComponentAlias;
import isis.anp.nesc.ot.CompoundStatement;
import isis.anp.nesc.ot.Configuration;
import isis.anp.nesc.ot.ConfigurationImplementation;
import isis.anp.nesc.ot.Connection;
import isis.anp.nesc.ot.ContinueStatement;
import isis.anp.nesc.ot.Declaration;
import isis.anp.nesc.ot.Declarator;
import isis.anp.nesc.ot.DefaultCaseStatement;
import isis.anp.nesc.ot.DirectionSpecifier;
import isis.anp.nesc.ot.DoStatement;
import isis.anp.nesc.ot.EnumSpecifier;
import isis.anp.nesc.ot.Enumerator;
import isis.anp.nesc.ot.Expression;
import isis.anp.nesc.ot.ExpressionStatement;
import isis.anp.nesc.ot.ForStatement;
import isis.anp.nesc.ot.FunctionDeclaration;
import isis.anp.nesc.ot.FunctionDefinition;
import isis.anp.nesc.ot.FunctionPort;
import isis.anp.nesc.ot.GotoStatement;
import isis.anp.nesc.ot.IfStatement;
import isis.anp.nesc.ot.Interface;
import isis.anp.nesc.ot.InterfacePort;
import isis.anp.nesc.ot.LabeledStatement;
import isis.anp.nesc.ot.Module;
import isis.anp.nesc.ot.ModuleImplementation;
import isis.anp.nesc.ot.NameConflictException;
import isis.anp.nesc.ot.NesCComponentFile;
import isis.anp.nesc.ot.NesCConfigurationFile;
import isis.anp.nesc.ot.NesCFile;
import isis.anp.nesc.ot.NesCIncludeFile;
import isis.anp.nesc.ot.NesCInterfaceFile;
import isis.anp.nesc.ot.NesCModuleFile;
import isis.anp.nesc.ot.ParameterDeclaration;
import isis.anp.nesc.ot.ParameterTypeList;
import isis.anp.nesc.ot.PointerGroup;
import isis.anp.nesc.ot.Port;
import isis.anp.nesc.ot.ReturnStatement;
import isis.anp.nesc.ot.Statement;
import isis.anp.nesc.ot.StorageClassSpecifier;
import isis.anp.nesc.ot.StructOrUnionSpecifier;
import isis.anp.nesc.ot.StructSpecifier;
import isis.anp.nesc.ot.SwitchStatement;
import isis.anp.nesc.ot.SynchronySpecifier;
import isis.anp.nesc.ot.TypeQualifier;
import isis.anp.nesc.ot.TypeResolutionException;
import isis.anp.nesc.ot.TypeSpecifier;
import isis.anp.nesc.ot.TypedefName;
import isis.anp.nesc.ot.TypelessDeclaration;
import isis.anp.nesc.ot.UnionSpecifier;
import isis.anp.nesc.ot.WhileStatement;
import isis.anp.nesc.ot.scope.Scope;
import isis.anp.nesc.ot.types.FunctionType;
import isis.anp.nesc.ot.types.TypeBuilder;
import isis.commons.fs.CanonicalPath;

import java.util.ArrayList;
import java.util.List;

import antlr.MismatchedTokenException;
import antlr.NoViableAltException;
import antlr.RecognitionException;
import antlr.collections.AST;
import antlr.collections.impl.BitSet;


public class NesCObjectTreeBuilder extends antlr.TreeParser       implements NesCObjectTreeBuilderTokenTypes
 {

		// We need a few member variables to share information between rules. (Obviously, this could have been done
		// with parameter passing, however, using globals is the easy way)
		int paramCount = 0;			// number of params in a param list

		NesCObjectTreeBuilderContext ctx = null;		// the current project
		
		public void setContext(NesCObjectTreeBuilderContext ctx) {
			this.ctx = ctx;
		}

        int traceDepth = 0;

        public void reportError(TypeResolutionException ex) {
          if ( ex != null)   {
          		ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(ex.node), ex));
          }
        }

        public void reportError(NameConflictException ex) {
          if ( ex != null)   {
          		ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(ex.getNode()), ex));
          }
        }

        public void reportError(RecognitionException ex) {
          if ( ex != null)   {
          		ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(ex.getFilename(), ex.getLine(), ex.getColumn()), ex));
          }
        }
        
	     public void reportError(NoViableAltException ex) {
          if ( ex != null)   {
          		ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(ex.getFilename(), ex.getLine(), ex.getColumn()), ex));
          }
        }
        
        public void reportError(MismatchedTokenException ex) {
          if ( ex != null)   {
          		ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(ex.getFilename(), ex.getLine(), ex.getColumn()), ex));
          }
        }
        
        public void reportError(String s) {        	
          	ctx.addMsg(new ParserMessage(ParserMessage.ERROR, s, null, null));
        }
        

        protected void match(AST t, int ttype) throws MismatchedTokenException {
                //System.out.println("match("+ttype+"); cursor is "+t);
                super.match(t, ttype);
        }
        public void match(AST t, BitSet b) throws MismatchedTokenException {
                //System.out.println("match("+b+"); cursor is "+t);
                super.match(t, b);
        }
        protected void matchNot(AST t, int ttype) throws MismatchedTokenException {
                //System.out.println("matchNot("+ttype+"); cursor is "+t);
                super.matchNot(t, ttype);
                }
        public void traceIn(String rname, AST t) {
          traceDepth += 1;
          for (int x=0; x<traceDepth; x++) System.out.print(" ");
          super.traceIn(rname, t);   
        }
        public void traceOut(String rname, AST t) {
          for (int x=0; x<traceDepth; x++) System.out.print(" ");
          super.traceOut(rname, t);
          traceDepth -= 1;
        }

public NesCObjectTreeBuilder() {
	tokenNames = _tokenNames;
}

	public final NesCFile  translationUnit(AST _t,
		CanonicalPath cp
	) throws RecognitionException {
		NesCFile nesCFileObj;
		
		TNode translationUnit_AST_in = (_t == ASTNULL) ? null : (TNode)_t;
		
																	nesCFileObj = null;
																
		
		if (_t==null) _t=ASTNULL;
		switch ( _t.getType()) {
		case NIncludeFile:
		{
			nesCFileObj=includeFile(_t,cp);
			_t = _retTree;
			break;
		}
		case NModuleFile:
		{
			nesCFileObj=moduleFile(_t,cp);
			_t = _retTree;
			break;
		}
		case NInterfaceFile:
		{
			nesCFileObj=interfaceFile(_t,cp);
			_t = _retTree;
			break;
		}
		case NConfigurationFile:
		{
			nesCFileObj=configurationFile(_t,cp);
			_t = _retTree;
			break;
		}
		default:
		{
			throw new NoViableAltException(_t);
		}
		}
		_retTree = _t;
		return nesCFileObj;
	}
	
	public final NesCIncludeFile  includeFile(AST _t,
		CanonicalPath cp
	) throws RecognitionException {
		NesCIncludeFile includeFileObj;
		
		TNode includeFile_AST_in = (_t == ASTNULL) ? null : (TNode)_t;
		TNode n = null;
			includeFileObj = null;
		
		try {      // for error handling
			AST __t648 = _t;
			n = _t==ASTNULL ? null :(TNode)_t;
			match(_t,NIncludeFile);
			_t = _t.getFirstChild();
			if ( inputState.guessing==0 ) {
				
																			includeFileObj = new NesCIncludeFile();
																			includeFileObj.setDefNode(n);
																			ctx.addProcessedObjectTree(cp,includeFileObj);															
																		
			}
			{
			if (_t==null) _t=ASTNULL;
			switch ( _t.getType()) {
			case LITERAL_asm:
			case SEMI:
			case NDeclaration:
			case NFunctionDef:
			case NTypeMissing:
			case NText:
			{
				externalList(_t,includeFileObj);
				_t = _retTree;
				break;
			}
			case 3:
			{
				break;
			}
			default:
			{
				throw new NoViableAltException(_t);
			}
			}
			}
			_t = __t648;
			_t = _t.getNextSibling();
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return includeFileObj;
	}
	
	public final NesCModuleFile  moduleFile(AST _t,
		CanonicalPath cp
	) throws RecognitionException {
		NesCModuleFile moduleFileObj;
		
		TNode moduleFile_AST_in = (_t == ASTNULL) ? null : (TNode)_t;
		TNode n = null;
			moduleFileObj = null; 
																	Module moduleObj = null;
																	List includeFileObjList = null;
																
		
		try {      // for error handling
			AST __t682 = _t;
			n = _t==ASTNULL ? null :(TNode)_t;
			match(_t,NModuleFile);
			_t = _t.getFirstChild();
			if ( inputState.guessing==0 ) {
					moduleFileObj = new NesCModuleFile();
																			moduleFileObj.setDefNode(n);
																			ctx.addProcessedObjectTree(cp, moduleFileObj);
																		
			}
			{
			_loop684:
			do {
				if (_t==null) _t=ASTNULL;
				if ((_t.getType()==NIncludes)) {
					includeFileObjList=includes(_t);
					_t = _retTree;
					if ( inputState.guessing==0 ) {
							moduleFileObj.addIncludeFiles(includeFileObjList);
					}
				}
				else {
					break _loop684;
				}
				
			} while (true);
			}
			moduleObj=module(_t);
			_t = _retTree;
			if ( inputState.guessing==0 ) {
					moduleFileObj.setModule(moduleObj);
			}
			_t = __t682;
			_t = _t.getNextSibling();
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return moduleFileObj;
	}
	
	public final NesCInterfaceFile  interfaceFile(AST _t,
		CanonicalPath cp
	) throws RecognitionException {
		NesCInterfaceFile interfaceFileObj;
		
		TNode interfaceFile_AST_in = (_t == ASTNULL) ? null : (TNode)_t;
		TNode n = null;
			interfaceFileObj = null;
																	List includeFileObjList = null;
																	Interface interfaceObj = null;
																
		
		try {      // for error handling
			AST __t651 = _t;
			n = _t==ASTNULL ? null :(TNode)_t;
			match(_t,NInterfaceFile);
			_t = _t.getFirstChild();
			if ( inputState.guessing==0 ) {
					interfaceFileObj = new NesCInterfaceFile();
																			interfaceFileObj.setDefNode(n);
																			ctx.addProcessedObjectTree(cp, interfaceFileObj);															
																			
																		
			}
			{
			_loop653:
			do {
				if (_t==null) _t=ASTNULL;
				if ((_t.getType()==NIncludes)) {
					includeFileObjList=includes(_t);
					_t = _retTree;
					if ( inputState.guessing==0 ) {
							interfaceFileObj.addIncludeFiles(includeFileObjList);
					}
				}
				else {
					break _loop653;
				}
				
			} while (true);
			}
			interfaceObj=interfaceDeclaration(_t);
			_t = _retTree;
			if ( inputState.guessing==0 ) {
					interfaceFileObj.setInterface(interfaceObj);
			}
			_t = __t651;
			_t = _t.getNextSibling();
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return interfaceFileObj;
	}
	
	public final NesCConfigurationFile  configurationFile(AST _t,
		CanonicalPath cp
	) throws RecognitionException {
		NesCConfigurationFile configFileObj;
		
		TNode configurationFile_AST_in = (_t == ASTNULL) ? null : (TNode)_t;
		TNode n = null;
			configFileObj = null; 
																	Configuration configObj = null;
																	List includeFileObjList = null;
																
		
		try {      // for error handling
			AST __t678 = _t;
			n = _t==ASTNULL ? null :(TNode)_t;
			match(_t,NConfigurationFile);
			_t = _t.getFirstChild();
			if ( inputState.guessing==0 ) {
					configFileObj = new NesCConfigurationFile();
																			configFileObj.setDefNode(n);
																			ctx.addProcessedObjectTree(cp, configFileObj);															
																			
																		
			}
			{
			_loop680:
			do {
				if (_t==null) _t=ASTNULL;
				if ((_t.getType()==NIncludes)) {
					includeFileObjList=includes(_t);
					_t = _retTree;
					if ( inputState.guessing==0 ) {
							configFileObj.addIncludeFiles(includeFileObjList);
					}
				}
				else {
					break _loop680;
				}
				
			} while (true);
			}
			configObj=configuration(_t,configFileObj);
			_t = _retTree;
			_t = __t678;
			_t = _t.getNextSibling();
		}
		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				if (_t!=null) {_t = _t.getNextSibling();}
			} else {
			  throw ex;
			}
		}
		_retTree = _t;
		return configFileObj;
	}
	
	public final void externalList(AST _t,
		NesCIncludeFile includeFileObj
	) throws RecognitionException {
		
		TNode externalList_AST_in = (_t == ASTNULL) ? null : (TNode)_t;
		TNode s = null;
		TNode tn = null;
		
																	List declListObj = null;
																	Declaration declObj = null;
																	AsmExpr asmExprObj = null;
																	TypelessDeclaration tldObj = null;												
																
		
		try {      // for error handling
			{
			int _cnt736=0;
			_loop736:
			do {
				if (_t==null) _t=ASTNULL;
				switch ( _t.getType()) {
				case NDeclaration:
				{
					declListObj=declaration(_t);
					_t = _retTree;
					if ( inputState.guessing==0 ) {
							includeFileObj.addExternal(declListObj);
					}
					break;
				}
				case NFunctionDef:
				{
					declObj=functionDef(_t);
					_t = _retTree;
					if ( inputState.guessing==0 ) {
							includeFileObj.addExternal(declObj);
					}
					break;
				}
				case LITERAL_asm:
				{
					asmExprObj=asm_expr(_t);
					_t = _retTree;
					if ( inputState.guessing==0 ) {
							includeFileObj.addExternal(asmExprObj);
					}
					break;
				}
				case SEMI:
				{
					s = (TNode)_t;
					match(_t,SEMI);
					_t = _t.getNextSibling();

⌨️ 快捷键说明

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