diff options
author | Dominik Picheta <dominikpicheta@gmail.com> | 2017-02-02 21:36:49 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@gmail.com> | 2017-02-02 21:36:49 +0100 |
commit | 656da1f6a99c504eb5bf7c51b01b8fe00e2afd71 (patch) | |
tree | b6b1b3a7731b01511758bf45962eb9d3fbda3dc7 /compiler | |
parent | 814f527175c0141c8f023b100461e72a9e990e6c (diff) | |
download | Nim-656da1f6a99c504eb5bf7c51b01b8fe00e2afd71.tar.gz |
WIP: `as` with generics.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/lookups.nim | 3 | ||||
-rw-r--r-- | compiler/semgnrc.nim | 11 | ||||
-rw-r--r-- | compiler/semstmts.nim | 3 | ||||
-rw-r--r-- | compiler/transf.nim | 2 |
4 files changed, 15 insertions, 4 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 61ecdb24b..cb7985384 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -434,3 +434,6 @@ proc pickSym*(c: PContext, n: PNode; kind: TSymKind; if a.kind == kind and flags <= a.flags: return a a = nextOverloadIter(o, c, n) + +proc isExceptAs*(n: PNode): bool = + return n.kind == nkInfix and considerQuotedIdent(n[0]).s == "as" \ No newline at end of file diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index ab0ce7c4c..42f9bd401 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -339,8 +339,17 @@ proc semGenericStmt(c: PContext, n: PNode, checkMinSonsLen(a, 1) var L = sonsLen(a) for j in countup(0, L-2): - a.sons[j] = semGenericStmt(c, a.sons[j], flags+{withinTypeDesc}, ctx) + debug(a.sons[j]) + if a.sons[j].isExceptAs(): + openScope(c) + addTempDecl(c, getIdentNode(a.sons[j][2]), skLet) + a.sons[j] = semGenericStmt(c, a.sons[j][1], flags+{withinTypeDesc}, ctx) + closeScope(c) + else: + a.sons[j] = semGenericStmt(c, a.sons[j], flags+{withinTypeDesc}, ctx) + debug(a) a.sons[L-1] = semGenericStmtScope(c, a.sons[L-1], flags, ctx) + of nkVarSection, nkLetSection: for i in countup(0, sonsLen(n) - 1): var a = n.sons[i] diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 35c686bcb..674589306 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -286,8 +286,7 @@ proc semTry(c: PContext, n: PNode): PNode = var typeNode = a.sons[j] # e.g. `Exception` var symbolNode: PNode = nil # e.g. `foobar` # Handle the case where the `Exception as foobar` syntax is used. - if typeNode.kind == nkInfix and - considerQuotedIdent(typeNode[0]).s == "as": + if typeNode.isExceptAs(): typeNode = a.sons[j].sons[1] symbolNode = a.sons[j].sons[2] diff --git a/compiler/transf.nim b/compiler/transf.nim index 8944ff43b..838b2d902 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -703,7 +703,7 @@ proc transformCall(c: PTransf, n: PNode): PTransNode = proc transformExceptBranch(c: PTransf, n: PNode): PTransNode = result = transformSons(c, n) - if n[0].kind == nkInfix and considerQuotedIdent(n[0][0]).s == "as": + if n[0].isExceptAs(): let excTypeNode = n[0][1] let actions = newTransNode(nkStmtList, n[1].info, 2) # Generating `let exc = (excType)(getCurrentException())` |