From d76aa0890cbcd52c03a51aa5d1e22b66e94b0f91 Mon Sep 17 00:00:00 2001 From: Eduard Staniloiu Date: Mon, 29 Jan 2024 18:00:16 +0200 Subject: [PATCH] Fix branch after rebase --- dmd | 2 +- makefile | 47 ++++++++++--- src/dscanner/analysis/helpers.d | 118 -------------------------------- src/dscanner/analysis/run.d | 4 ++ 4 files changed, 44 insertions(+), 127 deletions(-) diff --git a/dmd b/dmd index a422035..15ca454 160000 --- a/dmd +++ b/dmd @@ -1 +1 @@ -Subproject commit a4220358ecfcffe7ea38ab4a1996ffc5a5331f22 +Subproject commit 15ca454e8051b7dfefd1e8eab115e90e07c2ca3c diff --git a/makefile b/makefile index 0047405..6e8ace6 100644 --- a/makefile +++ b/makefile @@ -14,8 +14,37 @@ DMD_ROOT_SRC := \ DMD_FRONTEND_SRC := \ $(shell find dmd/compiler/src/dmd/common -name "*.d")\ $(shell find dmd/compiler/src/dmd/root -name "*.d")\ - $(shell find dmd/compiler/src/dmd/backend -name "*.d")\ - $(shell find dmd/compiler/src/dmd -maxdepth 1 -name "*.d" ! -name "mars.d" ) + $(shell find dmd/compiler/src/dmd -maxdepth 1 -name "*.d" \ + ! -name "mars.d" \ + ! -name "dmsc.d" \ + ! -name "e2ir.d" \ + ! -name "eh.d" \ + ! -name "glue.d" \ + ! -name "iasm.d" \ + ! -name "iasmdmd.d" \ + ! -name "iasmgcc.d" \ + ! -name "irstate.d" \ + ! -name "lib.d" \ + ! -name "libelf.d" \ + ! -name "libmach.d" \ + ! -name "libmscoff.d" \ + ! -name "libomf.d" \ + ! -name "link.d" \ + ! -name "objc_glue.d" \ + ! -name "s2ir.d" \ + ! -name "scanelf.d" \ + ! -name "scanmach.d" \ + ! -name "scanmscoff.d" \ + ! -name "scanomf.d" \ + ! -name "tocsym.d" \ + ! -name "toctype.d" \ + ! -name "tocvdebug.d" \ + ! -name "toobj.d" \ + ! -name "todt.d" \ + ! -name "toir.d" \ + ) + #$(shell find dmd/compiler/src/dmd/backend -name "*.d")\ + #$(shell find dmd/compiler/src/dmd -maxdepth 1 -name "*.d" ! -name "mars.d" ) DMD_LEXER_SRC := \ dmd/compiler/src/dmd/console.d \ @@ -83,7 +112,7 @@ INCLUDE_PATHS = \ -Ilibddoc/common/source \ -Idmd/compiler/src -DMD_VERSIONS = -version=StdLoggerDisableWarning -version=CallbackAPI -version=DMDLIB -version=MARS +DMD_VERSIONS = -version=StdLoggerDisableWarning -version=CallbackAPI -version=DMDLIB -version=MARS -version=NoBackend -version=NoMain DMD_DEBUG_VERSIONS = -version=dparse_verbose LDC_VERSIONS = -d-version=StdLoggerDisableWarning -d-version=CallbackAPI -d-version=DMDLIB -d-version=MARS LDC_DEBUG_VERSIONS = -d-version=dparse_verbose @@ -125,16 +154,18 @@ SHELL:=/usr/bin/env bash GITHASH = bin/githash.txt -FIRST_RUN_FLAG := $(OBJ_DIR)/$(DC)/first_run.flag +FIRST_RUN_FLAG := bin/first_run.flag -$(OBJ_DIR)/$(DC)/%.o: %.d +$(FIRST_RUN_FLAG): if [ ! -f $(FIRST_RUN_FLAG) ]; then \ - ${DC} -run dmd/config.d bin VERSION /etc; \ + ${DC} -run dmd/config.d bin VERSION /etc; \ touch $(FIRST_RUN_FLAG); \ fi + +$(OBJ_DIR)/$(DC)/%.o: %.d ${FIRST_RUN_FLAG} ${DC} ${DC_FLAGS} ${VERSIONS} ${INCLUDE_PATHS} -c $< ${WRITE_TO_TARGET_NAME} -$(UT_OBJ_DIR)/$(DC)/%.o: %.d +$(UT_OBJ_DIR)/$(DC)/%.o: %.d ${FIRST_RUN_FLAG} ${DC} ${DC_TEST_FLAGS} ${VERSIONS} ${INCLUDE_PATHS} -c $< ${WRITE_TO_TARGET_NAME} ${DSCANNER_BIN}: ${GITHASH} ${OBJ_BY_DC} | ${DSCANNER_BIN_DIR} @@ -174,7 +205,7 @@ ${UT_DSCANNER_LIB}: ${LIB_SRC} | ${UT_DSCANNER_LIB_DIR} test: ${UT_DSCANNER_BIN} -${UT_DSCANNER_BIN}: ${UT_DSCANNER_LIB} ${GITHASH} ${UT_OBJ_BY_DC} | ${DSCANNER_BIN_DIR} +${UT_DSCANNER_BIN}: ${GITHASH} ${UT_OBJ_BY_DC} ${UT_DSCANNER_LIB} | ${DSCANNER_BIN_DIR} ${DC} ${UT_DSCANNER_LIB} ${UT_OBJ_BY_DC} ${WRITE_TO_TARGET_NAME} ./${UT_DSCANNER_BIN} diff --git a/src/dscanner/analysis/helpers.d b/src/dscanner/analysis/helpers.d index 9cf9dce..b9e22dc 100644 --- a/src/dscanner/analysis/helpers.d +++ b/src/dscanner/analysis/helpers.d @@ -473,121 +473,3 @@ void assertAnalyzerWarningsDMD(string code, const StaticAnalysisConfig config, b throw new AssertError(message, file, line); } } - -void assertAnalyzerWarningsDMD(string code, const StaticAnalysisConfig config, bool semantic = false, - string file = __FILE__, size_t line = __LINE__) -{ - import dmd.globals : global; - import dscanner.utils : getModuleName; - import std.file : remove, exists; - import std.stdio : File; - import std.path : dirName; - import dmd.arraytypes : Strings; - - import std.stdio : File; - import std.file : exists, remove; - - auto deleteme = "test.txt"; - File f = File(deleteme, "w"); - scope(exit) - { - assert(exists(deleteme)); - remove(deleteme); - } - - f.write(code); - f.close(); - - auto dmdParentDir = dirName(dirName(dirName(dirName(__FILE_FULL_PATH__)))); - - global.params.useUnitTests = true; - global.path = new Strings(); - global.path.push((dmdParentDir ~ "/dmd" ~ "\0").ptr); - global.path.push((dmdParentDir ~ "/dmd/druntime/src" ~ "\0").ptr); - - initDMD(); - - auto input = cast(char[]) code; - input ~= '\0'; - auto t = dmd.frontend.parseModule(cast(const(char)[]) file, cast(const (char)[]) input); - if (semantic) - t.module_.fullSemantic(); - - MessageSet rawWarnings = analyzeDmd("test.txt", t.module_, getModuleName(t.module_.md), config); - - string[] codeLines = code.splitLines(); - - // Get the warnings ordered by line - string[size_t] warnings; - foreach (rawWarning; rawWarnings[]) - { - // Skip the warning if it is on line zero - immutable size_t rawLine = rawWarning.line; - if (rawLine == 0) - { - stderr.writefln("!!! Skipping warning because it is on line zero:\n%s", - rawWarning.message); - continue; - } - - size_t warnLine = line - 1 + rawLine; - warnings[warnLine] = format("[warn]: %s", rawWarning.message); - } - - // Get all the messages from the comments in the code - string[size_t] messages; - foreach (i, codeLine; codeLines) - { - // Skip if no [warn] comment - if (codeLine.indexOf("// [warn]:") == -1) - continue; - - // Skip if there is no comment or code - immutable string codePart = codeLine.before("// "); - immutable string commentPart = codeLine.after("// "); - if (!codePart.length || !commentPart.length) - continue; - - // Get the line of this code line - size_t lineNo = i + line; - - // Get the message - messages[lineNo] = commentPart; - } - - // Throw an assert error if any messages are not listed in the warnings - foreach (lineNo, message; messages) - { - // No warning - if (lineNo !in warnings) - { - immutable string errors = "Expected warning:\n%s\nFrom source code at (%s:?):\n%s".format(messages[lineNo], - lineNo, codeLines[lineNo - line]); - throw new AssertError(errors, file, lineNo); - } - // Different warning - else if (warnings[lineNo] != messages[lineNo]) - { - immutable string errors = "Expected warning:\n%s\nBut was:\n%s\nFrom source code at (%s:?):\n%s".format( - messages[lineNo], warnings[lineNo], lineNo, codeLines[lineNo - line]); - throw new AssertError(errors, file, lineNo); - } - } - - // Throw an assert error if there were any warnings that were not expected - string[] unexpectedWarnings; - foreach (lineNo, warning; warnings) - { - // Unexpected warning - if (lineNo !in messages) - { - unexpectedWarnings ~= "%s\nFrom source code at (%s:?):\n%s".format(warning, - lineNo, codeLines[lineNo - line]); - } - } - if (unexpectedWarnings.length) - { - immutable string message = "Unexpected warnings:\n" ~ unexpectedWarnings.join("\n"); - throw new AssertError(message, file, line); - } -} diff --git a/src/dscanner/analysis/run.d b/src/dscanner/analysis/run.d index 02a41c3..a298bcf 100644 --- a/src/dscanner/analysis/run.d +++ b/src/dscanner/analysis/run.d @@ -106,6 +106,10 @@ version (unittest) else enum ut = false; +void doNothing(string, size_t, size_t, string, bool) +{ +} + private alias ASTAllocator = CAllocatorImpl!( AllocatorList!(n => Region!Mallocator(1024 * 128), Mallocator));