From bd705a517f51d96300c35761d78c3f4c3ff50686 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 30 Apr 2014 00:53:44 +0200 Subject: [PATCH] compiler prepared for the new comment handling --- compiler/ccgstmts.nim | 1 + compiler/main.nim | 1 + compiler/msgs.nim | 6 +++--- compiler/semexprs.nim | 2 ++ compiler/semgnrc.nim | 1 + compiler/sempass2.nim | 8 +++++++- compiler/semtypes.nim | 1 + todo.txt | 1 + 8 files changed, 17 insertions(+), 4 deletions(-) diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 311149cb32..a8cfa57e46 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -593,6 +593,7 @@ proc genStringCase(p: BProc, t: PNode, d: var TLoc) = else: # else statement: nothing to do yet # but we reserved a label, which we use later + discard linefmt(p, cpsStmts, "switch (#hashString($1) & $2) {$n", rdLoc(a), toRope(bitMask)) for j in countup(0, high(branches)): diff --git a/compiler/main.nim b/compiler/main.nim index f6d11d960a..0e85405568 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -69,6 +69,7 @@ proc commandCompileToC = # echo "BEFORE CHECK DEP" # discard checkDepMem(gProjectMainIdx) # echo "CHECK DEP COMPLETE" + discard compileProject() cgenWriteModules() diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 8374c92a77..730cb96055 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -116,7 +116,7 @@ type warnSmallLshouldNotBeUsed, warnUnknownMagic, warnRedefinitionOfLabel, warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored, warnNilStatement, warnAnalysisLoophole, - warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure, + warnDifferentHeaps, warnWriteToForeignHeap, warnUnsafeCode, warnEachIdentIsTuple, warnShadowIdent, warnProveInit, warnProveField, warnProveIndex, warnGcUnsafe, warnGcUnsafe2, warnUninit, warnGcMem, warnUser, @@ -380,7 +380,7 @@ const warnAnalysisLoophole: "thread analysis incomplete due to unknown call '$1' [AnalysisLoophole]", warnDifferentHeaps: "possible inconsistency of thread local heaps [DifferentHeaps]", warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]", - warnImplicitClosure: "implicit closure convention: '$1' [ImplicitClosure]", + warnUnsafeCode: "unsafe code: '$1' [UnsafeCode]", warnEachIdentIsTuple: "each identifier is a tuple [EachIdentIsTuple]", warnShadowIdent: "shadowed identifier: '$1' [ShadowIdent]", warnProveInit: "Cannot prove that '$1' is initialized. This will become a compile time error in the future. [ProveInit]", @@ -416,7 +416,7 @@ const "RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported", "CommentXIgnored", "NilStmt", "AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap", - "ImplicitClosure", "EachIdentIsTuple", "ShadowIdent", + "UnsafeCode", "EachIdentIsTuple", "ShadowIdent", "ProveInit", "ProveField", "ProveIndex", "GcUnsafe", "GcUnsafe2", "Uninit", "GcMem", "User"] diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 652e1dd4b0..9ea93a15e9 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -166,6 +166,7 @@ proc checkConvertible(c: PContext, castDest, src: PType): TConvStatus = elif (skipTypes(castDest, abstractVarRange).kind in IntegralTypes) and (skipTypes(src, abstractVarRange-{tyTypeDesc}).kind in IntegralTypes): # accept conversion between integral types + discard else: # we use d, s here to speed up that operation a bit: case cmpTypes(c, d, s) @@ -2060,6 +2061,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = of nkClosedSymChoice, nkOpenSymChoice: # handling of sym choices is context dependent # the node is left intact for now + discard of nkStaticExpr: result = semStaticExpr(c, n) of nkAsgn: result = semAsgn(c, n) diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index da4a2a1321..63beb15b0a 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -141,6 +141,7 @@ proc semGenericStmt(c: PContext, n: PNode, # symbol lookup ... of skUnknown, skParam: # Leave it as an identifier. + discard of skProc, skMethod, skIterators, skConverter: result.sons[0] = symChoice(c, n.sons[0], s, scOption) first = 1 diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 6235fb76a4..6afde5f059 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -1,7 +1,7 @@ # # # The Nimrod Compiler -# (c) Copyright 2013 Andreas Rumpf +# (c) Copyright 2014 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -485,6 +485,11 @@ proc isTrue(n: PNode): bool = proc paramType(op: PType, i: int): PType = if op != nil and i < op.len: result = op.sons[i] +proc cstringCheck(tracked: PEffects; n: PNode) = + if n.sons[0].typ.kind == tyCString and (let a = skipConv(n[1]); + a.typ.kind == tyString and a.kind notin {nkStrLit..nkTripleStrLit}): + message(n.info, warnUnsafeCode, renderTree(n)) + proc track(tracked: PEffects, n: PNode) = case n.kind of nkSym: @@ -541,6 +546,7 @@ proc track(tracked: PEffects, n: PNode) = track(tracked, n.sons[0]) addAsgnFact(tracked.guards, n.sons[0], n.sons[1]) notNilCheck(tracked, n.sons[1], n.sons[0].typ) + when false: cstringCheck(tracked, n) of nkVarSection: for child in n: let last = lastSon(child) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 6289ecc85c..8fcb6ea997 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -385,6 +385,7 @@ proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode, case kind of skType: # process pragmas later, because result.typ has not been set yet + discard of skField: pragma(c, result, n.sons[1], fieldPragmas) of skVar: pragma(c, result, n.sons[1], varPragmas) of skLet: pragma(c, result, n.sons[1], letPragmas) diff --git a/todo.txt b/todo.txt index c2335dd32e..996067175f 100644 --- a/todo.txt +++ b/todo.txt @@ -11,6 +11,7 @@ version 0.9.6 - built-in 'getImpl' - type API for macros; make 'spawn' a macro - markAndSweepGC should expose an API for fibers +- prevent 'alloc(TypeWithGCedMemory)' Bugs