From 52bf954ba5e139fb696ada4c65f23bdc7a68864d Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 23 Aug 2023 18:19:39 +0800 Subject: [PATCH] checkpoint --- compiler/ast.nim | 3 ++- compiler/options.nim | 1 + compiler/pipelines.nim | 6 ++--- compiler/procfind.nim | 2 +- compiler/sem.nim | 55 ++++++++++++++++++++++++++++++++++++++++++ compiler/semstmts.nim | 30 +++++++++++++++++------ compiler/sigmatch.nim | 1 + tests/forward/t1.nim | 11 +++++++++ tests/forward/t2.nim | 14 +++++++++++ tests/forward/t3.nim | 15 ++++++++++++ tests/options/test.h | 5 ++++ 11 files changed, 131 insertions(+), 12 deletions(-) create mode 100644 tests/forward/t1.nim create mode 100644 tests/forward/t2.nim create mode 100644 tests/forward/t3.nim create mode 100644 tests/options/test.h diff --git a/compiler/ast.nim b/compiler/ast.nim index ce5ad0f292..9e60b1abf3 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -231,7 +231,7 @@ type TNodeKinds* = set[TNodeKind] type - TSymFlag* = enum # 51 flags! + TSymFlag* = enum # 52 flags! sfUsed, # read access of sym (for warnings) or simply used sfExported, # symbol is exported from module sfFromGeneric, # symbol is instantiation of a generic; this is needed @@ -316,6 +316,7 @@ type sfByCopy # param is marked as pass bycopy sfMember # proc is a C++ member of a type sfCodegenDecl # type, proc, global or proc param is marked as codegenDecl + sfToplevelDecl TSymFlags* = set[TSymFlag] diff --git a/compiler/options.nim b/compiler/options.nim index bda86a5989..bb1eb52d83 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -222,6 +222,7 @@ type strictDefs, strictCaseObjects, inferGenericTypes + noforwardDecl LegacyFeature* = enum allowSemcheckedAstModification, diff --git a/compiler/pipelines.nim b/compiler/pipelines.nim index 8517cd9426..4324b77280 100644 --- a/compiler/pipelines.nim +++ b/compiler/pipelines.nim @@ -81,9 +81,9 @@ proc prePass(c: PContext; n: PNode) = of nkStrLit, nkRStrLit, nkTripleStrLit: try: let feature = parseEnum[Feature](name.strVal) - if feature == codeReordering: - c.features.incl feature - c.module.flags.incl sfReorder + # if feature == codeReordering: + c.features.incl feature + c.module.flags.incl sfReorder except ValueError: discard else: diff --git a/compiler/procfind.nim b/compiler/procfind.nim index 0bdb3dae6d..5877a9dac1 100644 --- a/compiler/procfind.nim +++ b/compiler/procfind.nim @@ -34,7 +34,7 @@ proc searchForProcAux(c: PContext, scope: PScope, fn: PSym): PSym = var it: TIdentIter result = initIdentIter(it, scope.symbols, fn.name) while result != nil: - if result.kind == fn.kind: #and sameType(result.typ, fn.typ, flags): + if result.kind == fn.kind and result.typ != nil: #and sameType(result.typ, fn.typ, flags): case equalParams(result.typ.n, fn.typ.n) of paramsEqual: if (sfExported notin result.flags) and (sfExported in fn.flags): diff --git a/compiler/sem.nim b/compiler/sem.nim index f69e7a69d0..65ac689cd7 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -762,6 +762,58 @@ proc isEmptyTree(n: PNode): bool = of nkEmpty, nkCommentStmt: result = true else: result = false +proc decl(c: PContext, n: PNode, kind: TSymKind): PNode = + if n[0].kind == nkIdent: + var s = newSym(kind, n[0].ident, c.idgen, getCurrOwner(c), n.info) + s.flags.incl sfToplevelDecl + # pragmaCallable(c, s, n, allRoutinePragmas) + + result = n + if n[^1].kind != nkEmpty: + if s.kind in OverloadableSyms: + addInterfaceOverloadableSymAt(c, c.currentScope, s) + else: + addInterfaceDeclAt(c, c.currentScope, s) + + result[0] = newSymNode(s) + else: + result = n + +import reorder + +proc semSignature(c: PContext, n: PNode): PNode = + case n.kind + of nkProcDef: + result = decl(c, n, skProc) + of nkMethodDef: + result = decl(c, n, skMethod) + of nkConverterDef: + result = decl(c, n, skConverter) + of nkMacroDef: + result = decl(c, n, skMacro) + of nkTemplateDef: + result = decl(c, n, skTemplate) + of nkIteratorDef: + result = decl(c, n, skIterator) + of nkIncludeStmt: + result = n + for i in 0..