Skip to content

Commit

Permalink
add support for compiler option "-preview=shortenedMethods"
Browse files Browse the repository at this point in the history
  • Loading branch information
rainers committed Nov 26, 2023
1 parent b193ceb commit 92f1b06
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
3 changes: 3 additions & 0 deletions msbuild/dbuild/CompileD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public CompileD()
public bool PreviewMarkdown { get { return opts.PreviewMarkdown; } set { opts.PreviewMarkdown = value; } }
public bool PreviewIn { get { return opts.PreviewIn; } set { opts.PreviewIn = value; } }
public bool PreviewInclusiveInContracts { get { return opts.PreviewInclusiveInContracts; } set { opts.PreviewInclusiveInContracts = value; } }
public bool PreviewShortenedMethods { get { return opts.PreviewShortenedMethods; } set { opts.PreviewShortenedMethods = value; } }
public bool PreviewFixImmutableConv { get { return opts.PreviewFixImmutableConv; } set { opts.PreviewFixImmutableConv = value; } }
public bool PreviewSystemVariables { get { return opts.PreviewSystemVariables; } set { opts.PreviewSystemVariables = value; } }
public bool TransitionVMarkdown { get { return opts.TransitionVMarkdown; } set { opts.TransitionVMarkdown = value; } }
public bool TransitionField { get { return opts.TransitionField; } set { opts.TransitionField = value; } }
public bool TransitionCheckImports { get { return opts.TransitionCheckImports; } set { opts.TransitionCheckImports = value; } }
Expand Down
38 changes: 37 additions & 1 deletion msbuild/dbuild/CompileDOpt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public CompileDOptions(IToolSwitchProvider provider)
this.switchOrderList.Add("PreviewMarkdown");
this.switchOrderList.Add("PreviewIn");
this.switchOrderList.Add("PreviewInclusiveInContracts");
this.switchOrderList.Add("PreviewShortenedMethods");
this.switchOrderList.Add("PreviewFixImmutableConv");
this.switchOrderList.Add("PreviewSystemVariables");
this.switchOrderList.Add("TransitionVMarkdown");
this.switchOrderList.Add("TransitionField");
this.switchOrderList.Add("TransitionCheckImports");
Expand Down Expand Up @@ -646,11 +649,44 @@ public bool PreviewInclusiveInContracts
set
{
SetBoolProperty("PreviewInclusiveInContracts", "Preview inclusiveincontracts",
"''in' contracts of overridden methods must be a superset of parent contract (-preview=inclusiveincontracts)",
"'in' contracts of overridden methods must be a superset of parent contract (-preview=inclusiveincontracts)",
"-preview=inclusiveincontracts", value);
}
}

public bool PreviewShortenedMethods
{
get { return GetBoolProperty("PreviewShortenedMethods"); }
set
{
SetBoolProperty("PreviewShortenedMethods", "Preview shortened methods",
"allow use of => for methods and top-level functions in addition to lambdas (-preview=shortenedMethods)",
"-preview=shortenedMethods", value);
}
}

public bool PreviewFixImmutableConv
{
get { return GetBoolProperty("PreviewFixImmutableConv"); }
set
{
SetBoolProperty("PreviewFixImmutableConv", "Preview disallowing unsound immutable conversions",
"disallow unsound immutable conversions that were formerly incorrectly permitted (-preview=fixImmutableConv)",
"-preview=fixImmutableConv", value);
}
}

public bool PreviewSystemVariables
{
get { return GetBoolProperty("PreviewSystemVariables"); }
set
{
SetBoolProperty("PreviewSystemVariables", "Preview system variables",
"disable access to variables marked '@system' from @safe code (-preview=systemVariables)",
"-preview=systemVariables", value);
}
}

