private AST createFromNodeType(int nodeTypeIndex) { Debug.Assert((nodeTypeIndex >= 0) && (nodeTypeIndex <= nodeTypeObjectList_.Length), "Invalid AST node type!"); AST newNode = null; ASTNodeCreator creator = (ASTNodeCreator)typename2creator_[nodeTypeIndex.ToString()]; if (creator != null) { newNode = creator.Create(); } else { Type nodeTypeObject = nodeTypeObjectList_[nodeTypeIndex]; if (nodeTypeObject == null) { if (defaultCreator_ == null) { newNode = createFromNodeTypeObject(defaultASTNodeTypeObject_); } else { newNode = defaultCreator_.Create(); } } else { newNode = createFromNodeTypeObject(nodeTypeObject); } } return(newNode); }
/// <summary> /// Register an ASTNodeCreator for a given Token type ID. /// </summary> /// <param name="NodeType">The Token type ID.</param> /// <param name="creator">The creater to register.</param> public void setTokenTypeASTNodeCreator(int NodeType, ASTNodeCreator creator) { // check validity of arguments... if (NodeType < Token.MIN_USER_TYPE) { throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + NodeType + "'"); } // resize up to and including 'type' and initialize any gaps to default // factory. if (NodeType > (heteroList_.Length + 1)) { setMaxNodeType(NodeType); } // And add new thing.. if (heteroList_[NodeType] == null) { heteroList_[NodeType] = new FactoryEntry(creator); } else { heteroList_[NodeType].Creator = creator; } //typename2creator_[NodeType.ToString()] = creator; typename2creator_[creator.ASTNodeTypeName] = creator; }
/// <summary> /// Sets the global default AST Node Type for this ASTFactory instance. /// This method also attempts to load the <see cref="System.Type"/> instance /// for the specified typename. /// </summary> /// <param name="t">Fully qualified AST Node Type name.</param> public virtual void setASTNodeType(string t) { if (defaultCreator_ != null) { if (t != defaultCreator_.ASTNodeTypeName) { defaultCreator_ = null; } } defaultASTNodeTypeObject_ = loadNodeTypeObject(t); }
private AST createFromNodeName(string nodeTypeName) { AST newNode = null; ASTNodeCreator creator = (ASTNodeCreator)typename2creator_[nodeTypeName]; if (creator != null) { newNode = creator.Create(); if (newNode == null) { throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeName + "'"); } } else { newNode = createFromNodeTypeObject(loadNodeTypeObject(nodeTypeName)); } return(newNode); }
private AST createFromAST(AST node) { AST newNode = null; Type nodeAsTypeObj = node.GetType(); ASTNodeCreator creator = (ASTNodeCreator)typename2creator_[nodeAsTypeObj.FullName]; if (creator != null) { newNode = creator.Create(); if (newNode == null) { throw new ArgumentException("Unable to create AST Node Type: '" + nodeAsTypeObj.FullName + "'"); } } else { newNode = createFromNodeTypeObject(nodeAsTypeObj); } return(newNode); }
public FactoryEntry(ASTNodeCreator creator) { Creator = creator; }
public FactoryEntry(Type typeObj, ASTNodeCreator creator) { NodeTypeObject = typeObj; Creator = creator; }
/// <summary> /// Register an ASTNodeCreator to be used for creating node by default. /// </summary> /// <param name="creator">The ASTNodeCreator.</param> public void setASTNodeCreator(ASTNodeCreator creator) { defaultCreator_ = creator; }
/// <summary> /// Register an ASTNodeCreator for a given Token type ID. /// </summary> /// <param name="NodeType">The Token type ID.</param> /// <param name="creator">The creater to register.</param> public void setTokenTypeASTNodeCreator(int NodeType, ASTNodeCreator creator) { // check validity of arguments... if( NodeType < Token.MIN_USER_TYPE ) throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + NodeType + "'"); // resize up to and including 'type' and initialize any gaps to default // factory. if (NodeType > (heteroList_.Length+1)) setMaxNodeType(NodeType); // And add new thing.. if (heteroList_[NodeType] == null) heteroList_[NodeType] = new FactoryEntry(creator); else heteroList_[NodeType].Creator = creator; //typename2creator_[NodeType.ToString()] = creator; typename2creator_[creator.ASTNodeTypeName] = creator; }
/// <summary> /// Register an ASTNodeCreator for a given Token type ID. /// </summary> /// <param name="NodeType">The Token type ID.</param> /// <param name="NodeTypeName">The AST Node Type to register.</param> public void setTokenTypeASTNodeCreator(int NodeType, ASTNodeCreator creator) { typename2creator_[NodeType.ToString()] = creator; typename2creator_[creator.ASTNodeTypeName] = creator; }
/// <summary> /// Constructs an <c>ASTFactory</c> and use the specified AST node type /// as the default. /// </summary> /// <param name="nodeTypeName"> /// Name of default AST node type for this factory. /// </param> public ASTFactory(string nodeTypeName) { heteroList_ = new FactoryEntry[Token.MIN_USER_TYPE+1]; defaultASTNodeTypeObject_ = loadNodeTypeObject(nodeTypeName); defaultCreator_ = null; typename2creator_ = new Hashtable(32, (float) 0.3); typename2creator_["antlr.CommonAST"] = CommonAST.Creator; typename2creator_["antlr.CommonASTWithHiddenTokens"] = CommonASTWithHiddenTokens.Creator; }