Skip to content

Commit

Permalink
Псевдокомментарии \*\$(NO-)?(OPT|DRIVE|SPEC) (#195, #314)
Browse files Browse the repository at this point in the history
После псевдокомментария может следовать любое количество имён, запятых
и точек с запятой (знаки пунктуации игнорируются), имя должно быть
как минимум одно.
  • Loading branch information
Mazdaywik committed Aug 22, 2021
1 parent 84c8d7b commit edd0579
Show file tree
Hide file tree
Showing 27 changed files with 359 additions and 74 deletions.
19 changes: 19 additions & 0 deletions autotests/opt-tree-no-drive.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
* TREE

$ENTRY Go {
/* empty */ = /* empty */;

X = <Test '******************************' ()>;
}

*$NODRIVE Test, Double

Test {
'*' e.Count (e.Acc) = <Test e.Count (<Double (e.Acc)>)>;

/* empty */ (e.Acc) = e.Acc;
}

Double {
(e.Acc) = (e.Acc) (e.Acc)
}
15 changes: 15 additions & 0 deletions autotests/opt-tree-no-opt-misplaced.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* TREE

$ENTRY Go {
/* empty */ = /* empty */;

X = <Test '******************************' ()>;
}

Test {
'*' e.Count (e.Acc) = <Test e.Count ((e.Acc) (e.Acc))>;

*$NOOPT Test

/* empty */ (e.Acc) = e.Acc;
}
15 changes: 15 additions & 0 deletions autotests/opt-tree-no-opt.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* TREE

$ENTRY Go {
/* empty */ = /* empty */;

X = <Test '******************************' ()>;
}

*$NOOPT Test

Test {
'*' e.Count (e.Acc) = <Test e.Count ((e.Acc) (e.Acc))>;

/* empty */ (e.Acc) = e.Acc;
}
16 changes: 16 additions & 0 deletions autotests/opt-tree-no-spec.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
* TREE

$ENTRY Go {
/* empty */ = /* empty */;

X = <Test '******************************' ()>;
}

*$NODRIVE Test
*$NOSPEC Test

Test {
'*' e.Count (e.Acc) = <Test e.Count ((e.Acc) (e.Acc))>;

/* empty */ (e.Acc) = e.Acc;
}
12 changes: 0 additions & 12 deletions autotests/pseudocomments-error-misplaced.BAD-SYNTAX.ref

This file was deleted.

2 changes: 2 additions & 0 deletions autotests/pseudocomments-ok-multiline.ref
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* NO-WARNINGS

*$EXTENDED;

*$DRIVE Foo,
Expand Down
4 changes: 3 additions & 1 deletion autotests/pseudocomments-ok.ref
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
* NO-WARNINGS

*$EXTENDED;

*$SPEC Func s.STAT (s.dyn);
*$SPEC Func;,;,;

Func {
s.Stat (s.Dyn) = s.Stat s.Dyn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* WARNING ignored-pseudocomments
* WARNING pseudocomment

*$CLASSIC;

Expand Down
6 changes: 6 additions & 0 deletions autotests/pseudocomments-warning-conflict.WARNING.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* WARNING pseudocomment

*$SPEC S;
*$NOSPEC S;

$ENTRY S { = }
5 changes: 5 additions & 0 deletions autotests/pseudocomments-warning-dangling.WARNING.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* WARNING pseudocomment

*$OPT Undefined;

$ENTRY Go { = }
7 changes: 7 additions & 0 deletions autotests/pseudocomments-warning-empty.WARNING.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* WARNING pseudocomment

*$OPT

$ENTRY Test {
/* empty */ = /* empty */
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
* WARNING nul-in-compound
* WARNING pseudocomment

*$EXTENDED;

*$SPEC Func s.STAT "ABC\x00DEF" s.dyn;
*$SPEC Func "unclosed quote;

$ENTRY Func {
s.Stat ABC s.Dyn = s.Stat s.Dyn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
* WARNING pseudocomment

*$EXTENDED;

*$SPEC Func s.STAT 'unclosed quote;
*$SPEC Func "ABC\x00DEF";

$ENTRY Func {
s.Stat ABC s.Dyn = s.Stat s.Dyn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* WARNING pseudocomment

*$EXTENDED;

*$DRIVE D; $INLINE F;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* WARNING pseudocomment

*$EXTENDED;

*$SPEC Func s.STAT (s.dyn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* WARNING pseudocomment

*$EXTENDED;

*$SPEC Func (s.STAT) s.dyn;
Expand Down
101 changes: 100 additions & 1 deletion src/compiler/Checker.ref
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ PrepareMessage {
IntrinsicForDefined e.Name
= 'Function ' e.Name ' is defined, '
'$INTRINSIC declaration for it will be ignored';

OptFeaturesConflict s.Label1 s.Label2 e.Name
= 'Conflict between pseudocomments '
'$' <Upper <Explode s.Label1>> ' ' e.Name '; and '
'$' <Upper <Explode s.Label2>> ' ' e.Name ';, '
'$NO... pseudocomment has priority';

DanglingOptPseudocomment s.Label e.Name
= '$' <Upper <Explode s.Label>> ' ' e.Name '; label for missed function';
}

FindErrors {
Expand All @@ -146,7 +155,9 @@ CheckPseudofunctions {
= <Map
{
(s.Tag t.SrcPos s.ScopeClass e.Name)
, LegacyDrive LegacyInline Intrinsic : e._ s.Tag e._
, Opt Drive Spec NoOpt NoDrive NoSpec
LegacyDrive LegacyInline Intrinsic
: e._ s.Tag e._
, <Pseudofunctions> : e._ (e.Name) e._
= (Error t.SrcPos TaggedPseudofunction s.Tag e.Name);

Expand Down Expand Up @@ -557,6 +568,15 @@ SeparateDefines {
(e.Declarations) (LegacyDrive t.SrcPos s.ScopeClass e.Name) =
(e.Declarations (LegacyDrive t.SrcPos e.Name));

(e.Declarations) (s.OptNode t.SrcPos e.Name)
, (Opt Drive Spec Yes) (Drive Drive Yes) (Spec Spec Yes)
(NoOpt Drive Spec No) (NoDrive Drive No) (NoSpec Spec No)
: e._ (s.OptNode e.Features s.Enable) e._
= (
e.Declarations
(Opt s.OptNode (e.Features) s.Enable t.SrcPos e.Name)
);

(e.Declarations) (Intrinsic t.SrcPos s.ScopeClass e.Name) =
(e.Declarations (Intrinsic t.SrcPos e.Name));

Expand Down Expand Up @@ -585,6 +605,9 @@ CheckDeclarations {
&CheckRedefinitions
&FindFinalInitEntry
&CheckIntrinsics
&CheckConflictOptPseudocomments
&CleanupValidOptPseudocomments
&CheckDanglingOptPseudocomments
>
>
}
Expand Down Expand Up @@ -804,6 +827,82 @@ CheckIntrinsics {
e.Declarations = e.Declarations;
}

CheckConflictOptPseudocomments {
e.Declarations-B
(Opt s.OptNode1 (e.Feat1-B s.Feature e.Feat1-E) Yes t.YesPos e.Name)
e.Declarations-M
(Opt s.OptNode2 (e.Feat2-B s.Feature e.Feat2-E) No t.NoPos e.Name)
e.Declarations-E
= <CheckConflictOptPseudocomments
e.Declarations-B
(Opt s.OptNode1 (e.Feat1-B e.Feat1-E) Yes t.YesPos e.Name)
(Warning
pseudocomment t.YesPos OptFeaturesConflict s.OptNode1 s.OptNode2
e.Name
)
e.Declarations-M
(Opt s.OptNode2 (e.Feat2-B s.Feature e.Feat2-E) No t.NoPos e.Name)
e.Declarations-E
>;

e.Declarations-B
(Opt s.OptNode1 (e.Feat1-B s.Feature e.Feat1-E) No t.NoPos e.Name)
e.Declarations-M
(Opt s.OptNode2 (e.Feat2-B s.Feature e.Feat2-E) Yes t.YesPos e.Name)
e.Declarations-E
= <CheckConflictOptPseudocomments
e.Declarations-B
(Opt s.OptNode1 (e.Feat1-B s.Feature e.Feat1-E) No t.NoPos e.Name)
e.Declarations-M
(Opt s.OptNode2 (e.Feat2-B e.Feat2-E) Yes t.YesPos e.Name)
(Warning
pseudocomment t.YesPos OptFeaturesConflict s.OptNode1 s.OptNode2
e.Name
)
e.Declarations-E
>;

e.Declarations-B (Opt s._ () Yes t._ e._) e.Declarations-E
= <CheckConflictOptPseudocomments e.Declarations-B e.Declarations-E>;

e.Declarations = e.Declarations;
}

CleanupValidOptPseudocomments {
e.Declarations-B
(Opt s.OptNode (e.Features) s.Enable t.OptPos e.Name) e.Declarations-M
(Define t.SrcPos s.ScopeClass e.Name) e.Declarations-E
= <CleanupValidOptPseudocomments
e.Declarations-B e.Declarations-M
(Define t.SrcPos s.ScopeClass e.Name) e.Declarations-E
>;

e.Declarations-B
(Define t.SrcPos s.ScopeClass e.Name) e.Declarations-M
(Opt s.OptNode (e.Features) s.Enable t.OptPos e.Name) e.Declarations-E
= <CleanupValidOptPseudocomments
e.Declarations-B
(Define t.SrcPos s.ScopeClass e.Name) e.Declarations-M e.Declarations-E
>;

e.Declarations = e.Declarations;
}

CheckDanglingOptPseudocomments {
e.Declarations
= <Map
{
(Opt s.OptNode (e._) s._ t.Pos e.Name)
= (Warning
pseudocomment t.Pos DanglingOptPseudocomment s.OptNode e.Name
);

t.Declaration = t.Declaration;
}
e.Declarations
>
}

CheckFunctionBody {
(e.Body) =
<CheckFunctionBodyRec (<gen_e__ /* vars */>) e.Body>;
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/Config.ref
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ $ENTRY Config-Create {
(Optimize /* пусто */)
(WarningIds
nul-in-compound pseudofunctions repeated deprecated intrinsic
pseudocomment
)
(WarningIdsAsErrors /* пусто */)
(ErrorFile /* пусто */)
Expand Down Expand Up @@ -533,7 +534,7 @@ ValidWarningId {
WarningForName {
'screening' = True screening;
'nul-in-compound' = True nul-in-compound;
'ignored-pseudocomments' = True ignored-pseudocomments;
'pseudocomment' = True pseudocomment;
'pseudofunctions' = True pseudofunctions;
'pseudofunction' = True pseudofunctions; /* синоним */
'repeated' = True repeated;
Expand Down
17 changes: 17 additions & 0 deletions src/compiler/Desugaring.ref
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ $ENTRY Pass-RemovePos {

(LegacySpec t.SrcPos (e.Name) e.Pattern) = (LegacySpec e.Name);

(s.OptMarkup t.SrcPos e.Name)
, Opt Drive Spec NoOpt NoDrive NoSpec : e._ s.OptMarkup e._
= (s.OptMarkup e.Name);

(s.EnumSwapDeclaration t.SrcPos s.ScopeClass e.Name)
= (s.EnumSwapDeclaration s.ScopeClass e.Name);
}
Expand Down Expand Up @@ -812,6 +816,12 @@ Pass-CollectDeclarations {
(Intrinsic e.Name) = (GROUP Intrinsics (e.Name));
(LegacySpec e.Name) = (GROUP Specs (e.Name));

(s.OptMarkup e.Name)
, (Opt Drives Specs) (Drive Drives) (Spec Specs)
(NoOpt NoDrives NoSpecs) (NoDrive NoDrives) (NoSpec NoSpecs)
: e._ (s.OptMarkup e.Groups) e._
= <Map { s.Group = (GROUP s.Group (e.Name)) } e.Groups>;

(Function (e.Name) e.Body)
= (GROUP DefinedFunctions (e.Name)) (Function (e.Name) e.Body);

Expand All @@ -828,6 +838,8 @@ Pass-CollectDeclarations {
(GROUP Inlines)
(GROUP Intrinsics)
(GROUP Specs)
(GROUP NoDrives)
(GROUP NoSpecs)
(GROUP DefinedFunctions)
>
: e.AST^
Expand All @@ -836,13 +848,17 @@ Pass-CollectDeclarations {
(GROUP Inlines e.Inlines)
(GROUP Intrinsics e.Intrinsics)
(GROUP Specs e.Specs)
(GROUP NoDrives e.NoDrives)
(GROUP NoSpecs e.NoSpecs)
(GROUP DefinedFunctions e.DefinedFunctions)

= <Unique e.Externs> : e.Externs^
= <Unique e.Drives> : e.Drives^
= <Unique e.Inlines> : e.Inlines^
= <Unique e.Intrinsics> : e.Intrinsics^
= <Unique e.Specs> : e.Specs^
= <Unique e.NoDrives> : e.NoDrives^
= <Unique e.NoSpecs> : e.NoSpecs^

= <Set-Reject (e.Externs) (e.DefinedFunctions)> : e.Externs^
= <Set-Reject (e.Inlines) (e.Drives)> : e.Inlines^
Expand All @@ -851,6 +867,7 @@ Pass-CollectDeclarations {
= (Externs e.Externs)
(Drives e.Drives) (Inlines e.Inlines) (Intrinsics e.Intrinsics)
(Specs e.Specs)
(NoDrives e.NoDrives) (NoSpecs e.NoSpecs)
e.AST
}

Expand Down
Loading

0 comments on commit edd0579

Please sign in to comment.