first steps to deprecate 'nil' statement

This commit is contained in:
Araq
2012-09-09 01:08:00 +02:00
parent 46f652b93e
commit d3d9d32c35
9 changed files with 34 additions and 36 deletions

View File

@@ -853,9 +853,10 @@ proc genStmts(p: BProc, t: PNode) =
# transf is overly aggressive with 'nkFastAsgn', so we work around here.
# See tests/run/tcnstseq3 for an example that would fail otherwise.
genAsgn(p, t, fastAsgn=p.prc != nil)
of nkDiscardStmt:
genLineDir(p, t)
initLocExpr(p, t.sons[0], a)
of nkDiscardStmt:
if t.sons[0].kind != nkEmpty:
genLineDir(p, t)
initLocExpr(p, t.sons[0], a)
of nkAsmStmt: genAsmStmt(p, t)
of nkTryStmt:
if gCmd == cmdCompileToCpp: genTryStmtCpp(p, t)

View File

@@ -1458,9 +1458,10 @@ proc genStmt(p: var TProc, n: PNode, r: var TCompRes) =
of nkAsgn: genAsgn(p, n, r)
of nkFastAsgn: genFastAsgn(p, n, r)
of nkDiscardStmt:
genLineDir(p, n, r)
gen(p, n.sons[0], r)
app(r.res, ';' & tnl)
if n.sons[0].kind != nkEmpty:
genLineDir(p, n, r)
gen(p, n.sons[0], r)
app(r.res, ';' & tnl)
of nkAsmStmt: genAsmStmt(p, n, r)
of nkTryStmt: genTryStmt(p, n, r)
of nkRaiseStmt: genRaiseStmt(p, n, r)

View File

@@ -102,7 +102,7 @@ type
warnDeprecated, warnConfigDeprecated,
warnSmallLshouldNotBeUsed, warnUnknownMagic, warnRedefinitionOfLabel,
warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored,
warnXisPassedToProcVar, warnAnalysisLoophole,
warnNilStatement, warnAnalysisLoophole,
warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure,
warnEachIdentIsTuple, warnUser,
hintSuccess, hintSuccessX,
@@ -345,7 +345,7 @@ const
warnUnknownSubstitutionX: "unknown substitution \'$1\' [UnknownSubstitutionX]",
warnLanguageXNotSupported: "language \'$1\' not supported [LanguageXNotSupported]",
warnCommentXIgnored: "comment \'$1\' ignored [CommentXIgnored]",
warnXisPassedToProcVar: "\'$1\' is passed to a procvar; deprecated [XisPassedToProcVar]",
warnNilStatement: "'nil' statement is deprecated; use an empty 'discard' statement instead [NilStmt]",
warnAnalysisLoophole: "thread analysis incomplete due to unknown call '$1' [AnalysisLoophole]",
warnDifferentHeaps: "possible inconsistency of thread local heaps [DifferentHeaps]",
warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]",
@@ -375,7 +375,7 @@ const
"Deprecated", "ConfigDeprecated",
"SmallLshouldNotBeUsed", "UnknownMagic",
"RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported",
"CommentXIgnored", "XisPassedToProcVar",
"CommentXIgnored", "NilStmt",
"AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap",
"ImplicitClosure", "EachIdentIsTuple", "User"]

View File

@@ -1487,7 +1487,7 @@ proc simpleStmt(p: var TParser): PNode =
of tkReturn: result = parseReturnOrRaise(p, nkReturnStmt)
of tkRaise: result = parseReturnOrRaise(p, nkRaiseStmt)
of tkYield: result = parseYieldOrDiscard(p, nkYieldStmt)
of tkDiscard: result = parseYieldOrDiscard(p, nkDiscardStmt)
of tkDiscard: result = parseReturnOrRaise(p, nkDiscardStmt)
of tkBreak: result = parseBreakOrContinue(p, nkBreakStmt)
of tkContinue: result = parseBreakOrContinue(p, nkContinueStmt)
of tkCurlyDotLe: result = parseStmtPragma(p)

View File

@@ -121,9 +121,6 @@ proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool =
add(arglist, n)
else:
result = false
debug p.sons[2].sym.typ
debug n.typ
echo "type check failed!"
if n.kind notin nkCallKinds: return false
if matches(c, p.sons[1], n.sons[0]):

View File