public bool TransitionVMarkdown
{
get { return GetBoolProperty("TransitionVMarkdown"); }
Expand Down
6 changes: 6 additions & 0 deletions msbuild/dmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@
Description="'in' on parameters means `scope const [ref]` (dmd 2.092+) and accepts rvalues (dmd 2.094+)" />
<BoolProperty Name="PreviewInclusiveInContracts" Category="Language" DisplayName="Preview inclusive in contracts" Switch="-preview=inclusiveincontracts"
Description="'in' contracts of overridden methods must be a superset of parent contract (dmd 2.095+)" />
<BoolProperty Name="PreviewShortenedMethods" Category="Language" DisplayName="Preview shortened method/function syntax" Switch="-preview=shortenedMethods"
Description="allow use of => for methods and top-level functions in addition to lambdas (dmd 2.101+)" />
<BoolProperty Name="PreviewFixImmutableConv" Category="Language" DisplayName="Preview disallowing unsound immutable conversions" Switch="-preview=fixImmutableConv"
Description="disallow unsound immutable conversions that were formerly incorrectly permitted (dmd 2.101+)" />
<BoolProperty Name="PreviewSystemVariables" Category="Language" DisplayName="Preview system variables" Switch="-preview=systemVariables"
Description="disable access to variables marked '@system' from @safe code (dmd 2.102+)" />

<BoolProperty Name="RevertImport" Category="Language" DisplayName="Revert import" Switch="-revert=import"
Description="revert to single phase name lookup. (dmd 2.085+)" />
Expand Down
6 changes: 6 additions & 0 deletions msbuild/ldc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
Description="'in' on parameters means `scope const [ref]` and accepts rvalues" />
<BoolProperty Name="PreviewInclusiveInContracts" Category="Language" DisplayName="Preview inclusive in contracts" Switch="-preview=inclusiveincontracts"
Description="'in' contracts of overridden methods must be a superset of parent contract" />
<BoolProperty Name="PreviewShortenedMethods" Category="Language" DisplayName="Preview shortened method/function syntax" Switch="-preview=shortenedMethods"
Description="allow use of => for methods and top-level functions in addition to lambdas (dmd 2.101+)" />
<BoolProperty Name="PreviewFixImmutableConv" Category="Language" DisplayName="Preview disallowing unsound immutable conversions" Switch="-preview=fixImmutableConv"
Description="disallow unsound immutable conversions that were formerly incorrectly permitted (dmd 2.101+)" />
<BoolProperty Name="PreviewSystemVariables" Category="Language" DisplayName="Preview system variables" Switch="-preview=systemVariables"
Description="disable access to variables marked '@system' from @safe code (dmd 2.102+)" />

<BoolProperty Name="RevertImport" Category="Language" DisplayName="Revert import" Switch="-revert=import"
Description="revert to single phase name lookup." />
Expand Down
5 changes: 5 additions & 0 deletions visuald/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class ProjectOptions
bool preview_markdown; // enable Markdown replacements in Ddoc
bool preview_in; // `in` on parameters means `scope const [ref]` and accepts rvalues
bool preview_inclincontracts; // 'in' contracts of overridden methods must be a superset of parent contract
bool preview_shortenedMethods; // allow => in normal function declarations
bool transition_vmarkdown; // list instances of Markdown replacements in Ddoc

ubyte compiler; // 0: DMD, 1: GDC, 2:LDC
Expand Down Expand Up @@ -486,6 +487,8 @@ class ProjectOptions
cmd ~= " -preview=in";
if (preview_inclincontracts)
cmd ~= " -preview=inclusiveincontracts";
if (preview_shortenedMethods)
cmd ~= " -preview=shortenedMethods";
if (transition_vmarkdown)
cmd ~= " -transition=vmarkdown";

Expand Down Expand Up @@ -1473,6 +1476,7 @@ class ProjectOptions
elem ~= new xml.Element("preview_nosharedaccess", toElem(preview_nosharedaccess));
elem ~= new xml.Element("preview_in", toElem(preview_in));
elem ~= new xml.Element("preview_inclincontracts", toElem(preview_inclincontracts));
elem ~= new xml.Element("preview_shortenedMethods", toElem(preview_shortenedMethods));
elem ~= new xml.Element("transition_vmarkdown", toElem(transition_vmarkdown));

elem ~= new xml.Element("compiler", toElem(compiler));
Expand Down Expand Up @@ -1632,6 +1636,7 @@ class ProjectOptions
fromElem(elem, "preview_markdown", preview_markdown);
fromElem(elem, "preview_in", preview_in);
fromElem(elem, "preview_inclincontracts", preview_inclincontracts);
fromElem(elem, "preview_shortenedMethods", preview_shortenedMethods);
fromElem(elem, "transition_vmarkdown", transition_vmarkdown);

fromElem(elem, "compiler", compiler);
Expand Down
12 changes: 8 additions & 4 deletions visuald/propertypage.d
Original file line number Diff line number Diff line change
Expand Up @@ -1299,8 +1299,9 @@ class DmdLanguagePropertyPage : ProjectPropertyPage
AddControl("", mPreview_nosharedaccess = new CheckBox(mCanvas, "disable access to shared memory objects (DMD 2.088+)"));
AddControl("", mPreview_in = new CheckBox(mCanvas, "'in' on parameters means `scope const [ref]` (dmd 2.092+) and accepts rvalues (dmd 2.094+)"));
AddControl("", mPreview_inclInContracts = new CheckBox(mCanvas, "'in' contracts of overridden methods must be a superset of parent contract (dmd 2.095+)"));
AddControl("", mPreview_shortenedMethods = new CheckBox(mCanvas, "shortened method syntax: allow => in normal function declarations (dmd 2.101+)"));
AddHorizontalLine();
AddControl("", mTransition_import = new CheckBox(mCanvas, "revert to single phase name lookup (DMD 2.071 - 2.087)"));
AddControl("", mRevert_import = new CheckBox(mCanvas, "revert to single phase name lookup (DMD 2.071 - 2.087)"));
AddControl("", mTransition_dtorfields = new CheckBox(mCanvas, "destruct fields of partially constructed objects (DMD 2.083+)"));
AddControl("", mTransition_intpromote = new CheckBox(mCanvas, "fix integral promotions for unary + - ~ operators (DMD 2.078+)"));
AddControl("", mTransition_fixAliasThis = new CheckBox(mCanvas, "when a symbol is resolved, check alias this scope before upper scopes (DMD 2.084+)"));
Expand All @@ -1313,14 +1314,15 @@ class DmdLanguagePropertyPage : ProjectPropertyPage
mDip1000.setChecked(options.dip1000);
mDip1008.setChecked(options.dip1008);
mDip1021.setChecked(options.dip1021);
mTransition_import.setChecked(options.revert_import);
mRevert_import.setChecked(options.revert_import);
mTransition_dtorfields.setChecked(options.preview_dtorfields);
mTransition_intpromote.setChecked(options.preview_intpromote);
mTransition_fixAliasThis.setChecked(options.preview_fixAliasThis);
mPreview_rvaluerefparam.setChecked(options.preview_rvaluerefparam);
mPreview_nosharedaccess.setChecked(options.preview_nosharedaccess);
mPreview_in.setChecked(options.preview_in);
mPreview_inclInContracts.setChecked(options.preview_inclincontracts);
mPreview_shortenedMethods.setChecked(options.preview_shortenedMethods);
}

