Skip to content

Commit

Permalink
Merge branch 'replace_libdparse' into delete-duplicateda
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladiwostok committed Feb 20, 2024
2 parents 6a8492e + 2bf728f commit b54ab19
Show file tree
Hide file tree
Showing 67 changed files with 4,644 additions and 604 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/it/autofix_ide/source_autofix.d text eol=lf
35 changes: 32 additions & 3 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
]
build: [
{ type: make },
{ type: dub, version: 'current' },
{ type: dub, version: 'min libdparse' },
# Fail due to unresolvable dependencies
# { type: dub, version: 'max libdparse' },
Expand All @@ -62,6 +63,8 @@ jobs:
dmd: gdc-12
build:
type: dub
include:
- { do_report: 1, build: { type: dub, version: 'current' }, host: 'ubuntu-22.04', compiler: { version: dmd-latest, dmd: dmd } }

runs-on: ${{ matrix.host }}

Expand Down Expand Up @@ -114,14 +117,22 @@ jobs:
# Compile D-Scanner and execute all tests using a specific dependency version
# Currently skipped for GDC (dub installed from apt-get is broken)
- name: Build and test with dub
if: ${{ matrix.build.type == 'dub' }}
- name: Build and test with dub (min or max libdparse test)
if: ${{ matrix.build.type == 'dub' && matrix.build.version != 'current' }}
env:
DC: ${{ matrix.compiler.dmd }}
run: |
rdmd ./d-test-utils/test_with_package.d ${{ matrix.build.version }} -- dub build
rdmd ./d-test-utils/test_with_package.d ${{ matrix.build.version }} -- dub test
- name: Build and test with dub (with dub.selections.json)
if: ${{ matrix.build.type == 'dub' && matrix.build.version == 'current' }}
env:
DC: ${{ matrix.compiler.dmd }}
run: |
dub build
dub test
- uses: actions/upload-artifact@v2
with:
name: bin-${{matrix.build.type}}-${{matrix.build.version}}-${{ matrix.compiler.dmd }}-${{ matrix.host }}
Expand All @@ -130,13 +141,31 @@ jobs:
# Lint source code using the previously built binary
- name: Run linter
shell: bash
env:
REPORT_GITHUB: ${{matrix.do_report}}
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
EXE=".exe"
else
EXE=""
fi
"./bin/dscanner$EXE" --config .dscanner.ini --styleCheck src
if [ "$REPORT_GITHUB" == "1" ]; then
FORMAT="github"
else
FORMAT=""
fi
"./bin/dscanner$EXE" --styleCheck -f "$FORMAT" src
# TODO: fixme
#- name: Integration Tests
#run: ./it.sh
#working-directory: tests
#shell: bash

- name: Run style checks
if: ${{ matrix.compiler.dmd == 'dmd' && matrix.build.type == 'make' }}
run: |
make style
- name: Run style checks
if: ${{ matrix.compiler.dmd == 'dmd' && matrix.build.type == 'make' }}
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ dsc

# Dub stuff
.dub
dub.selections.json
2 changes: 1 addition & 1 deletion .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ else
make lint
git clone https://www.github.com/dlang/phobos.git --depth=1
# just check that it doesn't crash
cd phobos/std && ../../bin/dscanner -S --config=../.dscanner.ini || true
cd phobos/std && ../../bin/dscanner -S || true
fi
2 changes: 1 addition & 1 deletion DCD
Submodule DCD updated 56 files
+2 −2 .github/workflows/ci.yml
+4 −0 .gitignore
+2 −2 ci/summary_comment.sh
+495 −108 common/src/dcd/common/constants2.d
+5 −0 constants-gen/generator.d
+293 −40 constants-gen/pragma.dd
+979 −532 constants-gen/traits.dd
+1 −1 dsymbol/dub.json
+4 −0 dsymbol/src/dsymbol/builtin/symbols.d
+63 −22 dsymbol/src/dsymbol/conversion/first.d
+1 −1 dsymbol/src/dsymbol/conversion/package.d
+92 −91 dsymbol/src/dsymbol/conversion/second.d
+37 −1 dsymbol/src/dsymbol/conversion/third.d
+34 −2 dsymbol/src/dsymbol/symbol.d
+10 −1 dsymbol/src/dsymbol/tests.d
+70 −9 dsymbol/src/dsymbol/ufcs.d
+1 −1 dub.json
+1 −1 dub.selections.json
+1 −1 libdparse
+1 −1 makefile
+134 −39 src/dcd/server/autocomplete/complete.d
+36 −1 src/dcd/server/autocomplete/util.d
+10 −3 src/dcd/server/main.d
+1 −0 tests/extra/tc_ufcs_all_kinds/.gitignore
+266 −0 tests/extra/tc_ufcs_all_kinds/generate_tests.d
+7 −0 tests/extra/tc_ufcs_all_kinds/run.sh
+25 −7 tests/run_tests.sh
+8 −0 tests/tc717/expected.txt
+15 −0 tests/tc717/file.d
+5 −0 tests/tc717/run.sh
+2 −0 tests/tc_template_bang_completion/expected.txt
+2 −0 tests/tc_template_bang_completion/expected2.txt
+2 −0 tests/tc_template_bang_completion/expected3.txt
+2 −0 tests/tc_template_bang_completion/expected4.txt
+2 −0 tests/tc_template_bang_completion/expected5.txt
+2 −0 tests/tc_template_bang_completion/expected6.txt
+0 −0 tests/tc_template_bang_completion/expected7.txt
+0 −0 tests/tc_template_bang_completion/expected8.txt
+43 −0 tests/tc_template_bang_completion/file.d
+26 −0 tests/tc_template_bang_completion/run.sh
+13 −0 tests/tc_traits/expected.txt
+13 −0 tests/tc_ufcs_fundamental_types_completion/expected_bool_test.txt
+12 −0 tests/tc_ufcs_fundamental_types_completion/expected_byte_test.txt
+12 −0 tests/tc_ufcs_fundamental_types_completion/expected_char_test.txt
+6 −0 tests/tc_ufcs_fundamental_types_completion/expected_dchar_test.txt
+2 −0 tests/tc_ufcs_fundamental_types_completion/expected_double_test.txt
+2 −0 tests/tc_ufcs_fundamental_types_completion/expected_float_test.txt
+7 −0 tests/tc_ufcs_fundamental_types_completion/expected_int_test.txt
+4 −0 tests/tc_ufcs_fundamental_types_completion/expected_long_test.txt
+2 −0 tests/tc_ufcs_fundamental_types_completion/expected_real_test.txt
+9 −0 tests/tc_ufcs_fundamental_types_completion/expected_short_test.txt
+12 −0 tests/tc_ufcs_fundamental_types_completion/expected_ubyte_test.txt
+7 −0 tests/tc_ufcs_fundamental_types_completion/expected_uint_test.txt
+4 −0 tests/tc_ufcs_fundamental_types_completion/expected_ulong_test.txt
+9 −0 tests/tc_ufcs_fundamental_types_completion/expected_ushort_test.txt
+9 −0 tests/tc_ufcs_fundamental_types_completion/expected_wchar_test.txt
135 changes: 126 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# D-Scanner fork that uses dmd as a library (WIP)
# D-Scanner

[![CI status](https://github.com/dlang-community/D-Scanner/actions/workflows/default.yml/badge.svg)](https://github.com/dlang-community/D-Scanner/actions?query=workflow%3A%22run+tests%22)
[![Latest version](https://img.shields.io/dub/v/dscanner.svg)](http://code.dlang.org/packages/dscanner)
[![License](https://img.shields.io/dub/l/dscanner.svg)](http://code.dlang.org/packages/dscanner)

D-Scanner is a tool for analyzing D source code

Expand Down Expand Up @@ -51,6 +55,109 @@ void main(string[] args)
}
```

## Linting

Use

```sh
dscanner lint source/
```

to view a human readable list of issues.

Diagnostic types can be enabled/disabled using a configuration file, check out
the `--config` argument / `dscanner.ini` file for more info. Tip: some IDEs that
integrate D-Scanner may have helpers to configure the diagnostics or help
generate the dscanner.ini file.
<!--
IDE list for overview:
code-d has an "insert default dscanner.ini content" command + proprietary
disabling per-line (we really need to bring that into standard D-Scanner)
-->

## Auto-Fixing issues

Use

```sh
dscanner fix source/
```

to interactively fix all fixable issues within the source directory. Call with
`--applySingle` to automatically apply fixes that don't have multiple automatic
solutions.

## Tooling integration

Many D editors already ship with D-Scanner.

For a CLI / tool parsable output use either

```sh
dscanner -S source/
# or
dscanner --report source/
```

The `--report` switch includes all information, plus cheap to compute autofixes
that are already resolved ahead of time, as well as the names for the autofixes
that need to be resolved using the `--resolveMessage` switch like described
below.

You can also specify custom formats using `-f` / `--errorFormat`, where there
are also built-in formats for GitHub Actions:

```sh
# for GitHub actions: (automatically adds annotations to files in PRs)
dscanner -S -f github source/
# custom format:
dscanner -S -f '{filepath}({line}:{column})[{type}]: {message}' source/
```

To resolve automatic issue fixes for a given location use

```sh
# collecting automatic issue fixes
# --resolveMessage <line>:<column> <filename>
dscanner --resolveMessage 11:3 file.d
# --resolveMessage b<byteIndex> <filename>
dscanner --resolveMessage b512 file.d
# <filename> may be omitted to read from stdin
```

outputs JSON:

```json
// list of available auto-fixes at the given location
[
{
"name": "Make function const",
// byte range `[start, end)` what code to replace
// this is sorted by range[0]
"replacements": [
// replace: range[0] < range[1], newText != ""
{"range": [10, 14], "newText": "const "},
// insert: range[0] == range[1], newText != ""
{"range": [20, 20], "newText": "auto"},
// remove: range[0] < range[1], newText == ""
{"range": [30, 40], "newText": ""},
]
}
]
```

Algorithm to apply replacements:
```d
foreach_reverse (r; replacements)
codeBytes = codeBytes[0 .. r.range[0]] ~ r.newText ~ codeBytes[r.range[1] .. $];
```

Replacements are non-overlapping, sorted by `range[0]` in ascending order. When
combining multiple different replacements, you first need to sort them by
`range[0]` to apply using the algorithm above.

## Other features

### Token Count
The "--tokenCount" or "-t" option prints the number of tokens in the given file

Expand Down Expand Up @@ -103,7 +210,7 @@ To avoid these cases, it's possible to pass the "--skipTests" option.
#### Configuration
By default all checks are enabled. Individual checks can be enabled or disabled
by using a configuration file. Such a file can be placed, for example, is the root directory of your project.
Running ```dscanner --defaultConfig``` will generate a default configuration file and print the file's location.
Running `dscanner --defaultConfig` will generate a default configuration file and print the file's location.
You can also specify the path to a configuration file by using the "--config" option if
you want to override the default or the local settings.

Expand Down Expand Up @@ -207,8 +314,15 @@ and case tokens in the file.

### Syntax Highlighting
The "--highlight" option prints the given source file as syntax-highlighted HTML
to the standard output. The CSS styling is currently hard-coded to use the
[Solarized](http://ethanschoonover.com/solarized) color scheme.
to the standard output. The CSS styling uses the [Solarized](http://ethanschoonover.com/solarized)
color scheme by default, but can be customised using the "--theme" option.

The following themes are available:

- `solarized`
- `solarized-dark`
- `gruvbox`
- `gruvbox-dark`

No example. It would take up too much space

Expand Down Expand Up @@ -251,10 +365,13 @@ outline of the file's declarations to stdout.

### Configuration

By default Dscanner uses the configuration file given in `$HOME/.config/dscanner/dscanner.ini`.
Run `--defaultConfig` to regenerate it.
The `--config` option allows one to use a custom configuration file.
If a `dscanner.ini` file is locate in the working directory or any of it's parents, it overrides any other configuration files.
If a `dscanner.ini` file is locate in the working directory or any of it's
parents, it overrides any other configuration files.

As final location, D-Scanner uses the configuration file given in
`$HOME/.config/dscanner/dscanner.ini`. Run `--defaultConfig` to regenerate it.

The `--config` option allows one to use a custom configuration file path.

### AST Dump
The "--ast" or "--xml" options will dump the complete abstract syntax tree of
Expand Down Expand Up @@ -351,7 +468,7 @@ using its formatting switch.
Selecting modules for a specific check
--------------------------------------

It is possible to create a new section `analysis.config.ModuleFilters` in the `.dscanner.ini`.
It is possible to create a new section `analysis.config.ModuleFilters` in the `dscanner.ini`.
In this optional section a comma-separated list of inclusion and exclusion selectors can
be specified for every check on which selective filtering should be applied.
These given selectors match on the module name and partial matches (`std.` or `.foo.`) are possible.
Expand Down
69 changes: 47 additions & 22 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ if %githashsize% == 0 (
move /y bin\githash_.txt bin\githash.txt
)

set DFLAGS=-O -release -version=StdLoggerDisableWarning -version=CallbackAPI -version=DMDLIB -version=MARS -Jbin -Jdmd -Jdmd\compiler\src\dmd\res %MFLAGS%
set TESTFLAGS=-g -w -version=StdLoggerDisableWarning -version=CallbackAPI -version=DMDLIB -version=MARS -Jbin -Jdmd -Jdmd\compiler\src\dmd\res
set DFLAGS=-O -release -version=StdLoggerDisableWarning -version=CallbackAPI -version=DMDLIB -version=MARS -version=NoBackend -version=NoMain -Jbin -Jdmd -Jdmd\compiler\src\dmd\res %MFLAGS%
set TESTFLAGS=-g -w -version=StdLoggerDisableWarning -version=CallbackAPI -version=DMDLIB -version=MARS -version=NoBackend -version=NoMain -Jbin -Jdmd -Jdmd\compiler\src\dmd\res
set CORE=
set LIBDPARSE=
set STD=
Expand All @@ -29,7 +29,43 @@ set DSYMBOL=
set CONTAINERS=
set LIBDDOC=

SET DMD_FRONTEND_SRC=objc_glue.obj clone.obj transitivevisitor.obj iasm.obj iasmdmd.obj canthrow.obj tokens.obj optimize.obj func.obj semantic2.obj dvarstats.obj ph2.obj code.obj cdef.obj xmm.obj out.obj elfobj.obj glocal.obj dvec.obj code_x86.obj iasm2.obj string2.obj file2.obj obj.obj go.obj inliner.obj cc.obj bcomplex.obj mscoffobj.obj ptrntab.obj dlist.obj pdata.obj fp.obj cod3.obj os.obj cgelem.obj dcode.obj disasm86.obj exh.obj blockopt.obj aarray.obj cg.obj newman.obj dwarfdbginf.obj codebuilder.obj var.obj cod2.obj machobj.obj cgobj.obj cod4.obj dtype.obj cv4.obj backend.obj el.obj cgcod.obj cv8.obj dwarf.obj evalu8.obj ty.obj mem.obj cgxmm.obj gdag.obj gother.obj goh.obj cgcv.obj debugprint.obj cgsched.obj dwarfeh.obj cgreg.obj backconfig.obj gloop.obj divcoeff.obj cod5.obj dwarf2.obj cg87.obj nteh.obj dcgcv.obj util2.obj compress.obj type.obj elpicpie.obj gsroa.obj cgcs.obj ee.obj symbol.obj barray.obj melf.obj oper.obj cgcse.obj rtlsym.obj mscoff.obj drtlsym.obj symtab.obj dt.obj mach.obj cod1.obj global.obj filespec.obj gflow.obj elem.obj cgen.obj md5.obj chkformat.obj argtypes_sysv_x64.obj sideeffect.obj denum.obj apply.obj e2ir.obj typinf.obj statement.obj arraytypes.obj blockexit.obj init.obj scanomf.obj utils.obj parsetimevisitor.obj errorsink.obj scanmscoff.obj initsem.obj arrayop.obj nogc.obj dsymbol.obj hdrgen.obj dmangle.obj astenums.obj libmscoff.obj compiler.obj foreachvar.obj scanmach.obj dcast.obj tocsym.obj tocvdebug.obj semantic3.obj builtin.obj sapply.obj printast.obj dtemplate.obj importc.obj file_manager.obj dclass.obj argtypes_x86.obj glue.obj statement_rewrite_walker.obj target.obj aggregate.obj stringtable.obj ctfloat.obj response.obj strtold.obj port.obj aav.obj env.obj optional.obj filename.obj man.obj rootobject.obj complex.obj hash.obj region.obj utf.obj speller.obj rmem.obj array.obj longdouble.obj bitarray.obj eh.obj strictvisitor.obj permissivevisitor.obj lambdacomp.obj ctfeexpr.obj cparse.obj imphint.obj delegatize.obj access.obj identifier.obj todt.obj dmsc.obj entity.obj impcnvtab.obj dimport.obj lexer.obj dinifile.obj libomf.obj vsoptions.obj dstruct.obj aliasthis.obj ctorflow.obj errors.obj astcodegen.obj mtype.obj dtoh.obj argtypes_aarch64.obj cpreprocess.obj dmdparams.obj lib.obj id.obj parse.obj doc.obj scanelf.obj iasmgcc.obj cppmanglewin.obj stmtstate.obj ob.obj expression.obj declaration.obj location.obj dinterpret.obj inline.obj bitfields.obj string.obj int128.obj file.obj outbuffer.obj nspace.obj gluelayer.obj json.obj toir.obj intrange.obj cond.obj constfold.obj dversion.obj staticassert.obj dmodule.obj traits.obj opover.obj link.obj toctype.obj staticcond.obj statementsem.obj globals.obj libmach.obj toobj.obj s2ir.obj inlinecost.obj objc.obj visitor.obj asttypename.obj mustuse.obj dsymbolsem.obj frontend.obj safe.obj dscope.obj attrib.obj ast_node.obj escape.obj cli.obj templateparamsem.obj libelf.obj console.obj cppmangle.obj astbase.obj dmacro.obj typesem.obj expressionsem.obj
set DMD_FRONTEND_DENYLIST=^
dmd\compiler\src\dmd\mars.d^
dmd\compiler\src\dmd\dmsc.d^
dmd\compiler\src\dmd\e2ir.d^
dmd\compiler\src\dmd\eh.d^
dmd\compiler\src\dmd\glue.d^
dmd\compiler\src\dmd\iasm.d^
dmd\compiler\src\dmd\iasmdmd.d^
dmd\compiler\src\dmd\iasmgcc.d^
dmd\compiler\src\dmd\irstate.d^
dmd\compiler\src\dmd\lib.d^
dmd\compiler\src\dmd\libelf.d^
dmd\compiler\src\dmd\libmach.d^
dmd\compiler\src\dmd\libmscoff.d^
dmd\compiler\src\dmd\libomf.d^
dmd\compiler\src\dmd\objc_glue.d^
dmd\compiler\src\dmd\s2ir.d^
dmd\compiler\src\dmd\scanelf.d^
dmd\compiler\src\dmd\scanmach.d^
dmd\compiler\src\dmd\scanmscoff.d^
dmd\compiler\src\dmd\scanomf.d^
dmd\compiler\src\dmd\tocsym.d^
dmd\compiler\src\dmd\toctype.d^
dmd\compiler\src\dmd\tocvdebug.d^
dmd\compiler\src\dmd\toobj.d^
dmd\compiler\src\dmd\todt.d^
dmd\compiler\src\dmd\toir.d

set DMD_FRONTEND_SRC=
for %%x in (dmd\compiler\src\dmd\common\*.d) do set DMD_FRONTEND_SRC=!DMD_FRONTEND_SRC! %%x
for %%x in (dmd\compiler\src\dmd\root\*.d) do set DMD_FRONTEND_SRC=!DMD_FRONTEND_SRC! %%x
for %%x in (dmd\compiler\src\dmd\*.d) do (
echo "%DMD_FRONTEND_DENYLIST%" | findstr /i /c:"%%x" >nul
if errorlevel 1 (
set "DMD_FRONTEND_SRC=!DMD_FRONTEND_SRC! %%x"
)
)

set DMD_ROOT_SRC=
for %%x in (dmd\compiler\src\dmd\common\*.d) do set DMD_ROOT_SRC=!DMD_ROOT_SRC! %%x
Expand Down Expand Up @@ -69,21 +105,9 @@ for %%x in (DCD\dsymbol\src\dsymbol\conversion\*.d) do set DSYMBOL=!DSYMBOL! %%x
for %%x in (containers\src\containers\*.d) do set CONTAINERS=!CONTAINERS! %%x
for %%x in (containers\src\containers\internal\*.d) do set CONTAINERS=!CONTAINERS! %%x

for %%x in (dmd\compiler\src\dmd\common\*.d) do %DC% %DFLAGS% -c %%x -od. -I"dmd\compiler\src"
for %%x in (dmd\compiler\src\dmd\root\*.d) do %DC% %DFLAGS% -c %%x -od. -I"dmd\compiler\src"
for %%x in (dmd\compiler\src\dmd\backend\*.d) do %DC% %DFLAGS% -c %%x -od. -I"dmd\compiler\src"
for %%x in (dmd\compiler\src\dmd\*.d) do %DC% %DFLAGS% -c %%x -od. -I"dmd\compiler\src"

%DC% %DFLAGS% -c dmd\compiler\src\dmd\backend\iasm.d -od. -ofiasm2.obj -I"dmd\compiler\src"
%DC% %DFLAGS% -c dmd\compiler\src\dmd\common\string.d -od. -ofstring2.obj -I"dmd\compiler\src"
%DC% %DFLAGS% -c dmd\compiler\src\dmd\common\file.d -od. -offile2.obj -I"dmd\compiler\src"

if "%1" == "test" goto test_cmd

@echo on
dir
echo %DMD_FRONTEND_SRC%

%DC% %MFLAGS%^
%CORE%^
%STD%^
Expand All @@ -95,12 +119,12 @@ echo %DMD_FRONTEND_SRC%
%CONTAINERS%^
%DMD_FRONTEND_SRC%^
%DFLAGS%^
-I"libdparse\src"^
-I"DCD\dsymbol\src"^
-I"containers\src"^
-I"libddoc\src"^
-I"libddoc\common\source"^
-I"dmd\compiler\src"^
-Ilibdparse\src^
-IDCD\dsymbol\src^
-Icontainers\src^
-Ilibddoc\src^
-Ilibddoc\common\source^
-Idmd\compiler\src^
-ofbin\dscanner.exe
goto eof

Expand All @@ -121,7 +145,8 @@ set TESTNAME="bin\dscanner-unittest"
-I"libddoc\src"^
-I"dmd\compiler\src"^
-I"dmd\compiler\src\dmd\res"^
-lib %TESTFLAGS%^
%TESTFLAGS%^
-lib^
-of%TESTNAME%.lib
if exist %TESTNAME%.lib %DC% %MFLAGS%^
%CORE%^
Expand Down
2 changes: 1 addition & 1 deletion dmd
Submodule dmd updated 1251 files
4 changes: 3 additions & 1 deletion .dscanner.ini → dscanner.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if_else_same_check="enabled"
; Checks for some problems with constructors
constructor_check="enabled"
; Checks for unused variables and function parameters
unused_variable_check="disabled"
unused_variable_check="enabled"
; Checks for unused labels
unused_label_check="enabled"
; Checks for duplicate attributes
Expand Down Expand Up @@ -97,3 +97,5 @@ unused_result="enabled"
cyclomatic_complexity="disabled"
; Maximum cyclomatic complexity after which to issue warnings
max_cyclomatic_complexity="50"
; Check for function bodies on disabled functions
body_on_disabled_func_check="enabled"
Loading

0 comments on commit b54ab19

Please sign in to comment.