@@ -62,8 +62,9 @@ proc semIf(c: PContext, n: PNode): PNode =
proc semDiscard(c: PContext, n: PNode): PNode =
result = n
checkSonsLen(n, 1)
n.sons[0] = semExprWithType(c, n.sons[0])
if n.sons[0].typ == nil: localError(n.info, errInvalidDiscard)
if n.sons[0].kind != nkEmpty:
n.sons[0] = semExprWithType(c, n.sons[0])
if n.sons[0].typ == nil: localError(n.info, errInvalidDiscard)
proc semBreakOrContinue(c: PContext, n: PNode): PNode =
result = n
@@ -935,7 +936,8 @@ proc semStaticStmt(c: PContext, n: PNode): PNode =
if result.isNil:
LocalError(n.info, errCannotInterpretNodeX, renderTree(n))
elif result.kind == nkEmpty:
result = newNodeI(nkNilLit, n.info)
result = newNodeI(nkDiscardStmt, n.info, 1)
result.sons[0] = emptyNode
# special marker values that indicates that we are
# 1) AnalyzingDestructor: currenlty analyzing the type for destructor
@@ -1132,7 +1134,10 @@ proc SemStmt(c: PContext, n: PNode): PNode =
of nkAsgn: result = semAsgn(c, n)
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkMacroStmt, nkCallStrLit:
result = semCommand(c, n)
of nkEmpty, nkCommentStmt, nkNilLit: nil
of nkEmpty, nkCommentStmt: nil
of nkNilLit:
# XXX too much work and fixing would break bootstrapping:
#Message(n.info, warnNilStatement)
of nkBlockStmt: result = semBlock(c, n)
of nkStmtList:
var length = sonsLen(n)

View File

@@ -185,16 +185,6 @@ proc transformConstSection(c: PTransf, v: PNode): PTransNode =
else:
result[i] = PTransNode(it)
proc trivialBody(s: PSym): PNode =
# a routine's body is trivially inlinable if marked as 'inline' and its
# body consists of only 1 statement. It is important that we perform this
# optimization here as 'distinct strings' may cause string copying otherwise:
# proc xml(s: string): TXmlString = return xmlstring(s)
# We have to generate a ``nkLineTracking`` node though to not lose
# debug information:
# XXX to implement
nil
proc hasContinue(n: PNode): bool =
case n.kind
of nkEmpty..nkNilLit, nkForStmt, nkParForStmt, nkWhileStmt: nil
@@ -627,11 +617,14 @@ proc transform(c: PTransf, n: PNode): PTransNode =
result = transformAddrDeref(c, n, nkAddr, nkHiddenAddr)
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
result = transformConv(c, n)
of nkDiscardStmt:
result = transformSons(c, n)
if isConstExpr(PNode(result).sons[0]):
# ensure that e.g. discard "some comment" gets optimized away completely:
result = PTransNode(newNode(nkCommentStmt))
of nkDiscardStmt:
result = PTransNode(n)
if n.sons[0].kind != nkEmpty:
result = transformSons(c, n)
if isConstExpr(PNode(result).sons[0]):
# ensure that e.g. discard "some comment" gets optimized away
# completely:
result = PTransNode(newNode(nkCommentStmt))
of nkCommentStmt, nkTemplateDef:
return n.ptransNode
of nkConstSection:

View File

@@ -1,5 +1,6 @@
Comex
Eric Doughty-Papassideris
Simon Hafner
Keita Haga
Philippe Lhoste
Zahary Karadjov

View File

@@ -6,9 +6,6 @@ version 0.9.0
- make 'bind' default for templates and introduce 'mixin'
- implement "closure tuple consists of a single 'ref'" optimization
- implement for loop transformation for first class iterators
- implicit deref for parameter matching
- optimize genericAssign in the code generator
- the lookup rules for generics really are too permissive; global scope only
@@ -43,6 +40,8 @@ version 0.9.XX
echo a
echo b)
- implement "closure tuple consists of a single 'ref'" optimization
- implement for loop transformation for first class iterators
- JS gen:
- fix exception handling
- object branch transitions can't work with the current 'reset'; add a 'reset'
@@ -60,7 +59,8 @@ version 0.9.XX
a full blown statement; a ``try`` expression might be a good idea to make
error handling more light-weight
- ``=`` should be overloadable; requires specialization for ``=``
- ``hoist`` pragma for loop hoisting
- ``hoist`` pragma for loop hoisting: can be easily done with
AST overloading + global
- document destructors; don't work yet when used as expression
- make use of ``tyIter`` to fix the implicit items/pairs issue
- better support for macros that rewrite procs