override int DoApply(ProjectOptions options, ProjectOptions refoptions)
Expand All @@ -1331,14 +1333,15 @@ class DmdLanguagePropertyPage : ProjectPropertyPage
changes += changeOption(mDip1000.isChecked(), options.dip1000, refoptions.dip1000);
changes += changeOption(mDip1008.isChecked(), options.dip1008, refoptions.dip1008);
changes += changeOption(mDip1021.isChecked(), options.dip1021, refoptions.dip1021);
changes += changeOption(mTransition_import.isChecked(), options.revert_import, refoptions.revert_import);
changes += changeOption(mRevert_import.isChecked(), options.revert_import, refoptions.revert_import);
changes += changeOption(mTransition_dtorfields.isChecked(), options.preview_dtorfields, refoptions.preview_dtorfields);
changes += changeOption(mTransition_intpromote.isChecked(), options.preview_intpromote, refoptions.preview_intpromote);
changes += changeOption(mTransition_fixAliasThis.isChecked(), options.preview_fixAliasThis, refoptions.preview_fixAliasThis);
changes += changeOption(mPreview_rvaluerefparam.isChecked(), options.preview_rvaluerefparam, refoptions.preview_rvaluerefparam);
changes += changeOption(mPreview_nosharedaccess.isChecked(), options.preview_nosharedaccess, refoptions.preview_nosharedaccess);
changes += changeOption(mPreview_in.isChecked(), options.preview_in, refoptions.preview_in);
changes += changeOption(mPreview_inclInContracts.isChecked(), options.preview_inclincontracts, refoptions.preview_inclincontracts);
changes += changeOption(mPreview_shortenedMethods.isChecked(), options.preview_shortenedMethods, refoptions.preview_shortenedMethods);
return changes;
}

Expand All @@ -1351,7 +1354,8 @@ class DmdLanguagePropertyPage : ProjectPropertyPage
CheckBox mPreview_nosharedaccess;
CheckBox mPreview_in;
CheckBox mPreview_inclInContracts;
CheckBox mTransition_import;
CheckBox mPreview_shortenedMethods;
CheckBox mRevert_import;
CheckBox mTransition_dtorfields;
CheckBox mTransition_intpromote;
CheckBox mTransition_fixAliasThis;
Expand Down

0 comments on commit 92f1b06

Please sign in to comment.