Skip to content

Commit bfd0706

Browse files
committed
Small rules refactoring
1 parent d66cdfd commit bfd0706

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+151
-100
lines changed

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2022 Ivan Kniazkov
3+
Copyright (c) 2023 Ivan Kniazkov
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

pom.xml

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!--
33
The MIT License (MIT)
44
5-
Copyright (c) 2022 Ivan Kniazkov
5+
Copyright (c) 2023 Ivan Kniazkov
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
@@ -149,12 +149,13 @@ SOFTWARE.
149149
<plugin>
150150
<groupId>org.cqfn</groupId>
151151
<artifactId>astranaut-maven-plugin</artifactId>
152-
<version>0.1.10</version>
152+
<version>0.1.15</version>
153153
<configuration>
154-
<dsl>${basedir}/src/main/dsl/rules.dsl</dsl>
154+
<dsl>${basedir}/src/main/dsl/uast.dsl</dsl>
155155
<output>${basedir}/src/main/java</output>
156156
<version>0.1</version>
157157
<pkg>org.cqfn.uast.tree</pkg>
158+
<dbginfo>true</dbginfo>
158159
</configuration>
159160
<executions>
160161
<execution>
@@ -170,7 +171,7 @@ SOFTWARE.
170171
<dependency>
171172
<groupId>org.cqfn</groupId>
172173
<artifactId>astranaut-core</artifactId>
173-
<version>1.0.5</version>
174+
<version>1.0.6</version>
174175
</dependency>
175176
<dependency>
176177
<groupId>org.junit.jupiter</groupId>

src/main/dsl/rules.dsl src/main/dsl/uast.dsl

