nodekinds.nim 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #
  2. #
  3. # The Nim Compiler
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## NodeKind enum.
  10. type
  11. TNodeKind* = enum # order is extremely important, because ranges are used
  12. # to check whether a node belongs to a certain class
  13. nkNone, # unknown node kind: indicates an error
  14. # Expressions:
  15. # Atoms:
  16. nkEmpty, # the node is empty
  17. nkIdent, # node is an identifier
  18. nkSym, # node is a symbol
  19. nkType, # node is used for its typ field
  20. nkCharLit, # a character literal ''
  21. nkIntLit, # an integer literal
  22. nkInt8Lit,
  23. nkInt16Lit,
  24. nkInt32Lit,
  25. nkInt64Lit,
  26. nkUIntLit, # an unsigned integer literal
  27. nkUInt8Lit,
  28. nkUInt16Lit,
  29. nkUInt32Lit,
  30. nkUInt64Lit,
  31. nkFloatLit, # a floating point literal
  32. nkFloat32Lit,
  33. nkFloat64Lit,
  34. nkFloat128Lit,
  35. nkStrLit, # a string literal ""
  36. nkRStrLit, # a raw string literal r""
  37. nkTripleStrLit, # a triple string literal """
  38. nkNilLit, # the nil literal
  39. # end of atoms
  40. nkComesFrom, # "comes from" template/macro information for
  41. # better stack trace generation
  42. nkDotCall, # used to temporarily flag a nkCall node;
  43. # this is used
  44. # for transforming ``s.len`` to ``len(s)``
  45. nkCommand, # a call like ``p 2, 4`` without parenthesis
  46. nkCall, # a call like p(x, y) or an operation like +(a, b)
  47. nkCallStrLit, # a call with a string literal
  48. # x"abc" has two sons: nkIdent, nkRStrLit
  49. # x"""abc""" has two sons: nkIdent, nkTripleStrLit
  50. nkInfix, # a call like (a + b)
  51. nkPrefix, # a call like !a
  52. nkPostfix, # something like a! (also used for visibility)
  53. nkHiddenCallConv, # an implicit type conversion via a type converter
  54. nkExprEqExpr, # a named parameter with equals: ''expr = expr''
  55. nkExprColonExpr, # a named parameter with colon: ''expr: expr''
  56. nkIdentDefs, # a definition like `a, b: typeDesc = expr`
  57. # either typeDesc or expr may be nil; used in
  58. # formal parameters, var statements, etc.
  59. nkVarTuple, # a ``var (a, b) = expr`` construct
  60. nkPar, # syntactic (); may be a tuple constructor
  61. nkObjConstr, # object constructor: T(a: 1, b: 2)
  62. nkCurly, # syntactic {}
  63. nkCurlyExpr, # an expression like a{i}
  64. nkBracket, # syntactic []
  65. nkBracketExpr, # an expression like a[i..j, k]
  66. nkPragmaExpr, # an expression like a{.pragmas.}
  67. nkRange, # an expression like i..j
  68. nkDotExpr, # a.b
  69. nkCheckedFieldExpr, # a.b, but b is a field that needs to be checked
  70. nkDerefExpr, # a^
  71. nkIfExpr, # if as an expression
  72. nkElifExpr,
  73. nkElseExpr,
  74. nkLambda, # lambda expression
  75. nkDo, # lambda block appering as trailing proc param
  76. nkAccQuoted, # `a` as a node
  77. nkTableConstr, # a table constructor {expr: expr}
  78. nkBind, # ``bind expr`` node
  79. nkClosedSymChoice, # symbol choice node; a list of nkSyms (closed)
  80. nkOpenSymChoice, # symbol choice node; a list of nkSyms (open)
  81. nkHiddenStdConv, # an implicit standard type conversion
  82. nkHiddenSubConv, # an implicit type conversion from a subtype
  83. # to a supertype
  84. nkConv, # a type conversion
  85. nkCast, # a type cast
  86. nkStaticExpr, # a static expr
  87. nkAddr, # a addr expression
  88. nkHiddenAddr, # implicit address operator
  89. nkHiddenDeref, # implicit ^ operator
  90. nkObjDownConv, # down conversion between object types
  91. nkObjUpConv, # up conversion between object types
  92. nkChckRangeF, # range check for floats
  93. nkChckRange64, # range check for 64 bit ints
  94. nkChckRange, # range check for ints
  95. nkStringToCString, # string to cstring
  96. nkCStringToString, # cstring to string
  97. # end of expressions
  98. nkAsgn, # a = b
  99. nkFastAsgn, # internal node for a fast ``a = b``
  100. # (no string copy)
  101. nkGenericParams, # generic parameters
  102. nkFormalParams, # formal parameters
  103. nkOfInherit, # inherited from symbol
  104. nkImportAs, # a 'as' b in an import statement
  105. nkProcDef, # a proc
  106. nkMethodDef, # a method
  107. nkConverterDef, # a converter
  108. nkMacroDef, # a macro
  109. nkTemplateDef, # a template
  110. nkIteratorDef, # an iterator
  111. nkOfBranch, # used inside case statements
  112. # for (cond, action)-pairs
  113. nkElifBranch, # used in if statements
  114. nkExceptBranch, # an except section
  115. nkElse, # an else part
  116. nkAsmStmt, # an assembler block
  117. nkPragma, # a pragma statement
  118. nkPragmaBlock, # a pragma with a block
  119. nkIfStmt, # an if statement
  120. nkWhenStmt, # a when expression or statement
  121. nkForStmt, # a for statement
  122. nkParForStmt, # a parallel for statement
  123. nkWhileStmt, # a while statement
  124. nkCaseStmt, # a case statement
  125. nkTypeSection, # a type section (consists of type definitions)
  126. nkVarSection, # a var section
  127. nkLetSection, # a let section
  128. nkConstSection, # a const section
  129. nkConstDef, # a const definition
  130. nkTypeDef, # a type definition
  131. nkYieldStmt, # the yield statement as a tree
  132. nkDefer, # the 'defer' statement
  133. nkTryStmt, # a try statement
  134. nkFinally, # a finally section
  135. nkRaiseStmt, # a raise statement
  136. nkReturnStmt, # a return statement
  137. nkBreakStmt, # a break statement
  138. nkContinueStmt, # a continue statement
  139. nkBlockStmt, # a block statement
  140. nkStaticStmt, # a static statement
  141. nkDiscardStmt, # a discard statement
  142. nkStmtList, # a list of statements
  143. nkImportStmt, # an import statement
  144. nkImportExceptStmt, # an import x except a statement
  145. nkExportStmt, # an export statement
  146. nkExportExceptStmt, # an 'export except' statement
  147. nkFromStmt, # a from * import statement
  148. nkIncludeStmt, # an include statement
  149. nkBindStmt, # a bind statement
  150. nkMixinStmt, # a mixin statement
  151. nkUsingStmt, # an using statement
  152. nkCommentStmt, # a comment statement
  153. nkStmtListExpr, # a statement list followed by an expr; this is used
  154. # to allow powerful multi-line templates
  155. nkBlockExpr, # a statement block ending in an expr; this is used
  156. # to allow powerful multi-line templates that open a
  157. # temporary scope
  158. nkStmtListType, # a statement list ending in a type; for macros
  159. nkBlockType, # a statement block ending in a type; for macros
  160. # types as syntactic trees:
  161. nkWith, # distinct with `foo`
  162. nkWithout, # distinct without `foo`
  163. nkTypeOfExpr, # type(1+2)
  164. nkObjectTy, # object body
  165. nkTupleTy, # tuple body
  166. nkTupleClassTy, # tuple type class
  167. nkTypeClassTy, # user-defined type class
  168. nkStaticTy, # ``static[T]``
  169. nkRecList, # list of object parts
  170. nkRecCase, # case section of object
  171. nkRecWhen, # when section of object
  172. nkRefTy, # ``ref T``
  173. nkPtrTy, # ``ptr T``
  174. nkVarTy, # ``var T``
  175. nkConstTy, # ``const T``
  176. nkOutTy, # ``out T``
  177. nkDistinctTy, # distinct type
  178. nkProcTy, # proc type
  179. nkIteratorTy, # iterator type
  180. nkSinkAsgn, # '=sink(x, y)'
  181. nkEnumTy, # enum body
  182. nkEnumFieldDef, # `ident = expr` in an enumeration
  183. nkArgList, # argument list
  184. nkPattern, # a special pattern; used for matching
  185. nkHiddenTryStmt, # a hidden try statement
  186. nkClosure, # (prc, env)-pair (internally used for code gen)
  187. nkGotoState, # used for the state machine (for iterators)
  188. nkState, # give a label to a code section (for iterators)
  189. nkBreakState, # special break statement for easier code generation
  190. nkFuncDef, # a func
  191. nkTupleConstr # a tuple constructor
  192. nkError # erroneous AST node
  193. nkModuleRef # for .rod file support: A (moduleId, itemId) pair
  194. nkReplayAction # for .rod file support: A replay action
  195. nkNilRodNode # for .rod file support: a 'nil' PNode
  196. nkOpenSym # container for captured sym that can be overriden by local symbols
  197. const
  198. nkCallKinds* = {nkCall, nkInfix, nkPrefix, nkPostfix,
  199. nkCommand, nkCallStrLit, nkHiddenCallConv}