PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Boo.Lang.Parser/antlr/antlr/ASTFactory.cs

http://github.com/bamboo/boo
C# | 705 lines | 387 code | 59 blank | 259 comment | 79 complexity | e55b8c3f76eb0a327de263cc0646602d MD5 | raw file
Possible License(s): GPL-2.0
  1. using System;
  2. using System.Collections;
  3. using Assembly = System.Reflection.Assembly;
  4. using ArrayList = System.Collections.ArrayList;
  5. using Debug = System.Diagnostics.Debug;
  6. using AST = antlr.collections.AST;
  7. using ASTArray = antlr.collections.impl.ASTArray;
  8. using ANTLRException = antlr.ANTLRException;
  9. namespace antlr
  10. {
  11. /*ANTLR Translator Generator
  12. * Project led by Terence Parr at http://www.jGuru.com
  13. * Software rights: http://www.antlr.org/license.html
  14. *
  15. * $Id:$
  16. */
  17. //
  18. // ANTLR C# Code Generator by Micheal Jordan
  19. // Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
  20. // Anthony Oguntimehin
  21. //
  22. // With many thanks to Eric V. Smith from the ANTLR list.
  23. //
  24. // HISTORY:
  25. //
  26. // 19-Aug-2002 kunle Augmented the basic flexibility of the default ASTFactory with a map
  27. // of TokenID-to-NodeTypeName. It's now a proper GoF-style Factory ;-)
  28. //
  29. /// <summary>
  30. /// AST Support code shared by TreeParser and Parser.
  31. /// </summary>
  32. /// <remarks>
  33. /// <para>
  34. /// We use delegation to share code (and have only one
  35. /// bit of code to maintain) rather than subclassing
  36. /// or superclassing (forces AST support code to be
  37. /// loaded even when you don't want to do AST stuff).
  38. /// </para>
  39. /// <para>
  40. /// Typically, <see cref="setASTNodeType"/> is used to specify the
  41. /// homogeneous type of node to create, but you can override
  42. /// <see cref="create"/> to make heterogeneous nodes etc...
  43. /// </para>
  44. /// </remarks>
  45. public class ASTFactory
  46. {
  47. //---------------------------------------------------------------------
  48. // CONSTRUCTORS
  49. //---------------------------------------------------------------------
  50. /// <summary>
  51. /// Constructs an <c>ASTFactory</c> with the default AST node type of
  52. /// <see cref="antlr.CommonAST"/>.
  53. /// </summary>
  54. public ASTFactory() : this(typeof(antlr.CommonAST))
  55. {
  56. }
  57. /// <summary>
  58. /// Constructs an <c>ASTFactory</c> and use the specified AST node type
  59. /// as the default.
  60. /// </summary>
  61. /// <param name="nodeTypeName">
  62. /// Name of default AST node type for this factory.
  63. /// </param>
  64. public ASTFactory(string nodeTypeName) : this(loadNodeTypeObject(nodeTypeName))
  65. {
  66. }
  67. /// <summary>
  68. /// Constructs an <c>ASTFactory</c> and use the specified AST node type
  69. /// as the default.
  70. /// </summary>
  71. /// <param name="defaultASTNodeType">Node type for this factory.</param>
  72. public ASTFactory(Type defaultASTNodeType)
  73. {
  74. heteroList_ = new FactoryEntry[Token.MIN_USER_TYPE+1];
  75. defaultASTNodeTypeObject_ = defaultASTNodeType;
  76. defaultCreator_ = null;
  77. typename2creator_ = new Hashtable(32, (float) 0.3);
  78. typename2creator_["antlr.CommonAST"] = CommonAST.Creator;
  79. typename2creator_["antlr.CommonASTWithHiddenTokens"] = CommonASTWithHiddenTokens.Creator;
  80. }
  81. //---------------------------------------------------------------------
  82. // DATA MEMBERS
  83. //---------------------------------------------------------------------
  84. /// <summary>
  85. /// Stores the Type of the default AST node class to be used during tree construction.
  86. /// </summary>
  87. protected Type defaultASTNodeTypeObject_;
  88. protected ASTNodeCreator defaultCreator_;
  89. /// <summary>
  90. /// Stores the mapping between custom AST NodeTypes and their NodeTypeName/NodeTypeClass
  91. /// and ASTNodeCreator.
  92. /// </summary>
  93. protected FactoryEntry[] heteroList_;
  94. /// <summary>
  95. /// Stores the mapping between AST node typenames and their token ID.
  96. /// </summary>
  97. protected Hashtable typename2creator_;
  98. //---------------------------------------------------------------------
  99. // FUNCTION MEMBERS
  100. //---------------------------------------------------------------------
  101. /// <summary>
  102. /// Specify an "override" for the <see cref="AST"/> type created for
  103. /// the specified Token type.
  104. /// </summary>
  105. /// <remarks>
  106. /// This method is useful for situations that ANTLR cannot oridinarily deal
  107. /// with (i.e., when you create a token based upon a nonliteral token symbol
  108. /// like #[LT(1)]. This is a runtime value and ANTLR cannot determine the token
  109. /// type (and hence the AST) statically.
  110. /// </remarks>
  111. /// <param name="tokenType">Token type to override.</param>
  112. /// <param name="NodeTypeName">
  113. /// Fully qualified AST typename (or null to specify
  114. /// the factory's default AST type).
  115. /// </param>
  116. public void setTokenTypeASTNodeType(int tokenType, string NodeTypeName)
  117. {
  118. // check validity of arguments...
  119. if( tokenType < Token.MIN_USER_TYPE )
  120. throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + tokenType + "'");
  121. // resize up to and including 'type' and initialize any gaps to default
  122. // factory.
  123. if (tokenType > (heteroList_.Length+1))
  124. setMaxNodeType(tokenType);
  125. // And add new thing..
  126. if (heteroList_[tokenType] == null)
  127. heteroList_[tokenType] = new FactoryEntry(loadNodeTypeObject(NodeTypeName));
  128. else
  129. heteroList_[tokenType].NodeTypeObject = loadNodeTypeObject(NodeTypeName);
  130. }
  131. /// <summary>
  132. /// Register an AST Node Type for a given Token type ID.
  133. /// </summary>
  134. /// <param name="NodeType">The Token type ID.</param>
  135. /// <param name="NodeTypeName">The AST Node Type to register.</param>
  136. [Obsolete("Replaced by setTokenTypeASTNodeType(int, string) since version 2.7.2.6", true)]
  137. public void registerFactory(int NodeType, string NodeTypeName)
  138. {
  139. setTokenTypeASTNodeType(NodeType, NodeTypeName);
  140. }
  141. /// <summary>
  142. /// Register an ASTNodeCreator for a given Token type ID.
  143. /// </summary>
  144. /// <param name="NodeType">The Token type ID.</param>
  145. /// <param name="creator">The creater to register.</param>
  146. public void setTokenTypeASTNodeCreator(int NodeType, ASTNodeCreator creator)
  147. {
  148. // check validity of arguments...
  149. if( NodeType < Token.MIN_USER_TYPE )
  150. throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + NodeType + "'");
  151. // resize up to and including 'type' and initialize any gaps to default
  152. // factory.
  153. if (NodeType > (heteroList_.Length+1))
  154. setMaxNodeType(NodeType);
  155. // And add new thing..
  156. if (heteroList_[NodeType] == null)
  157. heteroList_[NodeType] = new FactoryEntry(creator);
  158. else
  159. heteroList_[NodeType].Creator = creator;
  160. //typename2creator_[NodeType.ToString()] = creator;
  161. typename2creator_[creator.ASTNodeTypeName] = creator;
  162. }
  163. /// <summary>
  164. /// Register an ASTNodeCreator to be used for creating node by default.
  165. /// </summary>
  166. /// <param name="creator">The ASTNodeCreator.</param>
  167. public void setASTNodeCreator(ASTNodeCreator creator)
  168. {
  169. defaultCreator_ = creator;
  170. }
  171. /// <summary>
  172. /// Pre-expands the internal list of TokenTypeID-to-ASTNodeType mappings
  173. /// to the specified size.
  174. /// This is primarily a convenience method that can be used to prevent
  175. /// unnecessary and costly re-org of the mappings list.
  176. /// </summary>
  177. /// <param name="NodeType">Maximum Token Type ID.</param>
  178. public void setMaxNodeType( int NodeType )
  179. {
  180. //Debug.WriteLine(this, "NodeType = " + NodeType + " and NodeList.Length = " + nodeTypeList_.Length);
  181. if (heteroList_ == null)
  182. {
  183. heteroList_ = new FactoryEntry[NodeType+1];
  184. }
  185. else
  186. {
  187. int length = heteroList_.Length;
  188. if ( NodeType > (length + 1) )
  189. {
  190. FactoryEntry[] newList = new FactoryEntry[NodeType+1];
  191. Array.Copy(heteroList_, 0, newList, 0, heteroList_.Length);
  192. heteroList_ = newList;
  193. }
  194. else if ( NodeType < (length + 1) )
  195. {
  196. FactoryEntry[] newList = new FactoryEntry[NodeType+1];
  197. Array.Copy(heteroList_, 0, newList, 0, (NodeType+1));
  198. heteroList_ = newList;
  199. }
  200. }
  201. //Debug.WriteLine(this, "NodeType = " + NodeType + " and NodeList.Length = " + nodeTypeList_.Length);
  202. }
  203. /// <summary>
  204. /// Add a child to the current AST
  205. /// </summary>
  206. /// <param name="currentAST">The AST to add a child to</param>
  207. /// <param name="child">The child AST to be added</param>
  208. public virtual void addASTChild(ASTPair currentAST, AST child)
  209. {
  210. if (child != null)
  211. {
  212. if (currentAST.root == null)
  213. {
  214. // Make new child the current root
  215. currentAST.root = child;
  216. }
  217. else
  218. {
  219. if (currentAST.child == null)
  220. {
  221. // Add new child to current root
  222. currentAST.root.setFirstChild(child);
  223. }
  224. else
  225. {
  226. currentAST.child.setNextSibling(child);
  227. }
  228. }
  229. // Make new child the current child
  230. currentAST.child = child;
  231. currentAST.advanceChildToEnd();
  232. }
  233. }
  234. /// <summary>
  235. /// Creates a new uninitialized AST node. Since a specific AST Node Type
  236. /// wasn't indicated, the new AST node is created using the current default
  237. /// AST Node type - <see cref="defaultASTNodeTypeObject_"/>
  238. /// </summary>
  239. /// <returns>An uninitialized AST node object.</returns>
  240. public virtual AST create()
  241. {
  242. AST newNode;
  243. if (defaultCreator_ == null)
  244. newNode = createFromNodeTypeObject(defaultASTNodeTypeObject_);
  245. else
  246. newNode = defaultCreator_.Create();
  247. return newNode;
  248. }
  249. /// <summary>
  250. /// Creates and initializes a new AST node using the specified Token Type ID.
  251. /// The <see cref="System.Type"/> used for creating this new AST node is
  252. /// determined by the following:
  253. /// <list type="bullet">
  254. /// <item>the current TokenTypeID-to-ASTNodeType mapping (if any) or,</item>
  255. /// <item>the <see cref="defaultASTNodeTypeObject_"/> otherwise</item>
  256. /// </list>
  257. /// </summary>
  258. /// <param name="type">Token type ID to be used to create new AST Node.</param>
  259. /// <returns>An initialized AST node object.</returns>
  260. public virtual AST create(int type)
  261. {
  262. AST newNode = createFromNodeType(type);
  263. newNode.initialize(type, "");
  264. return newNode;
  265. }
  266. /// <summary>
  267. /// Creates and initializes a new AST node using the specified Token Type ID.
  268. /// The <see cref="System.Type"/> used for creating this new AST node is
  269. /// determined by the following:
  270. /// <list type="bullet">
  271. /// <item>the current TokenTypeID-to-ASTNodeType mapping (if any) or,</item>
  272. /// <item>the <see cref="defaultASTNodeTypeObject_"/> otherwise</item>
  273. /// </list>
  274. /// </summary>
  275. /// <param name="type">Token type ID to be used to create new AST Node.</param>
  276. /// <param name="txt">Text for initializing the new AST Node.</param>
  277. /// <returns>An initialized AST node object.</returns>
  278. public virtual AST create(int type, string txt)
  279. {
  280. AST newNode = createFromNodeType(type);
  281. newNode.initialize(type, txt);
  282. return newNode;
  283. }
  284. /// <summary>
  285. /// Creates a new AST node using the specified AST Node Type name. Once created,
  286. /// the new AST node is initialized with the specified Token type ID and string.
  287. /// The <see cref="System.Type"/> used for creating this new AST node is
  288. /// determined solely by <c>ASTNodeTypeName</c>.
  289. /// The AST Node type must have a default/parameterless constructor.
  290. /// </summary>
  291. /// <param name="type">Token type ID to be used to create new AST Node.</param>
  292. /// <param name="txt">Text for initializing the new AST Node.</param>
  293. /// <param name="ASTNodeTypeName">Fully qualified name of the Type to be used for creating the new AST Node.</param>
  294. /// <returns>An initialized AST node object.</returns>
  295. public virtual AST create(int type, string txt, string ASTNodeTypeName)
  296. {
  297. AST newNode = createFromNodeName(ASTNodeTypeName);
  298. newNode.initialize(type, txt);
  299. return newNode;
  300. }
  301. /// <summary>
  302. /// Creates a new AST node using the specified AST Node Type name.
  303. /// </summary>
  304. /// <param name="tok">Token instance to be used to initialize the new AST Node.</param>
  305. /// <param name="ASTNodeTypeName">
  306. /// Fully qualified name of the Type to be used for creating the new AST Node.
  307. /// </param>
  308. /// <returns>A newly created and initialized AST node object.</returns>
  309. /// <remarks>
  310. /// Once created, the new AST node is initialized with the specified Token
  311. /// instance. The <see cref="System.Type"/> used for creating this new AST
  312. /// node is determined solely by <c>ASTNodeTypeName</c>.
  313. /// <para>The AST Node type must have a default/parameterless constructor.</para>
  314. /// </remarks>
  315. public virtual AST create(IToken tok, string ASTNodeTypeName)
  316. {
  317. AST newNode = createFromNodeName(ASTNodeTypeName);
  318. newNode.initialize(tok);
  319. return newNode;
  320. }
  321. /// <summary>
  322. /// Creates and initializes a new AST node using the specified AST Node instance.
  323. /// the new AST node is initialized with the specified Token type ID and string.
  324. /// The <see cref="System.Type"/> used for creating this new AST node is
  325. /// determined solely by <c>aNode</c>.
  326. /// The AST Node type must have a default/parameterless constructor.
  327. /// </summary>
  328. /// <param name="aNode">AST Node instance to be used for creating the new AST Node.</param>
  329. /// <returns>An initialized AST node object.</returns>
  330. public virtual AST create(AST aNode)
  331. {
  332. AST newNode;
  333. if (aNode == null)
  334. newNode = null;
  335. else
  336. {
  337. newNode = createFromAST(aNode);
  338. newNode.initialize(aNode);
  339. }
  340. return newNode;
  341. }
  342. /// <summary>
  343. /// Creates and initializes a new AST node using the specified Token instance.
  344. /// The <see cref="System.Type"/> used for creating this new AST node is
  345. /// determined by the following:
  346. /// <list type="bullet">
  347. /// <item>the current TokenTypeID-to-ASTNodeType mapping (if any) or,</item>
  348. /// <item>the <see cref="defaultASTNodeTypeObject_"/> otherwise</item>
  349. /// </list>
  350. /// </summary>
  351. /// <param name="tok">Token instance to be used to create new AST Node.</param>
  352. /// <returns>An initialized AST node object.</returns>
  353. public virtual AST create(IToken tok)
  354. {
  355. AST newNode;
  356. if (tok == null)
  357. newNode = null;
  358. else
  359. {
  360. newNode = createFromNodeType(tok.Type);
  361. newNode.initialize(tok);
  362. }
  363. return newNode;
  364. }
  365. /// <summary>
  366. /// Returns a copy of the specified AST Node instance. The copy is obtained by
  367. /// using the <see cref="ICloneable"/> method Clone().
  368. /// </summary>
  369. /// <param name="t">AST Node to copy.</param>
  370. /// <returns>An AST Node (or null if <c>t</c> is null).</returns>
  371. public virtual AST dup(AST t)
  372. {
  373. // The Java version is implemented using code like this:
  374. if (t == null)
  375. return null;
  376. AST dup_edNode = createFromAST(t);
  377. dup_edNode.initialize(t);
  378. return dup_edNode;
  379. }
  380. /// <summary>
  381. /// Duplicate AST Node tree rooted at specified AST node and all of it's siblings.
  382. /// </summary>
  383. /// <param name="t">Root of AST Node tree.</param>
  384. /// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
  385. public virtual AST dupList(AST t)
  386. {
  387. AST result = dupTree(t); // if t == null, then result==null
  388. AST nt = result;
  389. while (t != null)
  390. {
  391. // for each sibling of the root
  392. t = t.getNextSibling();
  393. nt.setNextSibling(dupTree(t)); // dup each subtree, building new tree
  394. nt = nt.getNextSibling();
  395. }
  396. return result;
  397. }
  398. /// <summary>
  399. /// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
  400. /// </summary>
  401. /// <param name="t">Root of AST Node tree.</param>
  402. /// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
  403. public virtual AST dupTree(AST t)
  404. {
  405. AST result = dup(t); // make copy of root
  406. // copy all children of root.
  407. if (t != null)
  408. {
  409. result.setFirstChild(dupList(t.getFirstChild()));
  410. }
  411. return result;
  412. }
  413. /// <summary>
  414. /// Make a tree from a list of nodes. The first element in the
  415. /// array is the root. If the root is null, then the tree is
  416. /// a simple list not a tree. Handles null children nodes correctly.
  417. /// For example, build(a, b, null, c) yields tree (a b c). build(null,a,b)
  418. /// yields tree (nil a b).
  419. /// </summary>
  420. /// <param name="nodes">List of Nodes.</param>
  421. /// <returns>AST Node tree.</returns>
  422. public virtual AST make(params AST[] nodes)
  423. {
  424. if (nodes == null || nodes.Length == 0)
  425. return null;
  426. AST root = nodes[0];
  427. AST tail = null;
  428. if (root != null)
  429. {
  430. root.setFirstChild(null); // don't leave any old pointers set
  431. }
  432. // link in children;
  433. for (int i = 1; i < nodes.Length; i++)
  434. {
  435. if (nodes[i] == null)
  436. continue;
  437. // ignore null nodes
  438. if (root == null)
  439. {
  440. // Set the root and set it up for a flat list
  441. root = (tail = nodes[i]);
  442. }
  443. else if (tail == null)
  444. {
  445. root.setFirstChild(nodes[i]);
  446. tail = root.getFirstChild();
  447. }
  448. else
  449. {
  450. tail.setNextSibling(nodes[i]);
  451. tail = tail.getNextSibling();
  452. }
  453. // Chase tail to last sibling
  454. while (tail.getNextSibling() != null)
  455. {
  456. tail = tail.getNextSibling();
  457. }
  458. }
  459. return root;
  460. }
  461. /// <summary>
  462. /// Make a tree from a list of nodes, where the nodes are contained
  463. /// in an ASTArray object.
  464. /// </summary>
  465. /// <param name="nodes">List of Nodes.</param>
  466. /// <returns>AST Node tree.</returns>
  467. public virtual AST make(ASTArray nodes)
  468. {
  469. return make(nodes.array);
  470. }
  471. /// <summary>
  472. /// Make an AST the root of current AST.
  473. /// </summary>
  474. /// <param name="currentAST"></param>
  475. /// <param name="root"></param>
  476. public virtual void makeASTRoot(ASTPair currentAST, AST root)
  477. {
  478. if (root != null)
  479. {
  480. // Add the current root as a child of new root
  481. root.addChild(currentAST.root);
  482. // The new current child is the last sibling of the old root
  483. currentAST.child = currentAST.root;
  484. currentAST.advanceChildToEnd();
  485. // Set the new root
  486. currentAST.root = root;
  487. }
  488. }
  489. /// <summary>
  490. /// Sets the global default AST Node Type for this ASTFactory instance.
  491. /// This method also attempts to load the <see cref="System.Type"/> instance
  492. /// for the specified typename.
  493. /// </summary>
  494. /// <param name="t">Fully qualified AST Node Type name.</param>
  495. public virtual void setASTNodeType(string t)
  496. {
  497. if (defaultCreator_ != null)
  498. {
  499. if (t != defaultCreator_.ASTNodeTypeName)
  500. {
  501. defaultCreator_ = null;
  502. }
  503. }
  504. defaultASTNodeTypeObject_ = loadNodeTypeObject(t);
  505. }
  506. /// <summary>
  507. /// To change where error messages go, can subclass/override this method
  508. /// and then setASTFactory in Parser and TreeParser. This method removes
  509. /// a prior dependency on class antlr.Tool.
  510. /// </summary>
  511. /// <param name="e"></param>
  512. public virtual void error(string e)
  513. {
  514. Console.Error.WriteLine(e);
  515. }
  516. //---------------------------------------------------------------------
  517. // PRIVATE FUNCTION MEMBERS
  518. //---------------------------------------------------------------------
  519. private static Type loadNodeTypeObject(string nodeTypeName)
  520. {
  521. Type nodeTypeObject = null;
  522. bool typeCreated = false;
  523. if (nodeTypeName != null)
  524. {
  525. foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
  526. {
  527. try
  528. {
  529. nodeTypeObject = assem.GetType(nodeTypeName, false);
  530. if (nodeTypeObject != null)
  531. {
  532. typeCreated = true;
  533. break;
  534. }
  535. }
  536. catch
  537. {
  538. typeCreated = false;
  539. }
  540. }
  541. }
  542. if (!typeCreated)
  543. {
  544. throw new TypeLoadException("Unable to load AST Node Type: '" + nodeTypeName + "'");
  545. }
  546. return nodeTypeObject;
  547. }
  548. private AST createFromAST(AST node)
  549. {
  550. AST newNode = null;
  551. Type nodeAsTypeObj = node.GetType();
  552. ASTNodeCreator creator = (ASTNodeCreator) typename2creator_[nodeAsTypeObj.FullName];
  553. if (creator != null)
  554. {
  555. newNode = creator.Create();
  556. if (newNode == null)
  557. {
  558. throw new ArgumentException("Unable to create AST Node Type: '" + nodeAsTypeObj.FullName + "'");
  559. }
  560. }
  561. else
  562. {
  563. newNode = createFromNodeTypeObject(nodeAsTypeObj);
  564. }
  565. return newNode;
  566. }
  567. private AST createFromNodeName(string nodeTypeName)
  568. {
  569. AST newNode = null;
  570. ASTNodeCreator creator = (ASTNodeCreator) typename2creator_[nodeTypeName];
  571. if (creator != null)
  572. {
  573. newNode = creator.Create();
  574. if (newNode == null)
  575. {
  576. throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeName + "'");
  577. }
  578. }
  579. else
  580. {
  581. newNode = createFromNodeTypeObject( loadNodeTypeObject(nodeTypeName) );
  582. }
  583. return newNode;
  584. }
  585. private AST createFromNodeType(int nodeTypeIndex)
  586. {
  587. Debug.Assert((nodeTypeIndex >= 0) && (nodeTypeIndex <= heteroList_.Length), "Invalid AST node type!");
  588. AST newNode = null;
  589. FactoryEntry entry = heteroList_[nodeTypeIndex];
  590. if ((entry != null) && (entry.Creator != null))
  591. {
  592. newNode = entry.Creator.Create();
  593. }
  594. else
  595. {
  596. if ((entry == null) || (entry.NodeTypeObject == null))
  597. {
  598. if (defaultCreator_ == null)
  599. {
  600. newNode = createFromNodeTypeObject(defaultASTNodeTypeObject_);
  601. }
  602. else
  603. newNode = defaultCreator_.Create();
  604. }
  605. else
  606. newNode = createFromNodeTypeObject( entry.NodeTypeObject );
  607. }
  608. return newNode;
  609. }
  610. private AST createFromNodeTypeObject(Type nodeTypeObject)
  611. {
  612. AST newNode = null;
  613. try
  614. {
  615. newNode = (AST) Activator.CreateInstance(nodeTypeObject);
  616. if (newNode == null)
  617. {
  618. throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeObject.FullName + "'");
  619. }
  620. }
  621. catch(Exception ex)
  622. {
  623. throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeObject.FullName + "'", ex);
  624. }
  625. return newNode;
  626. }
  627. protected class FactoryEntry
  628. {
  629. public FactoryEntry(Type typeObj, ASTNodeCreator creator)
  630. {
  631. NodeTypeObject = typeObj;
  632. Creator = creator;
  633. }
  634. public FactoryEntry(Type typeObj)
  635. {
  636. NodeTypeObject = typeObj;
  637. }
  638. public FactoryEntry(ASTNodeCreator creator)
  639. {
  640. Creator = creator;
  641. }
  642. public Type NodeTypeObject;
  643. public ASTNodeCreator Creator;
  644. }
  645. }
  646. }