+105-55
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,107 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2023 Ivan Kniazkov
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
/*
26+
I. Unified AST description
27+
28+
1. Literals
29+
*/
30+
131
IntegerLiteral <- $int$, $String.valueOf(#)$, $Integer.parseInt(#)$, $NumberFormatException$;
232
Identifier <- $String$, $#$, $#$;
333
StringLiteral <- $String$, $#$, $#$;
434
Modifier <- $String$, $#$, $#$;
535
PrimitiveType <- $String$, $#$, $#$;
636

37+
Name <- [composition@Name], last@Identifier;
38+
39+
/*
40+
2. Program structure
41+
*/
42+
743
Program <- {ProgramItem};
844
ProgramItem <- ClassDeclaration | Statement | ClassItem;
45+
ClassDeclaration <- [modifiers@ModifierBlock], name@Identifier, [extendsbl@ExtendsBlock], [implementsbl@ImplementsBlock], body@ClassBody;
46+
ModifierBlock <- {Modifier};
47+
Parameter <- [modifiers@ModifierBlock], [datatype@TypeName], name@Identifier;
48+
ParameterBlock <- {Parameter};
49+
ExtendsBlock <- {ClassType};
50+
ImplementsBlock <- {ClassType};
51+
ThrowsBlock <- {Exception};
52+
ClassBody <- {ClassItem};
53+
ClassItem <- FunctionDeclaration | FieldDeclaration;
54+
FunctionDeclaration <- [modifiers@ModifierBlock], [datatype@TypeName], name@Identifier, parameters@ParameterBlock, [throwsbl@ThrowsBlock], body@StatementBlock;
55+
FieldDeclaration <- [modifiers@ModifierBlock], [datatype@TypeName], declarators@DeclaratorList;
56+
DeclaratorList <- {Declarator};
57+
Declarator <- name@Identifier, [value@Expression];
58+
Exception <- name@ClassType;
959

60+
/*
61+
3. Data types
62+
*/
63+
64+
TypeName <- ArrayType | PrimitiveType | ClassType | VoidType;
65+
ArrayType <- base@TypeName, dimensions@DimensionList;
66+
ClassType <- name@Name;
67+
VoidType <- 0;
68+
DimensionList <- {Dimension};
69+
Dimension <- [expression@Expression];
70+
71+
/*
72+
4. Statements
73+
*/
74+
75+
Statement <- Return | StatementBlock | VariableDeclaration | ExpressionStatement | IfElse;
76+
Return <- [expression@Expression];
77+
StatementBlock <- {Statement};
78+
VariableDeclaration <- [modifiers@ModifierBlock], [datatype@TypeName], declarators@DeclaratorList;
79+
ExpressionStatement <- expression@Expression;
80+
IfElse <- condition@Expression, ifBranch@Statement, [elseBranch@Statement];
81+
82+
/*
83+
5. Expressions
84+
*/
85+
86+
ExpressionList <- {Expression};
1087
Expression <- BinaryExpression | IntegerLiteral | This | StringLiteral | Identifier | NullLiteral
1188
| FunctionCall | UnaryExpression | BitwiseExpression | LogicalExpression | AssignableExpression | Assignment
1289
| ParenthesizedExpression | ObjectCreationExpression | ArrayInitializer;
1390
ArithmeticExpression <- Addition | Subtraction | Multiplication | Division | Modulus;
1491
BinaryExpression <- ArithmeticExpression | RelationalExpression;
1592
RelationalExpression <- IsEqualTo | NotEqualTo | GreaterThan | LessThan | GreaterThanOrEqualTo | LessThanOrEqualTo;
16-
Statement <- Return | StatementBlock | VariableDeclaration | ExpressionStatement | IfElse;
17-
TypeName <- ArrayType | PrimitiveType | ClassType | VoidType;
1893
UnaryExpression <- PreIncrement | PreDecrement | PostIncrement | PostDecrement | Positive | Negative;
1994
BitwiseExpression <- BitwiseComplement | LeftShift | RightShift | UnsignedRightShift | BitwiseAnd | BitwiseOr | ExclusiveOr;
2095
LogicalExpression <- LogicalAnd | LogicalOr | LogicalNot;
2196
Assignment <- SimpleAssignment | AdditionAssignment | SubtractionAssignment | MultiplicationAssignment
2297
| DivisionAssignment | ModulusAssignment | BitwiseAndAssignment | BitwiseOrAssignment | ExclusiveOrAssignment
2398
| RightShiftAssignment | UnsignedRightShiftAssignment | LeftShiftAssignment;
2499
AssignableExpression <- Variable | PropertyAccess;
25-
26-
ExpressionStatement <- expression@Expression;
27100
ParenthesizedExpression <- expression@Expression;
28101

102+
This <- 0;
103+
NullLiteral <- 0;
104+
29105
Addition <- left@Expression, right@Expression;
30106
Subtraction <- left@Expression, right@Expression;
31107
Multiplication <- left@Expression, right@Expression;
@@ -71,46 +147,28 @@ UnsignedRightShiftAssignment <- left@AssignableExpression, right@Expression;
71147
RightShiftAssignment <- left@AssignableExpression, right@Expression;
72148
LeftShiftAssignment <- left@AssignableExpression, right@Expression;
73149

74-
ClassType <- name@Name;
75-
ArrayType <- base@TypeName, dimensions@DimensionList;
76-
DimensionList <- {Dimension};
77-
Dimension <- [expression@Expression];
78-
Return <- [expression@Expression];
79-
IfElse <- condition@Expression, ifbranch@Statement, [elsebranch@Statement];
80-
Name <- [composition@Name], last@Identifier;
81150
Variable <- Name;
82-
StatementBlock <- {Statement};
83-
This <- 0;
84-
VoidType <- 0;
85-
NullLiteral <- 0;
86-
PropertyAccess <- left@Expression, right@Expression;
87-
ModifierBlock <- {Modifier};
88-
ExpressionList <- {Expression};
89-
ArrayInitializer <- {Expression};
90151
FunctionCall <- [owner@Name], name@Identifier, arguments@ExpressionList;
91-
Parameter <- [modifiers@ModifierBlock], [datatype@TypeName], name@Identifier;
92-
FunctionDeclaration <- [modifiers@ModifierBlock], [datatype@TypeName], name@Identifier, parameters@ParameterBlock, [throwsbl@ThrowsBlock], body@StatementBlock;
93-
ParameterBlock <- {Parameter};
94-
ClassDeclaration <- [modifiers@ModifierBlock], name@Identifier, [extendsbl@ExtendsBlock], [implementsbl@ImplementsBlock], body@ClassBody;
95-
ExtendsBlock <- {ClassType};
96-
ImplementsBlock <- {ClassType};
97-
ThrowsBlock <- {Exception};
98-
ClassBody <- {ClassItem};
99-
ClassItem <- FunctionDeclaration | FieldDeclaration;
100-
FieldDeclaration <- [modifiers@ModifierBlock], [datatype@TypeName], declarators@DeclaratorList;
101-
VariableDeclaration <- [modifiers@ModifierBlock], [datatype@TypeName], declarators@DeclaratorList;
102-
DeclaratorList <- {Declarator};
103-
Declarator <- name@Identifier, [value@Expression];
104-
Exception <- name@ClassType;
105152
ObjectCreationExpression <- datatype@TypeName, [arguments@ExpressionList];
153+
PropertyAccess <- left@Expression, right@Expression;
154+
ArrayInitializer <- {Expression};
155+
156+
/*
157+
II. Java
158+
159+
1. Red nodes
160+
*/
106161

107162
java:
108163

109164
Synchronized <- expression@Expression, body@StatementBlock;
110165
Statement <- & | Synchronized;
111166

112-
IntegerLiteralExpr<#1> -> IntegerLiteral<#1>;
167+
/*
168+
2. Transformation rules
169+
*/
113170

171+
IntegerLiteralExpr<#1> -> IntegerLiteral<#1>;
114172

115173
EnclosedExpr(#1) -> ParenthesizedExpression(#1);
116174

@@ -275,17 +333,11 @@ Modifier<#1> -> Modifier<#1>;
275333
NullLiteralExpr -> NullLiteral;
276334
IfStmt(#1, #2) -> IfElse(#1, #2);
277335

278-
// Arrays
279-
280336
ArrayType(#1) -> ArrayType(#1, DimensionList(Dimension));
281337
ArrayInitializerExpr(#1...) -> ArrayInitializer(#1);
282338

283-
//
284-
285339
CompilationUnit(#1) -> Program(#1);
286340

287-
// Class declaration ClassDeclaration <- [ModifierBlock], Identifier, [ExtendsBlock], [ImplementsBlock], ClassBody;
288-
289341
ClassOrInterfaceDeclaration(Modifier#1, #2, InterfaceType(#3)) ->
290342
ClassDeclaration(ModifierBlock(#1), #2, ImplementsBlock(ClassType(Name(#3))), ClassBody);
291343

@@ -297,8 +349,6 @@ ClassOrInterfaceDeclaration(Modifier#1, #2, #3...) ->
297349

298350
ClassOrInterfaceDeclaration(#1, #2...) -> ClassDeclaration(#1, ClassBody(#2));
299351

300-
// Field and variable declaration
301-
302352
ObjectCreationExpr(#1) -> ObjectCreationExpression(#1);
303353
ObjectCreationExpr(#1, #2...) -> ObjectCreationExpression(#1, ExpressionList(#2));
304354

@@ -314,8 +364,6 @@ VariableDeclarationExpr(VariableDeclarator(#1, #2, #3)) -> VariableDeclaration(#
314364
VariableDeclarationExpr(Modifier#3, VariableDeclarator(#1, #2)) -> VariableDeclaration(ModifierBlock(#3), #1, DeclaratorList(Declarator(#2)));
315365
VariableDeclarationExpr(Modifier#4, VariableDeclarator(#1, #2, #3)) -> VariableDeclaration(ModifierBlock(#4), #1, DeclaratorList(Declarator(#2, #3)));
316366

317-
// Function declaration FunctionDeclaration <- [modifiers@ModifierBlock], [typename@TypeName], name@Identifier, parameters@ParameterBlock, body@StatementBlock;
318-
319367
MethodDeclaration(Modifier#1, #2, Parameter#3, #4, #5) ->
320368
FunctionDeclaration(ModifierBlock(#1), #4, #2, ParameterBlock(#3), #5);
321369
MethodDeclaration(Modifier#1, #2, Parameter#3, Exception#6, #4, #5) ->
@@ -324,18 +372,24 @@ MethodDeclaration(Modifier#1, #2, Parameter#3, Exception#6, #4, #5) ->
324372
ConstructorDeclaration(Modifier#1, #2, Parameter#3, #4) ->
325373
FunctionDeclaration(ModifierBlock(#1), #2, ParameterBlock(#3), #4);
326374

375+
/*
376+
III. JavaScript
377+
378+
1. Red nodes
379+
*/
380+
327381
js:
328382

329383
ClassItem <- & | Property;
330384
Expression <- & | ObjectLiteral;
331385
ObjectLiteral <- {Property};
332-
// PropertyList <- {Property};
333-
//ObjectLiteral <- 0;
334386
Property <- name@Identifier, value@Expression;
335387
Yield <- Expression;
336388

337-
// ObjectCreationExpr(#1, #2...) -> ObjectCreationExpression(#1, ExpressionList(#2));
338-
// ObjectCreationExpression <- datatype@TypeName, [arguments@ExpressionList];
389+
/*
390+
2. Transformation rules
391+
*/
392+
339393
propertyAssignment(propertyName(identifierName(#1)), #2) -> Property(#1, #2);
340394
objectLiteral(#1...) -> ObjectLiteral(#1);
341395
singleExpression(literal<"new">, Variable(#1), arguments(#2...)) ->
@@ -470,7 +524,6 @@ singleExpression(#1, literal<"--">) -> PostDecrement(#1);
470524
singleExpression(literal<"-">, #1) -> Negative(#1);
471525
singleExpression(literal<"+">, #1) -> Positive(#1);
472526

473-
474527
identifier(literal<#1>) -> Identifier<#1>;
475528

476529
singleExpression(#1, literal<"=">, #2) -> SimpleAssignment(#1, #2);
@@ -517,8 +570,6 @@ program(sourceElements(#1...)) -> Program(#1);
517570

518571
returnStatement(literal<"return">, expressionSequence(#1)) -> Return(#1);
519572

520-
// Class declaration ClassDeclaration <- [ModifierBlock], Identifier, [ExtendsBlock], [ImplementsBlock], ClassBody;
521-
522573
classDeclaration(literal<"class">, #1, classTail(literal<"extends">, Variable(#2)))
523574
-> ClassDeclaration(#1, ExtendsBlock(ClassType(#2)), ClassBody);
524575
classDeclaration(literal<"class">, #1, classTail(#2, classElement(emptyStatement_)))
@@ -528,8 +579,6 @@ classDeclaration(literal<"class">, #1, classTail(#2...)) -> ClassDeclaration(#1,
528579
classElement(propertyName(identifierName(#1)), literal<"=">, #2) -> Property(#1, #2);
529580
classElement(#1) -> #1;
530581

531-
// Function declaration FunctionDeclaration <- [modifiers@ModifierBlock], [typename@TypeName], name@Identifier, parameters@ParameterBlock, body@StatementBlock;
532-
533582
functionBody(sourceElements(sourceElement(statement(expressionStatement(expressionSequence(#1)))))) ->
534583
StatementBlock(#1);
535584
functionBody(sourceElements(sourceElement(statement(#1)))) ->
@@ -547,6 +596,9 @@ methodDefinition(propertyName(identifierName(#1)), #2, #3) -> FunctionDeclarati
547596
formalParameterArg(assignable(#1)) -> Parameter(#1);
548597
formalParameterList(#1...) -> ParameterBlock(#1);
549598

599+
/*
600+
IV. Python
601+
*/
550602

551603
python:
552604

@@ -656,8 +708,6 @@ file_input(#1, small_stmt(#2)) -> Program(#1, #2);
656708

657709
file_input(#1...) -> Program(#1);
658710

659-
// Class declaration ClassDeclaration <- [ModifierBlock], Identifier, [ExtendsBlock], [ImplementsBlock], ClassBody;
660-
661711
classdef(literal<"class">, name(literal<#1>), suite(small_stmt(literal<"pass">)))
662712
-> ClassDeclaration(Identifier<#1>, ClassBody);
663713

src/main/java/org/cqfn/uast/Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2022 Ivan Kniazkov
4+
* Copyright (c) 2023 Ivan Kniazkov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/org/cqfn/uast/algorithms/Algorithm.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2022 Ivan Kniazkov
4+
* Copyright (c) 2023 Ivan Kniazkov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/org/cqfn/uast/algorithms/Carrying.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2022 Ivan Kniazkov
4+
* Copyright (c) 2023 Ivan Kniazkov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/org/cqfn/uast/algorithms/Greening.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2022 Ivan Kniazkov
4+
* Copyright (c) 2023 Ivan Kniazkov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/org/cqfn/uast/algorithms/package-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2022 Ivan Kniazkov
4+
* Copyright (c) 2023 Ivan Kniazkov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/org/cqfn/uast/cli/AlgorithmConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2022 Ivan Kniazkov
4+
* Copyright (c) 2023 Ivan Kniazkov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/org/cqfn/uast/cli/FileConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2022 Ivan Kniazkov
4+
* Copyright (c) 2023 Ivan Kniazkov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/org/cqfn/uast/cli/ImagePathValidator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2022 Ivan Kniazkov
4+
* Copyright (c) 2023 Ivan Kniazkov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)