Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Предупреждения о связанных переменных в образцах #347

Merged
merged 15 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
afc88ce
Отдельно вынесена 'плоская' проверка образца (#290)
penachett Feb 21, 2021
8eae031
Добавлены опции предупреждений (#290)
penachett Feb 22, 2021
da8ae0c
добавлены заглушки под чеки (#290)
penachett Feb 22, 2021
57dfc63
Переделана проверки включённости предупреждений (#290)
penachett Feb 22, 2021
034630a
Микрофикс передачи списка предупреждений (#290)
penachett Feb 22, 2021
58d33af
Проверка внесена в основной checker + добавлен маркер последнего пред…
penachett Feb 26, 2021
8bc6e85
Добавлен флаг для образца в присваивании и пробрасывание контекста (#…
penachett Feb 26, 2021
61b381f
Добавлена замена интервала между e-переменными (#290)
penachett Feb 27, 2021
9b2d89e
Добавлена проверка и выдача предупреждений (#290)
penachett Feb 28, 2021
41e8d28
Добавлены тесты + микрофикс CheckSentenceRec (#290)
penachett Feb 28, 2021
1023313
Убрана выдача предупреждений в условиях (#290)
penachett Feb 28, 2021
6b79c57
Добавлена проверка всех предложений для repeated-maybe (#290)
penachett Feb 28, 2021
9ef7218
Убрана проверка в условиях + рефакторинг (#290)
penachett Mar 4, 2021
8e18a0c
Добавлена РПЗ и презентация (#290)
penachett Mar 5, 2021
5f66943
Микрофикс теста (#290)
penachett Mar 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions autotests/repeated-maybe.WARNING.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
* WARNING repeated-maybe

*$FROM LibraryEx
$EXTERN Map;

$ENTRY Go {
= <TestNotLastSentence (1 2 3) 'a'>
}


TestNotLastSentence {
e.List s.Symbol
= <Map
{
(s.Num s.Symbol) = 'not last sentence';
(s.Num s.Symbol^) = 'last sentence';
}
e.List
>
}

SomeProcessing {
e.Any = e.Any
}
38 changes: 38 additions & 0 deletions autotests/repeated.WARNING.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
* WARNING repeated

*$FROM LibraryEx
$EXTERN Map;

$ENTRY Go {
= <TestAssignment ('a') 'a'>
<TestAssignment2 ('a') 'a'>
<TestAssignment3 ('a') 'a'>
<TestLastSentence (1 2 3) 'a'>
}

TestAssignment {
t.X s.Y = <SomeProcessing t.X s.Y> : t.X s.Y = /* пусто */ ;
}

TestAssignment2 {
t.X s.Y = <SomeProcessing t.X s.Y> : t.X e.B s.Y e.E = /* пусто */ ;
}

TestAssignment3 {
t.X s.Y = <SomeProcessing t.X s.Y> : e.B t.X e.E s.Y = /* пусто */ ;
}

TestLastSentence {
e.List s.Symbol
= <Map
{
(s.Num s.Symbol) = (s.Num 'default symbol');
(s.Num s.Symbol) = (s.Num 'not default symbol (should be)') ;
}
e.List
>
}

SomeProcessing {
e.Any = e.Any
}
33 changes: 33 additions & 0 deletions autotests/repeated.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
* NO-WARNINGS

$ENTRY Go {
= <TestAssignment ('a') 'a'>
<TestAssignment2 ('a') 'a'>
<TestAssignment3 ('a') 'a'>
<TestAssignment4 ('a') 'a'>
<TestAssignment5 ('a') 'a'>
}

TestAssignment {
t.X s.Y = <SomeProcessing t.X s.Y> : t.X^ s.Y^ = /* пусто */ ;
}

TestAssignment2 {
t.X s.Y = <SomeProcessing t.X s.Y> : t.X^ e.B s.Y e.E = /* пусто */ ;
}

TestAssignment3 {
t.X s.Y = <SomeProcessing t.X s.Y> : e.B t.X e.E s.Y^ = /* пусто */ ;
}

TestAssignment4 {
t.X s.Y = <SomeProcessing t.X s.Y> : e.B s.Y e.E = /* пусто */ ;
}

TestAssignment5 {
t.X s.Y = <SomeProcessing t.X s.Y> : e.B t.X s.Y e.E = /* пусто */ ;
}

SomeProcessing {
e.Any = e.Any
}
130 changes: 124 additions & 6 deletions src/compiler/Checker.ref
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ PrepareMessage {
RepVarInSpecPattern s.Mode e.Index
= 'Repeated variable ' s.Mode '.' e.Index ' in specialization pattern';

RepeatedVariable s.Mode e.Index
= 'Repeated variable ' s.Mode '.' e.Index ' in assignment/last sentence';

RepeatedVariableMaybe s.Mode e.Index
= 'Maybe repeated variable ' s.Mode '.' e.Index;

UnnamedVariableInSpecPattern s.Mode e.Index
= 'Unnamed variable ' s.Mode '.' e.Index ' can\'t appear '
'in $SPEC pattern';
Expand Down Expand Up @@ -765,16 +771,25 @@ CheckFunctionBody {

CheckFunctionBodyRec {
(e.ScopeVars) Sentences e.Sentences =
<Map (&CheckSentence e.ScopeVars) e.Sentences>;
<CheckSentenceRec (e.ScopeVars) e.Sentences>;

(e.ScopeVars) NativeBody e.Code =
/* пусто, нет ни имён функций, ни ошибок внутри */;
}

CheckSentenceRec {
(e.ScopeVars) t.LastSentence
= <CheckSentence e.ScopeVars t.LastSentence LastSentence> ;
(e.ScopeVars) t.Sentence e.Sentences
= <CheckSentence e.ScopeVars t.Sentence NotLastSentence>
<CheckSentenceRec (e.ScopeVars) e.Sentences>;
(e.ScopeVars) /* предложений нет (пустая лямбда) */ = /* пусто */ ;
}

CheckSentence {
e.ScopeVars ((e.Pattern) e.Assignments (e.Result) (e.Blocks))
e.ScopeVars ((e.Pattern) e.Assignments (e.Result) (e.Blocks)) e.Flag

= <CheckPattern (e.ScopeVars) <FlatExpr e.Pattern>>
= <CheckPattern (e.ScopeVars) (e.Pattern) e.Flag>
: (e.ScopeVars^) e.PatternFunctionsAndErrors

= <DoCheckAssignments (e.Assignments) (e.ScopeVars) /* нет ошибок */>
Expand Down Expand Up @@ -812,7 +827,7 @@ DoCheckAssignments {

= <CheckBlocks (e.ScopeVars) e.Blocks> : e.BlocksFunctionsAndErrors

= <CheckPattern (e.ScopeVars) <FlatExpr e.Pattern>>
= <CheckPattern (e.ScopeVars) (e.Pattern) s.ChainType>
: (e.ScopeVars^) e.PatternFunctionsAndErrors

= <DoCheckAssignments
Expand Down Expand Up @@ -855,8 +870,104 @@ FlatExpr {
}

CheckPattern {
(e.ScopeVars) (e.Pattern) e.Flag
= <CheckPattern-Flatten (e.ScopeVars) <FlatExpr e.Pattern>>
<CheckPattern-WarnRepeated
(e.ScopeVars)
<WarningIdByFlag e.Flag>
(e.Pattern)
>;
}

CheckPattern-WarnRepeated {
(e.ScopeVars) s.WarningId (e.Pattern)
= <CheckPattern-WarnRepeatedRec (e.ScopeVars) s.WarningId (e.Pattern)>;
(e._) (e._) = /* не нужно проверять */;
}

CheckPattern-WarnRepeatedRec {
(e.ScopeVars) s.WarningId
(e.B (TkVariable t.Pos 'e' e.Index) e.M (TkVariable t.Pos2 'e' e.Index2) e.E)
= <CheckPattern-WarnRepeatedRec
(e.ScopeVars) s.WarningId
<ReducePattern e.B (TkVariable t.Pos 'e' e.Index)
e.M (TkVariable t.Pos2 'e' e.Index2) e.E>
>;

(e.ScopeVars) s.WarningId ((TkVariable e.Info) e.Tail)
= <CheckVariableRepeating (e.ScopeVars) s.WarningId (TkVariable e.Info)>
<CheckPattern-WarnRepeatedRec (e.ScopeVars) s.WarningId (e.Tail)>;

(e.ScopeVars) s.WarningId ((TkNewVariable e.Info) e.Tail)
= <CheckPattern-WarnRepeatedRec (e.ScopeVars) s.WarningId (e.Tail)>;

(e.ScopeVars) s.WarningId ((Symbol e.Info) e.Tail)
= <CheckPattern-WarnRepeatedRec (e.ScopeVars) s.WarningId (e.Tail)>;

(e.ScopeVars) s.WarningId ((Brackets e.InBrackets) e.Tail)
= <CheckPattern-WarnRepeatedRec (e.ScopeVars) s.WarningId (e.InBrackets)>
<CheckPattern-WarnRepeatedRec (e.ScopeVars) s.WarningId (e.Tail)>;

(e.ScopeVars) s.WarningId ((ADT-Brackets t.SrcPos (e.Name) e.InBrackets) e.Tail)
= <CheckPattern-WarnRepeatedRec (e.ScopeVars) s.WarningId (e.InBrackets)>
<CheckPattern-WarnRepeatedRec (e.ScopeVars) s.WarningId (e.Tail)>;

(e.ScopeVars) s.WarningId () = /* предложения кончились */;
}


ReducePattern {
e.Pattern
= <FindLastE e.Pattern> : t.LastE
= <ReplaceInterval t.LastE e.Pattern>;
}

FindLastE {
e.Pattern
= <Reduce
{
t.LastElem (TkVariable t.Pos 'e' e.Index)
= (TkVariable t.Pos 'e' e.Index);
t.LastElem (e.Another) = t.LastElem;
}
()
e.Pattern
>
}

ReplaceInterval {
t.LastElem
e.B (TkVariable t.Pos 'e' e.Index) e.M t.LastElem e.E
= (e.B (TkVariable t.Pos 'e' '_') e.E);
}

WarningIdByFlag {
Assign = RepeatedVariable;
LastSentence = RepeatedVariable;
NotLastSentence = RepeatedVariableMaybe;
Condition = /* пусто */;
/* пусто */ = /* пусто */;
}

CheckVariableRepeating {
(e.ScopeVars) s.WarningId (TkVariable t.SrcPos s.Mode '_' e.Index) = ;

(e.Vars-B (s.Mode e.Index) e.Vars-E) s.WarningId
(TkVariable t.SrcPos s.Mode e.Index)
= (Warning <WarningNameForId s.WarningId>
t.SrcPos s.WarningId s.Mode e.Index);

e._ = ;
}

WarningNameForId {
RepeatedVariable = repeated;
RepeatedVariableMaybe = repeated-maybe;
}

CheckPattern-Flatten {
(e.ScopeVars) e.Items-B (TkNewVariable t.SrcPos s.Mode '_' e.Index) e.Items-E
= <CheckPattern
= <CheckPattern-Flatten
(e.ScopeVars)
e.Items-B
(TkVariable t.SrcPos s.Mode '_' e.Index)
Expand All @@ -867,7 +978,7 @@ CheckPattern {
(e.ScopeVars)
e.Items-B (TkVariable t.SrcPos1 s.Mode1 e.Index) e.Items-M
(TkNewVariable t.SrcPos2 s.Mode2 e.Index) e.Items-E =
<CheckPattern
<CheckPattern-Flatten
(e.ScopeVars)
e.Items-B (TkVariable t.SrcPos1 s.Mode1 e.Index) e.Items-M
(TkVariable t.SrcPos2 s.Mode2 e.Index)
Expand Down Expand Up @@ -984,6 +1095,13 @@ CheckValidUsings {
e.NameRefsAndErrors
>;

(e.DeclarationsAndErrors)
(Warning s.WarningId t.SrcPos s.Type e.Info) e.NameRefsAndErrors =
<CheckValidUsings
(e.DeclarationsAndErrors (Warning s.WarningId t.SrcPos s.Type e.Info))
e.NameRefsAndErrors
>;

(e.DeclarationsAndErrors) /* кончились ошибки и имена */ =
<Map
{
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/Config.ref
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ $ENTRY Config-GetWarningIds {

e.WarningName ::= 'no-'? e.Error | 'no-'? e.WarningIdName | 'all'
e.Error ::= 'error' ('=' e.WarningName)?
e.WarningIdName :: = 'screening' | 'nul-in-compound'
e.WarningIdName :: = 'screening' | 'nul-in-compound' | 'repeated' | 'repeated-maybe'

*/
$ENTRY Config-SetWarning {
Expand Down Expand Up @@ -534,12 +534,14 @@ WarningForName {
'ignored-pseudocomments' = True ignored-pseudocomments;
'pseudofunctions' = True pseudofunctions;
'pseudofunction' = True pseudofunctions; /* синоним */
'repeated' = True repeated;
'repeated-maybe' = True repeated-maybe;

e.Other = False
}

$ENTRY Config-AllWarningIds {
/* пусто */ = (screening nul-in-compound)
/* пусто */ = (screening nul-in-compound repeated repeated-maybe)
}

WarningIds-Add {
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/Error.ref
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ $EXTERN Config-AllWarningIds;
s.WarningId ::=
screening
| nul-in-compound
| repeated
| repeated-maybe
*/
$ENUM ErrorList;

Expand Down
5 changes: 5 additions & 0 deletions src/compiler/ParseCmdLine.ref
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ $ENTRY ParseCommandLine {
s.Pos
'option -W expects \'all\', \'[no-]error[=...]\', '
'\'[no-]screening\', \'[no-]pseudofunctions\' '
'\'[no-]repeated\', \'[no-]repeated-maybe\' '
'\'[no-]nul-in-compound\', but got \'' e.BadValue '\''
);

Expand Down Expand Up @@ -386,6 +387,10 @@ PrintHelp {
' (enabled by default)\n'
' -Wpseudofunctions, -Wno-... - check/don\'t pseudofunction\n'
' correctness (enabled by default)\n'
' -Wrepeated, -Wno-... - check/don\'t repeated variables\n'
' in assignments/last sentences (disabled by default)\n'
' -Wrepeated-maybe, -Wno-... - check/don\'t repeated variables\n'
' (disabled by default)\n'
' -Werror[=...], -Wno-error[=...] - treat/don\'t all or only provided\n'
' warning(s) as error(s)\n'
'-p, --prefix prefix-name\n'
Expand Down