Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
261 commits
Select commit Hold shift + click to select a range
1a3aaf6
Refactor do loop AST representation
Process-ing Jul 7, 2026
8d7785b
Refactor subroutine AST representation
Process-ing Jul 7, 2026
c716ef9
Add tests for comments
Process-ing Jul 7, 2026
7e77fde
Regenerate dump for comment test
Process-ing Jul 7, 2026
20296eb
Add support for leading comments
Process-ing Jul 7, 2026
e0e4f30
Add support for program final comments
Process-ing Jul 7, 2026
24bd4db
Update comment test
Process-ing Jul 7, 2026
dcd1080
Regenerate dumps
Process-ing Jul 7, 2026
4bd747d
Fix child key in NamedConstantDef processor
Process-ing Jul 8, 2026
bc14bbe
Improve comments test
Process-ing Jul 8, 2026
42e4d94
Fix structure creation in node factory
Process-ing Jul 8, 2026
f9be456
Fix weaver node association
Process-ing Jul 8, 2026
944232e
Complete weaver fix
Process-ing Jul 8, 2026
1a6af29
Create new test case
Process-ing Jul 13, 2026
453a79a
Add test for legacy do loops
Process-ing Jul 14, 2026
bd2a454
Add AST-level support for labeled do loops
Process-ing Jul 14, 2026
70a4849
Upload dump
Process-ing Jul 14, 2026
90b1835
Fix labeled loop processing
Process-ing Jul 14, 2026
fa5f2cc
Fix some keyword usage
Process-ing Jul 14, 2026
1e43a6f
Fix label on end statement
Process-ing Jul 14, 2026
766f097
Fix loop label extraction on fixed-format Fortran
Process-ing Jul 14, 2026
01b8617
Add fixed form indication in FortranContext
Process-ing Jul 14, 2026
dbec91a
Fix file extensions in program
Process-ing Jul 19, 2026
32774d1
Use fixed form info on code generation
Process-ing Jul 19, 2026
06149f8
Separate constructs from executable statements
Process-ing Jul 19, 2026
9296642
Fix lack of extension context in tests
Process-ing Jul 19, 2026
04bc90c
Regenerate dump and fix Fujitsu test case
Process-ing Jul 20, 2026
6bb2737
Fix weaver
Process-ing Jul 20, 2026
06fb222
Fix Fortran form used on tests
Process-ing Jul 20, 2026
d5199ad
Change label justification in fixed form
Process-ing Jul 20, 2026
fcbec2e
Add new Fujitsu test case
Process-ing Jul 20, 2026
6aec2bc
Add return unit test
Process-ing Jul 20, 2026
6a89f96
Refactor dummy argument node and improve architecture to handle node …
Process-ing Jul 20, 2026
4448052
Add return statement to AST
Process-ing Jul 20, 2026
466dba7
Refactor return statement node
Process-ing Jul 20, 2026
1941468
Add return statement processing and do some adjustments to executable…
Process-ing Jul 20, 2026
562c2dc
Fix intent casing
Process-ing Jul 20, 2026
3d2a522
Fix subroutine test with fixed intent kind casing
Process-ing Jul 21, 2026
f281325
Correct Fujitsu test expected code
Process-ing Jul 21, 2026
a3672ab
Regenerate dump
Process-ing Jul 21, 2026
0cea2f8
Support fixed-form comments
Process-ing Jul 21, 2026
7d09b5a
Regenerate dumps
Process-ing Jul 21, 2026
f475024
Fix Fujitsu test expected code
Process-ing Jul 21, 2026
edcbf9e
Update weaver AST structure
Process-ing Jul 21, 2026
551444f
Add new Fujitsu test case
Process-ing Jul 21, 2026
1e86e8b
Change expected code in legacy fortran
Process-ing Jul 21, 2026
fe77387
Configure optional spaces for fixed-form compatibility
Process-ing Jul 21, 2026
2828590
Fix expected code for Fujitsu test case 0001_0011
Process-ing Jul 21, 2026
b6b90d6
Fix extra token in type declaration statement
Process-ing Jul 22, 2026
8a87ef2
Add new Fujitsu test case
Process-ing Jul 22, 2026
3080470
Define AST nodes for complex part
Process-ing Jul 22, 2026
063d929
Define AST node for complex literal
Process-ing Jul 22, 2026
8565671
Create complex literal nodes mapping to classes
Process-ing Jul 22, 2026
3dc04d7
Add complex literal test
Process-ing Jul 22, 2026
3f39eb8
Add complex type node
Process-ing Jul 22, 2026
268aa54
Add code generation for complex type
Process-ing Jul 22, 2026
fde844e
Upload dump for complex literal test
Process-ing Jul 22, 2026
a5c7c93
Add processing of complex type and fix kind selector representation
Process-ing Jul 22, 2026
759db55
Add processing of complex literal
Process-ing Jul 22, 2026
7e0402f
Regenerate dump
Process-ing Jul 22, 2026
9503d67
Improve literal representation and fix processing
Process-ing Jul 22, 2026
96b4aac
Fix complex literal test source code
Process-ing Jul 22, 2026
e26f1c4
Fix real literals not having sign
Process-ing Jul 22, 2026
b72ab2b
Extend use statement architecture
Process-ing Jul 22, 2026
853826c
Regenerate dump
Process-ing Jul 22, 2026
dfd3c6a
Map new use statement nodes to names
Process-ing Jul 22, 2026
ef0b1f2
Implement processors for new use statements
Process-ing Jul 22, 2026
da4669c
Fix complex literal expected code
Process-ing Jul 22, 2026
a0a3dee
Fix some style decisions
Process-ing Jul 22, 2026
b42c34e
Fix processing of named constants and problems with NamedConstantDef
Process-ing Jul 22, 2026
e4ed35b
Fix expected code of Fujitsu 0000_0033
Process-ing Jul 22, 2026
071fe61
Regenerate dump
Process-ing Jul 22, 2026
f99b9ed
Add dimension statement node to AST
Process-ing Jul 22, 2026
cc455f0
Add processing of dimension statements
Process-ing Jul 22, 2026
b1b4363
Fix dimension statement code gen
Process-ing Jul 22, 2026
3032241
Fix Fujitsu test 0001_0032
Process-ing Jul 22, 2026
b97b584
Go back on type declaration statement usage of ::
Process-ing Jul 22, 2026
b3d5bfe
FIx weaver
Process-ing Jul 22, 2026
9e0bb9d
Add substring test
Process-ing Jul 23, 2026
d1384bc
Create substring node
Process-ing Jul 23, 2026
19db421
Add substring node to class map
Process-ing Jul 23, 2026
e1fb10e
Regenerate dump
Process-ing Jul 23, 2026
4fc6700
Add processing of substrings
Process-ing Jul 23, 2026
be6c788
Fix substring processing
Process-ing Jul 23, 2026
70b7c4e
Add variable node
Process-ing Jul 23, 2026
851f361
Add variable node to class mapping
Process-ing Jul 23, 2026
bdfef3b
Add processing of designator variables
Process-ing Jul 23, 2026
5ba1b7a
Fix assignment statement processing to use variable node
Process-ing Jul 23, 2026
4366a46
Add full support for string concatenation
Process-ing Jul 23, 2026
debdaa9
Fix substring test
Process-ing Jul 23, 2026
e67aa2b
Fix usage of variables across nodes
Process-ing Jul 23, 2026
a3c3d39
Add compaction for fixed-form woven code
Process-ing Jul 23, 2026
6a0f58c
Remove usage of optional space
Process-ing Jul 23, 2026
e382cef
Update expected code of tests with fixed-form code
Process-ing Jul 23, 2026
ab505d7
Add continuation line test
Process-ing Jul 23, 2026
22c4ce4
Add continuation line addition for fixed-form Fortran code
Process-ing Jul 23, 2026
3ec0936
Fix processing of allocate statements with no options and code genera…
Process-ing Jul 23, 2026
a21f700
Extend character selector
Process-ing Jul 24, 2026
ceb90d2
Add new nodes to class map
Process-ing Jul 24, 2026
9bdbbdc
Create new approach for matching Flang names to AST node classes
Process-ing Jul 24, 2026
7bdc940
Improve case mapper error message
Process-ing Jul 24, 2026
25c859e
Add processing of type param values
Process-ing Jul 24, 2026
0ea0b65
Add length selector test
Process-ing Jul 24, 2026
ff6ef9d
Add processors for new length selectors
Process-ing Jul 24, 2026
f4025f0
Extend binary operator test
Process-ing Jul 24, 2026
38a3109
Regenerate dump
Process-ing Jul 24, 2026
cb4a8fa
Extend binary operator at the AST level
Process-ing Jul 24, 2026
6eedd86
Match new binary logical operators to AST nodes
Process-ing Jul 24, 2026
6c2e38c
Add IO control test
Process-ing Jul 25, 2026
391ed9b
Create nodes for open statement
Process-ing Jul 25, 2026
86a9279
Add mapping of open statements
Process-ing Jul 25, 2026
f38da93
Add processors for open statements
Process-ing Jul 25, 2026
73ff6a4
Extend AST nodes for IO control specifications
Process-ing Jul 25, 2026
7392d83
Add mapping of improved IO control specs nodes
Process-ing Jul 26, 2026
775f0a1
Create processors for new IO control specifications
Process-ing Jul 26, 2026
60ee6a6
Fix parsing of spec kinds
Process-ing Jul 27, 2026
1400959
Improve mapper error flagging
Process-ing Jul 27, 2026
d246bc5
Add nodes for rewind statement
Process-ing Jul 27, 2026
50facfc
Fix parsing of write statements
Process-ing Jul 27, 2026
af06ea6
Add processors for rewind stmt
Process-ing Jul 27, 2026
77332d7
Create AST nodes for namelist statements
Process-ing Jul 27, 2026
1560406
Add mapping and processors for namelist statements
Process-ing Jul 27, 2026
455da34
Create new nodes for allocation options
Process-ing Jul 27, 2026
1ddcb32
Fix allocation option processors with new AST structure
Process-ing Jul 27, 2026
579598a
Create nodes for read statement
Process-ing Jul 27, 2026
127f420
Add processors for read statements
Process-ing Jul 27, 2026
e9cd5e9
Create AST nodes for wait statement
Process-ing Jul 27, 2026
dbc2f98
Extend structure of write statement
Process-ing Jul 27, 2026
230b6f5
Add processors for new output items
Process-ing Jul 27, 2026
5000fd5
Add processors for wait statement
Process-ing Jul 27, 2026
47eb1f6
Add nodes for close statement
Process-ing Jul 27, 2026
0345d8b
Add processors for close statement
Process-ing Jul 27, 2026
108b49d
Fix processing of namelist statements
Process-ing Jul 27, 2026
d51f48c
Fix attribute lookup on processors for read and write statements
Process-ing Jul 27, 2026
dbdb827
Fix some nitpicks in code generation and fix expected code for IO con…
Process-ing Jul 27, 2026
68b04d1
Fix kind parameter parsing
Process-ing Jul 27, 2026
bdf56b0
Hide specifier keyword on allowed cases in generated code
Process-ing Jul 27, 2026
c73cbe2
Fix continuation line limit trigger
Process-ing Jul 27, 2026
93e03a6
Improve mismatch reporting in unit tests
Process-ing Jul 30, 2026
c0b9750
Improve AST nodes for format
Process-ing Aug 3, 2026
4932416
Add processors for new format nodes
Process-ing Aug 3, 2026
3c20bfd
Fix node factory
Process-ing Aug 3, 2026
eb6d04a
Restructure subroutine and main program nodes nodes
Process-ing Aug 3, 2026
7ee0052
Fix processing of new nodes
Process-ing Aug 3, 2026
367d0f5
Create test for functions
Process-ing Aug 3, 2026
e1927d9
Add AST nodes for functions
Process-ing Aug 3, 2026
973ea39
Regenerate dump
Process-ing Aug 3, 2026
b14a1fe
Add processors for functions
Process-ing Aug 3, 2026
8dc10ce
Remove star node
Process-ing Aug 3, 2026
d1c7d53
Modify function statement to have suffix
Process-ing Aug 3, 2026
c4bb7ad
Regenerate dump
Process-ing Aug 3, 2026
11b24e7
Fix function statement suffix processing
Process-ing Aug 4, 2026
d99d255
Fix weaver
Process-ing Aug 4, 2026
d6445ee
Rename internal subprogram part
Process-ing Aug 4, 2026
575f2b6
Remove console log
Process-ing Aug 4, 2026
0b8d4cf
Merge branch 'feature/comment-dumping' into feature/fujitsu-support-2
Process-ing Aug 4, 2026
30fa649
Fix compilation errors from merge
Process-ing Aug 4, 2026
ce79119
Fix main program factory
Process-ing Aug 4, 2026
4aa0d9f
Add module test
Process-ing Aug 4, 2026
907f79f
Change main program name location to program statement
Process-ing Aug 4, 2026
cf59003
Change subroutine and function names to start statement
Process-ing Aug 4, 2026
14be3b5
Add module AST nodes
Process-ing Aug 4, 2026
b69c84e
Add processors for module nodes
Process-ing Aug 4, 2026
6148a48
Create generic specifier AST nodes
Process-ing Aug 4, 2026
a2abfa7
Create access statement AST nodes
Process-ing Aug 4, 2026
32a42d0
Add processors for generic specifiers and access statement
Process-ing Aug 4, 2026
440ae80
Fix end module statement generator
Process-ing Aug 4, 2026
9fa07f6
Delete empty file
Process-ing Aug 4, 2026
3796e79
Fix module name in module test
Process-ing Aug 4, 2026
d8cf4fd
Change subprogram part code generation
Process-ing Aug 5, 2026
aac9a10
Add another module test
Process-ing Aug 5, 2026
8cfa797
Add import statement AST node
Process-ing Aug 5, 2026
43d622d
Implement processors for import statements
Process-ing Aug 5, 2026
327422f
Implement AST nodes for derived type
Process-ing Aug 6, 2026
bd6b29c
Implement AST nodes for declaration type
Process-ing Aug 6, 2026
242a3cb
Add implicit part test
Process-ing Aug 6, 2026
9a61306
Implement AST nodes for implicit statement and implicit part
Process-ing Aug 6, 2026
5e9b62e
Improve type consistency of specification
Process-ing Aug 6, 2026
037392b
Start fixing specification processing
Process-ing Aug 6, 2026
255cf34
Fix compiler directives on specification
Process-ing Aug 6, 2026
5c3eabb
Fix mismatch line and column reporting
Process-ing Aug 6, 2026
b71a8ae
Restrict statement typing
Process-ing Aug 6, 2026
9bac9c2
Regenerate dumps
Process-ing Aug 6, 2026
0fa4deb
Fix specification association with use and import statements
Process-ing Aug 6, 2026
4419a5f
Fix implicit statement implementation
Process-ing Aug 6, 2026
6e1abf1
Add mapping of new AST nodes to Flang names
Process-ing Aug 6, 2026
14139d4
Fix problems with type declarations statement
Process-ing Aug 6, 2026
cd02b77
Implement processors for declaration types
Process-ing Aug 6, 2026
882c0a8
Add processors for derived type
Process-ing Aug 6, 2026
4e6ab35
Add processors for implicit statement
Process-ing Aug 6, 2026
40e7cc6
Regenerate dumps
Process-ing Aug 6, 2026
4e386f0
Fise internal part with specification and add processors for it
Process-ing Aug 6, 2026
b560476
Fix implicit none statement processing
Process-ing Aug 6, 2026
e27c13c
Fix processing of derived types
Process-ing Aug 6, 2026
270ceac
Improve LetterSpec to use characters instead of ints
Process-ing Aug 7, 2026
4e99116
Create function specifier AST nodes
Process-ing Aug 7, 2026
64623b1
Add processors and mapping for function specifiers
Process-ing Aug 7, 2026
19a36c3
Add prefix to function statement
Process-ing Aug 7, 2026
e0cb477
Create nodes for component attributes
Process-ing Aug 7, 2026
f2e8d9c
Improve nodes for shapes
Process-ing Aug 7, 2026
8d06dd1
Add missing array spec
Process-ing Aug 8, 2026
912543e
Add mapping for new shape nodes
Process-ing Aug 8, 2026
e9f4be6
Rename some shape nodes
Process-ing Aug 8, 2026
8a94ccc
Add processors to new shape structure
Process-ing Aug 8, 2026
fa982d0
Fix array spec code generation
Process-ing Aug 8, 2026
bc08f18
Add coarray specifier AST nodes
Process-ing Aug 8, 2026
296a877
Add missing component attribute nodes
Process-ing Aug 8, 2026
1a2675a
Improve component attribute hierarchy
Process-ing Aug 8, 2026
4a78da7
Restructure len selector hierarchy to distinguish char length
Process-ing Aug 8, 2026
e39e2b8
Add processors to new length selector
Process-ing Aug 8, 2026
af13e2d
Add data component definition statement node
Process-ing Aug 8, 2026
2eb138b
Create AST nodes for derived type definition
Process-ing Aug 8, 2026
0c95ccc
Add type attribute nodes
Process-ing Aug 8, 2026
5ae335c
Finish implementing derived type and end type statements
Process-ing Aug 8, 2026
fff4ae0
Add mapping of new node classes to Flang names
Process-ing Aug 8, 2026
422138c
Add processors for type attributes
Process-ing Aug 8, 2026
72d27ed
Add missing statement to class mapping
Process-ing Aug 8, 2026
ca815bd
Regenerate dump
Process-ing Aug 8, 2026
bb00528
Add more missing nodes to class mapping
Process-ing Aug 8, 2026
53534e5
Add processors for component attributes
Process-ing Aug 8, 2026
614b98f
Finish processors for derived type definition nodes
Process-ing Aug 8, 2026
e169b84
Implement interface AST nodes
Process-ing Aug 8, 2026
754dfc5
Add interface nodes to class mapping
Process-ing Aug 8, 2026
e7a4d9e
Add processors for interface nodes
Process-ing Aug 8, 2026
d51b242
Regenerate dump
Process-ing Aug 8, 2026
491f222
Fix statement child fetching on new processors
Process-ing Aug 8, 2026
00e313b
Fix type name extraction on end type statement
Process-ing Aug 8, 2026
30863b4
Fix name fetching for end function and end subroutine statements
Process-ing Aug 8, 2026
6cdddfa
Fix name fetching for end interface statement
Process-ing Aug 8, 2026
8d382ba
Improve program parts type consistency
Process-ing Aug 11, 2026
6324099
Improve type consistency on Execution node
Process-ing Aug 11, 2026
e160f48
Fix structure of OMP constructs
Process-ing Aug 11, 2026
919b6b8
Fix code generation for legacy do loops
Process-ing Aug 11, 2026
b148c37
Fix processing of paramenter statements
Process-ing Aug 11, 2026
85f96e7
Fix weaver
Process-ing Aug 11, 2026
295faaf
Extend attribute specifier nodes
Process-ing Aug 13, 2026
6492219
Add processors for the new attribute specifiers
Process-ing Aug 13, 2026
9643d1e
Fix weaver
Process-ing Aug 23, 2026
670d7c1
Add nodes for pointer assignment statement
Process-ing Aug 24, 2026
d8165b7
Add pointer assignment test
Process-ing Aug 24, 2026
c96c703
Extend initialization nodes
Process-ing Aug 24, 2026
42b0319
Add AST nodes for procedure interfaces
Process-ing Aug 24, 2026
c05c05d
Add AST nodes for procedure attributes
Process-ing Aug 24, 2026
d5f5f46
Create AST nodes for procedure declaration statement
Process-ing Aug 24, 2026
9b434c2
Add mapping of new nodes to names
Process-ing Aug 24, 2026
76a7960
Improve call node structure
Process-ing Aug 24, 2026
84e6555
Fix processing with new call structure
Process-ing Aug 24, 2026
6fe8297
Add processors for procedure declaration statement
Process-ing Aug 24, 2026
1210f28
Add processors for pointer assignment statement
Process-ing Aug 24, 2026
1ce16d8
Fix code generation for pointer assignment statement with single bounds
Process-ing Aug 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 0 additions & 2 deletions Fortran-JS/src-api/Query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,6 @@ describe("Query", () => {
lst.push(stmt.code);
}

console.log(lst);

expect(lst.length).toBe(4);
expect(lst[0]).toEqual('PROGRAM HELLO');
expect(lst[1]).toEqual('PRINT *, "Hello, World!"');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class FortranContext extends ADataClass<FortranContext> {
public final static DataKey<Optional<File>> LAST_PARSED_FILE = KeyFactory
.optional("lastParsedFile");

public final static DataKey<Optional<String>> LAST_PARSED_FILE_EXT = KeyFactory.optional("lastParsedFileExt");

public final static DataKey<Boolean> FIXED_FORM = KeyFactory.bool("fixedObject").setDefault(() -> false);

/**
* A DataStore with options from {@link FortranAstOptions}.
Expand All @@ -85,5 +88,7 @@ public String toString() {
return "FortranContext " + hashCode();
}


public DataStore getFortranOptions() {
return get(FORTRAN_OPTIONS);
}
}
46 changes: 44 additions & 2 deletions FortranAst/src/pt/up/fe/specs/fortran/ast/FortranKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ public enum FortranKeyword {
CONCURRENT,
SUBROUTINE,
FUNCTION,
WRITE,
USE,
INTRINSIC,
NON_INTRINSIC,
ONLY,
GOTO,
EXTERNAL,
RETURN,
STOP,
MODULE,

// Execution statements
PRINT,
Expand All @@ -22,6 +24,22 @@ public enum FortranKeyword {
ERROR,
QUIET,
CALL,
CONTINUE,
CONTAINS,
ALLOCATE,
DEALLOCATE,
RETURN,
OPEN,
ERR,
WRITE,
UNIT,
FMT,
NML,
REWIND,
NAMELIST,
READ,
WAIT,
CLOSE,

// Conditional statements
IF,
Expand All @@ -39,11 +57,35 @@ public enum FortranKeyword {
DOUBLE,
PRECISION,
DIMENSION,
COMPLEX,

// Declarations
PARAMETER,
DATA,
COMMON,
INTENT,
STAT,
LEN,
KIND,
BIND,
C,
NAME,
CDEFINED,
RESULT,
OPERATOR,
ASSIGNMENT,
FORMATTED,
UNFORMATTED,
IMPORT,
NONE,
ALL,
IMPLICIT,
TYPE,
CODIMENSION,
EXTENDS,
ABSTRACT,
INTERFACE,
PROCEDURE,

OMP;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public String get(FortranKeyword keyword) {
return keyword.getKeyword(lowercase);
}

public boolean isLowercase() {
return lowercase;
}
}
152 changes: 114 additions & 38 deletions FortranAst/src/pt/up/fe/specs/fortran/ast/FortranNodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import org.suikasoft.jOptions.Interfaces.DataStore;
import org.suikasoft.jOptions.storedefinition.StoreDefinitions;
import pt.up.fe.specs.fortran.ast.nodes.FortranNode;
import pt.up.fe.specs.fortran.ast.nodes.decl.ExprInitialization;
import pt.up.fe.specs.fortran.ast.nodes.decl.LabelDecl;
import pt.up.fe.specs.fortran.ast.nodes.decl.ListInitialization;
import pt.up.fe.specs.fortran.ast.nodes.expr.Argument;
import pt.up.fe.specs.fortran.ast.nodes.expr.BinaryOperator;
import pt.up.fe.specs.fortran.ast.nodes.expr.Call;
import pt.up.fe.specs.fortran.ast.nodes.expr.DataRef;
import pt.up.fe.specs.fortran.ast.nodes.expr.Expr;
import pt.up.fe.specs.fortran.ast.nodes.expr.IntLiteral;
import pt.up.fe.specs.fortran.ast.nodes.expr.Literal;
import pt.up.fe.specs.fortran.ast.nodes.expr.StringLiteral;
import pt.up.fe.specs.fortran.ast.nodes.decl.NamedParameter;
import pt.up.fe.specs.fortran.ast.nodes.decl.init.ExprInitialization;
import pt.up.fe.specs.fortran.ast.nodes.decl.init.ListInitialization;
import pt.up.fe.specs.fortran.ast.nodes.expr.*;
import pt.up.fe.specs.fortran.ast.nodes.expr.enums.BinaryOperatorKind;
import pt.up.fe.specs.fortran.ast.nodes.io.Format;
import pt.up.fe.specs.fortran.ast.nodes.io.StarFormat;
import pt.up.fe.specs.fortran.ast.nodes.loops.LoopControl;
import pt.up.fe.specs.fortran.ast.nodes.loops.RangeLoopControl;
import pt.up.fe.specs.fortran.ast.nodes.omp.OmpBlockConstruct;
Expand All @@ -26,13 +22,20 @@
import pt.up.fe.specs.fortran.ast.nodes.omp.enums.OmpClauseKind;
import pt.up.fe.specs.fortran.ast.nodes.omp.enums.OmpDirectiveKind;
import pt.up.fe.specs.fortran.ast.nodes.program.*;
import pt.up.fe.specs.fortran.ast.nodes.program.construct.*;
import pt.up.fe.specs.fortran.ast.nodes.program.unit.EndProgramStmt;
import pt.up.fe.specs.fortran.ast.nodes.program.unit.MainProgram;
import pt.up.fe.specs.fortran.ast.nodes.program.unit.ProgramStmt;
import pt.up.fe.specs.fortran.ast.nodes.program.unit.ProgramUnit;
import pt.up.fe.specs.fortran.ast.nodes.stmt.*;
import pt.up.fe.specs.fortran.ast.nodes.stmt.implicit.IDEStmtImplicitAdapter;
import pt.up.fe.specs.fortran.ast.nodes.stmt.implicit.ISStmtImplicitAdapter;
import pt.up.fe.specs.fortran.ast.nodes.stmt.loop.DoConstruct;
import pt.up.fe.specs.fortran.ast.nodes.stmt.loop.DoStmt;
import pt.up.fe.specs.fortran.ast.nodes.stmt.loop.EndDoStmt;
import pt.up.fe.specs.fortran.ast.nodes.utils.Format;
import pt.up.fe.specs.fortran.ast.nodes.stmt.usestmt.UseOnlyStmt;
import pt.up.fe.specs.fortran.ast.nodes.stmt.usestmt.UseRenameStmt;
import pt.up.fe.specs.fortran.ast.nodes.utils.LabelRef;
import pt.up.fe.specs.fortran.ast.nodes.utils.Star;
import pt.up.fe.specs.util.SpecsCheck;
import pt.up.fe.specs.util.SpecsCollections;

Expand Down Expand Up @@ -136,23 +139,33 @@ private void initComments(Stmt stmt) {
stmt.set(Stmt.LEADING_COMMENTS, List.of());
}

public MainProgram mainProgram(String programName, List<ExecutableStmt> execution) {
public MainProgram mainProgram(String programName, List<ExecPartConstruct> execution) {
DataStore data = newDataStore(MainProgram.class);
data.set(MainProgram.NAME, Optional.ofNullable(programName));

var programStmt = newNode(ProgramStmt.class, Collections.emptyList());
programStmt.set(ProgramStmt.PROGRAM_NAME, programName);
initComments(programStmt);

var specificationBlock = newNode(Specification.class, Collections.emptyList());
var executionBlock = execution(execution);

var endProgramStmt = newNode(EndProgramStmt.class, Collections.emptyList());
initComments(endProgramStmt);

return new MainProgram(data, List.of(programStmt, executionBlock, endProgramStmt));
return new MainProgram(data, List.of(programStmt, specificationBlock, executionBlock, endProgramStmt));
}

public Execution execution(List<ExecutableStmt> statements) {
DataStore data = newDataStore(Execution.class);
public Execution execution(List<ExecPartConstruct> constructs) {
SpecsCheck.checkArgument(
constructs.isEmpty() || !(constructs.get(constructs.size() - 1) instanceof ExecConstruct),
() -> "The last construct of Execution must be of type ExecConstruct"
);

return newNode(Execution.class, constructs);
}

return new Execution(data, statements);
public ExecBlock execBlock(List<ExecPartConstruct> constructs) {
return newNode(ExecBlock.class, constructs);
}

// STMT
Expand Down Expand Up @@ -206,26 +219,16 @@ public StringLiteral stringLiteral(String literal) {

public StringLiteral stringLiteral(String literal, String kindParam) {
DataStore data = newDataStore(StringLiteral.class);
data.set(Literal.SOURCE_LITERAL, literal);
data.set(StringLiteral.CONTENTS, literal);

return new StringLiteral(data, Collections.emptyList());
}

// UTIL

public Format format(FortranNode formatType) {
// Check if node is of allowed type
if (!(formatType instanceof Star)) {
throw new RuntimeException("Unsupported type for Format child: " + formatType.getClass());
}

public StarFormat starFormat() {
DataStore data = newDataStore(Format.class);
return new Format(data, List.of(formatType));
}

public Star star() {
DataStore data = newDataStore(Star.class);
return new Star(data, Collections.emptyList());
return new StarFormat(data, List.of());
}

public LabelRef labelRef(LabelDecl labelDecl) {
Expand Down Expand Up @@ -286,20 +289,30 @@ public DataRef dataRef(String name) {
return newNode;
}

public UseStmt useStmt(String moduleName) {
DataStore data = newDataStore(UseStmt.class);
public UseRenameStmt useRenameStmt(String moduleName) {
DataStore data = newDataStore(UseRenameStmt.class);

UseStmt newNode = new UseStmt(data, Collections.emptyList());
UseRenameStmt newNode = new UseRenameStmt(data, Collections.emptyList());

newNode.set(UseStmt.NAME, moduleName);
newNode.set(UseRenameStmt.NAME, moduleName);

return newNode;
}

public UseOnlyStmt useOnlyStmt(String moduleName) {
DataStore data = newDataStore(UseOnlyStmt.class);

UseOnlyStmt newNode = new UseOnlyStmt(data, Collections.emptyList());

newNode.set(UseOnlyStmt.NAME, moduleName);

return newNode;
}

public OmpReductionClause ompReductionClause(BinaryOperatorKind operator, List<DataRef> refs) {
DataStore data = newDataStore(OmpReductionClause.class);

OmpReductionClause newNode= new OmpReductionClause(data, refs);
OmpReductionClause newNode = new OmpReductionClause(data, refs);

newNode.set(OmpReductionClause.KIND, OmpClauseKind.REDUCTION);

Expand All @@ -312,8 +325,7 @@ public IntLiteral intLiteral(int value) {
DataStore data = newDataStore(IntLiteral.class);

IntLiteral newNode = new IntLiteral(data, Collections.emptyList());

newNode.set(IntLiteral.SOURCE_LITERAL, Integer.toString(value));
newNode.set(IntLiteral.SOURCE, Integer.toString(value));

return newNode;
}
Expand Down Expand Up @@ -364,4 +376,68 @@ public OmpOrderedClause ompOrderedClause(int value) {

return newNode;
}

public NamedParameter namedParameter(String name) {
var data = newDataStore(NamedParameter.class);

var node = new NamedParameter(data, Collections.emptyList());
node.set(NamedParameter.NAME, name);

return node;
}

public DeclStmtAdapter declStmtAdapter(DeclStmt declStmt) {
return newNode(DeclStmtAdapter.class, List.of(declStmt));
}

public IDEStmtDeclAdapter ideStmtDeclAdapter(IDEStmt ideStmt) {
return newNode(IDEStmtDeclAdapter.class, List.of(ideStmt));
}

public SpecStmtAdapter specStmtAdapter(SpecStmt specStmt) {
return newNode(SpecStmtAdapter.class, List.of(specStmt));
}

public DirectiveSpecAdapter directiveSpecAdapter(CompilerDirective compilerDirective) {
return newNode(DirectiveSpecAdapter.class, List.of(compilerDirective));
}

public ISStmtSpecAdapter isStmtSpecAdapter(ISStmt isStmt) {
return newNode(ISStmtSpecAdapter.class, List.of(isStmt));
}

private <T extends Stmt> T withInfoOf(T dest, Stmt source) {
dest.set(Stmt.LEADING_COMMENTS, source.getLeadingComments());
dest.set(Stmt.TRAILING_COMMENT, source.getTrailingComment());
source.getLabel().ifPresent(label -> dest.addChild(0, label));

return dest;
}

public IDEStmtImplicitAdapter ideStmtImplicitAdapter(IDEStmt ideStmt) {
return withInfoOf(newNode(IDEStmtImplicitAdapter.class, List.of(ideStmt)), ideStmt);
}

public ISStmtImplicitAdapter isStmtImplicitAdapter(ISStmt isStmt) {
return withInfoOf(newNode(ISStmtImplicitAdapter.class, List.of(isStmt)), isStmt);
}

public ActionStmtAdapter actionStmtAdapter(ActionStmt actionStmt) {
return newNode(ActionStmtAdapter.class, List.of(actionStmt));
}

public IDEStmtExecAdapter ideStmtExecAdapter(IDEStmt ideStmt) {
return newNode(IDEStmtExecAdapter.class, List.of(ideStmt));
}

public DirectiveExecAdapter directiveExecAdapter(CompilerDirective directive) {
return newNode(DirectiveExecAdapter.class, List.of(directive));
}

public NamedProcDesignator namedProcDesignator(String name) {
var data = newDataStore(NamedProcDesignator.class);
data.set(NamedProcDesignator.NAME, name);

return new NamedProcDesignator(data, List.of());
}
}
Loading
Loading