fort 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fort/src/code/depended_module.rb +40 -0
- data/lib/fort/src/code/program_unit.rb +36 -0
- data/lib/fort/src/code.rb +105 -0
- data/lib/fort/src.rb +19 -0
- data/lib/fort/type/character_type.rb +28 -0
- data/lib/fort/type/complex_type.rb +26 -0
- data/lib/fort/type/integer_type.rb +27 -0
- data/lib/fort/type/logical_type.rb +19 -0
- data/lib/fort/type/real_type.rb +26 -0
- data/lib/fort/type.rb +30 -0
- data/lib/fort/version.rb +3 -0
- data/lib/fort.rb +13 -0
- data/rakefile +7 -0
- data/spec/fort/src/code_spec.rb +167 -0
- data/spec/fort/src/lib_test.f90 +16 -0
- data/spec/fort/src/test.f90 +16 -0
- data/spec/fort/src/test_clean_code.f90 +13 -0
- data/test/fort/test_type.rb +7 -0
- data/test/fort/type/test_character_type.rb +27 -0
- data/test/fort/type/test_complex_type.rb +22 -0
- data/test/fort/type/test_integer_type.rb +22 -0
- data/test/fort/type/test_logical_type.rb +18 -0
- data/test/fort/type/test_real_type.rb +32 -0
- data/test/helper_for_test.rb +3 -0
- data/test/test_fort.rb +7 -0
- metadata +99 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
module Fort
|
2
|
+
class Src
|
3
|
+
class Code
|
4
|
+
class DependedModule
|
5
|
+
require 'ruby_patch'
|
6
|
+
extend ::RubyPatch::AutoLoad
|
7
|
+
|
8
|
+
attr_reader :name, :intrinsic_mode
|
9
|
+
|
10
|
+
def initialize(name, intrinsic_mode = nil)
|
11
|
+
@name = name
|
12
|
+
@intrinsic_mode = if intrinsic_mode.nil?
|
13
|
+
if ::Fort::INTRINSIC_MODULES.include?(name)
|
14
|
+
:both
|
15
|
+
else
|
16
|
+
:non_intrinsic
|
17
|
+
end
|
18
|
+
else
|
19
|
+
intrinsic_mode
|
20
|
+
end
|
21
|
+
raise ArgumentError unless [:intrinsic, :non_intrinsic, :both].include?(@intrinsic_mode)
|
22
|
+
end
|
23
|
+
|
24
|
+
def ==(other)
|
25
|
+
self.class == other.class\
|
26
|
+
&& @name == other.name\
|
27
|
+
&& @intrinsic_mode == other.intrinsic_mode
|
28
|
+
end
|
29
|
+
|
30
|
+
def eql?(other)
|
31
|
+
self.class == other.class && self.hash == other.hash
|
32
|
+
end
|
33
|
+
|
34
|
+
def hash
|
35
|
+
[@name, @intrinsic_mode].hash
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Fort
|
2
|
+
class Src
|
3
|
+
class Code
|
4
|
+
class ProgramUnit
|
5
|
+
require 'ruby_patch'
|
6
|
+
extend ::RubyPatch::AutoLoad
|
7
|
+
|
8
|
+
attr_reader :type, :name
|
9
|
+
attr_accessor :deps
|
10
|
+
|
11
|
+
def initialize(name, type, deps = [])
|
12
|
+
raise ArgumentError unless [:program, :module].include?(type)
|
13
|
+
|
14
|
+
@name = name
|
15
|
+
@type = type
|
16
|
+
@deps = deps
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
self.class == other.class\
|
21
|
+
&& @name == other.name\
|
22
|
+
&& @type == other.type\
|
23
|
+
&& @deps == other.deps
|
24
|
+
end
|
25
|
+
|
26
|
+
def eql?(other)
|
27
|
+
self.class == other.class && self.hash == other.hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def hash
|
31
|
+
[@name, @intrinsic_mode].hash
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Fort
|
2
|
+
class Src
|
3
|
+
|
4
|
+
# Add Fortran source code specific utilities for String.
|
5
|
+
class Code < String
|
6
|
+
require 'pry'
|
7
|
+
require 'ruby_patch'
|
8
|
+
extend ::RubyPatch::AutoLoad
|
9
|
+
|
10
|
+
# $1: quote, $2: string, $3: comment.
|
11
|
+
# We don't need $2 and $3.
|
12
|
+
STRING_OR_COMMENT_REG = /[^"'!]*(?:(["'])(.*?)\1|(!.*?)(?:\n|\z))/mi
|
13
|
+
|
14
|
+
CONTINUATION_AMPERSAND_REG = /& *\n+ *&?/
|
15
|
+
ONE_LINER_REG = /;/
|
16
|
+
|
17
|
+
# $1: "program" or "module". $2: program or module name.
|
18
|
+
START_SECTION_REG = /\A(program|module) +([A-Za-z]\w*)\z/i
|
19
|
+
END_SECTION_REG = /\Aend +(program|module) +([A-Za-z]\w*)\z/i
|
20
|
+
|
21
|
+
# $1: "non_intrinsic" or "intrinsic" or nil. $2: module name.
|
22
|
+
USE_REG = /\Ause(?:(?: *, *((?:non_)?intrinsic) *:: *)|(?: *::)? +)([A-Za-z]\w*)/i
|
23
|
+
|
24
|
+
ParseError = Class.new(StandardError)
|
25
|
+
|
26
|
+
# @return [Array<ProgramUnit>]
|
27
|
+
def parse
|
28
|
+
mode = nil
|
29
|
+
name = nil
|
30
|
+
program_unit = nil
|
31
|
+
program_unit_list = []
|
32
|
+
clean_code.each do |line|
|
33
|
+
case line
|
34
|
+
when START_SECTION_REG
|
35
|
+
raise ParseError unless mode.nil? && name.nil?
|
36
|
+
|
37
|
+
mode = low_sym($1)
|
38
|
+
name = low_sym($2)
|
39
|
+
program_unit = ProgramUnit.new(name, mode)
|
40
|
+
next
|
41
|
+
when END_SECTION_REG
|
42
|
+
raise ParseError unless low_sym($1) == mode && low_sym($2) == name
|
43
|
+
|
44
|
+
mode = nil
|
45
|
+
name = nil
|
46
|
+
program_unit_list << program_unit
|
47
|
+
next
|
48
|
+
end
|
49
|
+
|
50
|
+
case mode
|
51
|
+
when :program, :module
|
52
|
+
next unless line =~ USE_REG
|
53
|
+
|
54
|
+
program_unit.deps << DependedModule.new(low_sym($2), if $1.nil? then nil else low_sym($1) end)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
program_unit_list
|
59
|
+
end
|
60
|
+
|
61
|
+
def contents
|
62
|
+
@contents ||= parse
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Array] Lines without empty lines.
|
66
|
+
def clean_code
|
67
|
+
@clean_code ||= without_comments_and_strings\
|
68
|
+
.without_continuation_ampersand\
|
69
|
+
.without_one_line_semicolon\
|
70
|
+
.split("\n")\
|
71
|
+
.map(&:strip)\
|
72
|
+
.delete_if(&:empty?)\
|
73
|
+
.map(&:downcase)
|
74
|
+
end
|
75
|
+
|
76
|
+
def without_comments_and_strings()
|
77
|
+
self.gsub(STRING_OR_COMMENT_REG) do |s|
|
78
|
+
if $2
|
79
|
+
s[STRING_OR_COMMENT_REG, 2] = ''
|
80
|
+
elsif $3
|
81
|
+
s[STRING_OR_COMMENT_REG, 3] = ''
|
82
|
+
else
|
83
|
+
raise MustNotHappen
|
84
|
+
end
|
85
|
+
|
86
|
+
s
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def without_continuation_ampersand()
|
91
|
+
self.gsub(CONTINUATION_AMPERSAND_REG, '')
|
92
|
+
end
|
93
|
+
|
94
|
+
def without_one_line_semicolon()
|
95
|
+
self.gsub(ONE_LINER_REG, "\n")
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def low_sym(str)
|
101
|
+
str.downcase.to_sym
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/fort/src.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fort
|
2
|
+
|
3
|
+
# Handle file related informations.
|
4
|
+
class Src
|
5
|
+
require 'pathname'
|
6
|
+
require 'ruby_patch'
|
7
|
+
extend ::RubyPatch::AutoLoad
|
8
|
+
|
9
|
+
attr_reader :path
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@path = Pathname.new(path).expand_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def code
|
16
|
+
@code ||= Code.new(@path.read)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Fort
|
2
|
+
class Type
|
3
|
+
class CharacterType < Type
|
4
|
+
require 'ruby_patch'
|
5
|
+
extend ::RubyPatch::AutoLoad
|
6
|
+
|
7
|
+
attr_reader :sym, :len
|
8
|
+
|
9
|
+
def initialize(dim = 0, len = 1)
|
10
|
+
super(dim)
|
11
|
+
@len = len
|
12
|
+
len_suffix = case @len
|
13
|
+
when '*'
|
14
|
+
'Ast'
|
15
|
+
when ':'
|
16
|
+
'Colon'
|
17
|
+
else
|
18
|
+
@len
|
19
|
+
end
|
20
|
+
@sym = "c#{len_suffix}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
"Character(len = #{@len})"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Fort
|
2
|
+
class Type
|
3
|
+
class ComplexType < Type
|
4
|
+
require 'ruby_patch'
|
5
|
+
extend ::RubyPatch::AutoLoad
|
6
|
+
|
7
|
+
KIND_SYM = {
|
8
|
+
32 => 'S', # Single
|
9
|
+
64 => 'D', # Double
|
10
|
+
128 => 'Q', # Quad
|
11
|
+
}
|
12
|
+
|
13
|
+
attr_reader :sym, :kind
|
14
|
+
|
15
|
+
def initialize(dim = 0, kind = 32)
|
16
|
+
super(dim)
|
17
|
+
@kind = kind
|
18
|
+
@sym = "z#{KIND_SYM[@kind]}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
@to_s ||= "Complex(REAL#{@kind})"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Fort
|
2
|
+
class Type
|
3
|
+
class IntegerType < Type
|
4
|
+
require 'ruby_patch'
|
5
|
+
extend ::RubyPatch::AutoLoad
|
6
|
+
|
7
|
+
KIND_SYM = {
|
8
|
+
8 => 'Hh', # Harf-Harf
|
9
|
+
16 => 'H', # Harf
|
10
|
+
32 => 'S', # Single
|
11
|
+
64 => 'D' # Double
|
12
|
+
}
|
13
|
+
|
14
|
+
attr_reader :sym, :kind
|
15
|
+
|
16
|
+
def initialize(dim = 0, kind = 32)
|
17
|
+
super(dim)
|
18
|
+
@kind = kind
|
19
|
+
@sym = "i#{KIND_SYM[@kind]}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
@to_s ||= "Integer(INT#{@kind})"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Fort
|
2
|
+
class Type
|
3
|
+
class RealType < Type
|
4
|
+
require 'ruby_patch'
|
5
|
+
extend ::RubyPatch::AutoLoad
|
6
|
+
|
7
|
+
KIND_SYM = {
|
8
|
+
32 => 'S', # Single
|
9
|
+
64 => 'D', # Double
|
10
|
+
128 => 'Q', # Quad
|
11
|
+
}
|
12
|
+
|
13
|
+
attr_reader :sym, :kind
|
14
|
+
|
15
|
+
def initialize(dim = 0, kind = 32)
|
16
|
+
super(dim)
|
17
|
+
@kind = kind
|
18
|
+
@sym = "r#{KIND_SYM[@kind]}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
@to_s ||= "Real(REAL#{@kind})"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/fort/type.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fort
|
2
|
+
class Type
|
3
|
+
require 'ruby_patch'
|
4
|
+
extend ::RubyPatch::AutoLoad
|
5
|
+
|
6
|
+
USE_ISO_FORTRAN_ENV = "use, intrinsic:: iso_fortran_env, only: INT8, INT16, INT32, INT64, REAL32, REAL64, REAL128"
|
7
|
+
|
8
|
+
attr_reader :dim
|
9
|
+
|
10
|
+
def initialize(dim = 0)
|
11
|
+
@dim = dim
|
12
|
+
end
|
13
|
+
|
14
|
+
def colons
|
15
|
+
@colons ||= ([':']*@dim).join(', ')
|
16
|
+
end
|
17
|
+
|
18
|
+
def parenthesis
|
19
|
+
@parenthesis ||= if @dim >= 1
|
20
|
+
"(#{self.colons})"
|
21
|
+
else
|
22
|
+
''
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def suf
|
27
|
+
@suf ||= "_#{self.sym}_#{@dim}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/fort/version.rb
ADDED
data/lib/fort.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Fort
|
2
|
+
require 'fort/version'
|
3
|
+
require 'ruby_patch'
|
4
|
+
extend ::RubyPatch::AutoLoad
|
5
|
+
|
6
|
+
MustNotHappen = Class.new(Exception)
|
7
|
+
INTRINSIC_MODULES = [
|
8
|
+
:ieee_arithmetic,
|
9
|
+
:ieee_exceptions,
|
10
|
+
:ieee_features,
|
11
|
+
:iso_c_binding,
|
12
|
+
:iso_fortran_env]
|
13
|
+
end
|
data/rakefile
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Fort::Src::Code do
|
4
|
+
describe "#contents" do
|
5
|
+
context 'normal case' do
|
6
|
+
context 'program' do
|
7
|
+
it do
|
8
|
+
::Fort::Src::Code.new(File.read(File.join(__DIR__, 'test.f90')))\
|
9
|
+
.contents\
|
10
|
+
.should == [
|
11
|
+
::Fort::Src::Code::ProgramUnit.new(:test, :program, [
|
12
|
+
::Fort::Src::Code::DependedModule.new(:mod1, :non_intrinsic),
|
13
|
+
::Fort::Src::Code::DependedModule.new(:mod2, :non_intrinsic),
|
14
|
+
::Fort::Src::Code::DependedModule.new(:iso_fortran_env, :both)])]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'module' do
|
19
|
+
it do
|
20
|
+
::Fort::Src::Code.new(File.read(File.join(__DIR__, 'lib_test.f90')))
|
21
|
+
.contents\
|
22
|
+
.should == [
|
23
|
+
::Fort::Src::Code::ProgramUnit.new(:lib_test, :module, [
|
24
|
+
::Fort::Src::Code::DependedModule.new(:mod1, :non_intrinsic),
|
25
|
+
::Fort::Src::Code::DependedModule.new(:mod2, :non_intrinsic),
|
26
|
+
::Fort::Src::Code::DependedModule.new(:iso_fortran_env, :non_intrinsic)])]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'wrong case' do
|
32
|
+
context 'too many start (program or module)' do
|
33
|
+
it do
|
34
|
+
lambda{::Fort::Src::Code.new(File.read(File.join(__DIR__, 'test.f90')))\
|
35
|
+
.sub(/none/, "none\nmodule ab").contents}.should raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'too many end (end program or end module)' do
|
40
|
+
it do
|
41
|
+
lambda{::Fort::Src::Code.new(File.read(File.join(__DIR__, 'test.f90')))\
|
42
|
+
.sub(/write/, "end program ab\nwrite").contents}.should raise_error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#clean_code' do
|
49
|
+
it do
|
50
|
+
raw = File.read(File.join(__DIR__, 'test.f90'))
|
51
|
+
expected = File.read(File.join(__DIR__, 'test_clean_code.f90')).split("\n")
|
52
|
+
::Fort::Src::Code.new(raw).clean_code.should == expected
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#without_continuation_ampersand' do
|
57
|
+
context 'simplest case' do
|
58
|
+
raw= <<-EOS
|
59
|
+
abc&
|
60
|
+
&def
|
61
|
+
EOS
|
62
|
+
|
63
|
+
expected = <<-EOS
|
64
|
+
abcdef
|
65
|
+
EOS
|
66
|
+
|
67
|
+
it do
|
68
|
+
::Fort::Src::Code.new(raw).without_continuation_ampersand.should == expected
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'no ampersand on the top of the continuation lines' do
|
73
|
+
raw= <<-EOS
|
74
|
+
abc&
|
75
|
+
def
|
76
|
+
EOS
|
77
|
+
|
78
|
+
expected = <<-EOS
|
79
|
+
abcdef
|
80
|
+
EOS
|
81
|
+
|
82
|
+
it do
|
83
|
+
::Fort::Src::Code.new(raw).without_continuation_ampersand.should == expected
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "don't join lines if no ampersand exist at the end of the first line" do
|
88
|
+
raw= <<-EOS
|
89
|
+
abc
|
90
|
+
&def
|
91
|
+
EOS
|
92
|
+
|
93
|
+
expected = <<-EOS
|
94
|
+
abc
|
95
|
+
&def
|
96
|
+
EOS
|
97
|
+
|
98
|
+
it do
|
99
|
+
::Fort::Src::Code.new(raw).without_continuation_ampersand.should == expected
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'complex case' do
|
104
|
+
raw= <<-EOS
|
105
|
+
A = (/ &
|
106
|
+
& 1, 2, 3, &
|
107
|
+
& 4, 5, 6, &
|
108
|
+
& 7, 8, 9 &
|
109
|
+
/)
|
110
|
+
EOS
|
111
|
+
|
112
|
+
expected = <<-EOS
|
113
|
+
A = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /)
|
114
|
+
EOS
|
115
|
+
|
116
|
+
it do
|
117
|
+
::Fort::Src::Code.new(raw).without_continuation_ampersand.should == expected
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#without_one_line_semicolon' do
|
123
|
+
context 'simplest case' do
|
124
|
+
raw= <<-EOS
|
125
|
+
abc; def
|
126
|
+
EOS
|
127
|
+
|
128
|
+
expected = <<-EOS
|
129
|
+
abc
|
130
|
+
def
|
131
|
+
EOS
|
132
|
+
|
133
|
+
it do
|
134
|
+
::Fort::Src::Code.new(raw).without_one_line_semicolon.should == expected
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#without_comments_and_strings' do
|
140
|
+
context 'simplest case' do
|
141
|
+
it do
|
142
|
+
::Fort::Src::Code.new("abc!def").without_comments_and_strings.should == 'abc'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'complex case' do
|
147
|
+
it do
|
148
|
+
raw= <<-EOS
|
149
|
+
'd'
|
150
|
+
abc 'def&
|
151
|
+
&ghij'
|
152
|
+
ddd ! ! ddd
|
153
|
+
ab"df'
|
154
|
+
asd"dd
|
155
|
+
EOS
|
156
|
+
|
157
|
+
expected = <<-EOS
|
158
|
+
''
|
159
|
+
abc ''
|
160
|
+
ddd
|
161
|
+
ab""dd
|
162
|
+
EOS
|
163
|
+
::Fort::Src::Code.new(raw).without_comments_and_strings.should == expected
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module lib_test
|
2
|
+
use mod1, only: func1, proc1
|
3
|
+
use, non_intrinsic :: mod2, only: func2, CONST1
|
4
|
+
use, non_intrinsic:: ISO_FORTRAN_ENV, only: OUTPUT_UNIT
|
5
|
+
|
6
|
+
implicit none
|
7
|
+
real:: a, b
|
8
|
+
integer:: c, d
|
9
|
+
integer, parameter:: VERSION = 1
|
10
|
+
|
11
|
+
write(0, *) "input a, b: " ! Try to read.
|
12
|
+
write(6, *) "input a, b: " ! Try to read.
|
13
|
+
read(5, *) a, &
|
14
|
+
& b
|
15
|
+
stop
|
16
|
+
end module lib_test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
program test
|
2
|
+
use mod1, only: func1, proc1
|
3
|
+
use, non_intrinsic :: mod2, only: func2, CONST1
|
4
|
+
use :: ISO_FORTRAN_ENV, only: OUTPUT_UNIT
|
5
|
+
|
6
|
+
implicit none
|
7
|
+
real:: a, b
|
8
|
+
integer:: c, d
|
9
|
+
integer, parameter:: VERSION = 1
|
10
|
+
|
11
|
+
write(0, *) "input a, b: " ! Try to read.
|
12
|
+
write(6, *) "input a, b: " ! Try to read.
|
13
|
+
read(5, *) a, &
|
14
|
+
& b
|
15
|
+
stop
|
16
|
+
end program test
|
@@ -0,0 +1,13 @@
|
|
1
|
+
program test
|
2
|
+
use mod1, only: func1, proc1
|
3
|
+
use, non_intrinsic :: mod2, only: func2, const1
|
4
|
+
use :: iso_fortran_env, only: output_unit
|
5
|
+
implicit none
|
6
|
+
real:: a, b
|
7
|
+
integer:: c, d
|
8
|
+
integer, parameter:: version = 1
|
9
|
+
write(0, *) ""
|
10
|
+
write(6, *) ""
|
11
|
+
read(5, *) a, b
|
12
|
+
stop
|
13
|
+
end program test
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'helper_for_test'
|
2
|
+
|
3
|
+
class TestCharacterType < ::MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@cAst_0 = ::Fort::Type::CharacterType.new(0, '*')
|
6
|
+
@cColon_1 = ::Fort::Type::CharacterType.new(1, ':')
|
7
|
+
@c3_2 = ::Fort::Type::CharacterType.new(2, 3)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_to_s
|
11
|
+
assert_equal(@cAst_0.to_s, "Character(len = *)")
|
12
|
+
assert_equal(@cColon_1.to_s, "Character(len = :)")
|
13
|
+
assert_equal(@c3_2.to_s, "Character(len = 3)")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_dim
|
17
|
+
assert_equal(@cAst_0.dim, 0)
|
18
|
+
assert_equal(@cColon_1.dim, 1)
|
19
|
+
assert_equal(@c3_2.dim, 2)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_suf
|
23
|
+
assert_equal(@cAst_0.suf, '_cAst_0')
|
24
|
+
assert_equal(@cColon_1.suf, '_cColon_1')
|
25
|
+
assert_equal(@c3_2.suf, '_c3_2')
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper_for_test'
|
2
|
+
|
3
|
+
class TestComplexType < ::MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@d_0 = ::Fort::Type::ComplexType.new(0, 64)
|
6
|
+
@s_2 = ::Fort::Type::ComplexType.new(2, 32)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_KIND_SYM
|
10
|
+
assert(::Fort::Type::ComplexType::KIND_SYM)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_to_s
|
14
|
+
assert_equal(@d_0.to_s, "Complex(REAL64)")
|
15
|
+
assert_equal(@s_2.to_s, "Complex(REAL32)")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_suf
|
19
|
+
assert_equal(@d_0.suf, "_zD_0")
|
20
|
+
assert_equal(@s_2.suf, "_zS_2")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper_for_test'
|
2
|
+
|
3
|
+
class TestIntegerType < ::MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@d_0 = ::Fort::Type::IntegerType.new(0, 64)
|
6
|
+
@s_2 = ::Fort::Type::IntegerType.new(2, 32)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_KIND_SYM
|
10
|
+
assert(::Fort::Type::IntegerType::KIND_SYM)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_to_s
|
14
|
+
assert_equal(@d_0.to_s, "Integer(INT64)")
|
15
|
+
assert_equal(@s_2.to_s, "Integer(INT32)")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_suf
|
19
|
+
assert_equal(@d_0.suf, "_iD_0")
|
20
|
+
assert_equal(@s_2.suf, "_iS_2")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper_for_test'
|
2
|
+
|
3
|
+
class TestLogicalType < ::MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@l0 = ::Fort::Type::LogicalType.new(0)
|
6
|
+
@l2 = ::Fort::Type::LogicalType.new(2)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_to_s
|
10
|
+
assert_equal(@l0.to_s, "Logical")
|
11
|
+
assert_equal(@l2.to_s, "Logical")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_suf
|
15
|
+
assert_equal(@l0.suf, "_l_0")
|
16
|
+
assert_equal(@l2.suf, "_l_2")
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper_for_test'
|
2
|
+
|
3
|
+
class TestRealType < ::MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@d_0 = ::Fort::Type::RealType.new(0, 64)
|
6
|
+
@s_2 = ::Fort::Type::RealType.new(2, 32)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_KIND_SYM
|
10
|
+
assert(::Fort::Type::RealType::KIND_SYM)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_to_s
|
14
|
+
assert_equal(@d_0.to_s, "Real(REAL64)")
|
15
|
+
assert_equal(@s_2.to_s, "Real(REAL32)")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_dim
|
19
|
+
assert_equal(@d_0.dim, 0)
|
20
|
+
assert_equal(@s_2.dim, 2)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_suf
|
24
|
+
assert_equal(@d_0.suf, "_rD_0")
|
25
|
+
assert_equal(@s_2.suf, "_rS_2")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_parenthesis
|
29
|
+
assert_equal(@d_0.parenthesis, "")
|
30
|
+
assert_equal(@s_2.parenthesis, "(:, :)")
|
31
|
+
end
|
32
|
+
end
|
data/test/test_fort.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fort
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- kshramt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ruby_patch
|
16
|
+
requirement: &79800780 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *79800780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: pry
|
27
|
+
requirement: &79800210 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.9'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *79800210
|
36
|
+
description: Ruby library for Fortran 90 and newer.
|
37
|
+
email:
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- lib/fort.rb
|
43
|
+
- lib/fort/src.rb
|
44
|
+
- lib/fort/src/code.rb
|
45
|
+
- lib/fort/src/code/depended_module.rb
|
46
|
+
- lib/fort/src/code/program_unit.rb
|
47
|
+
- lib/fort/type.rb
|
48
|
+
- lib/fort/type/character_type.rb
|
49
|
+
- lib/fort/type/complex_type.rb
|
50
|
+
- lib/fort/type/integer_type.rb
|
51
|
+
- lib/fort/type/logical_type.rb
|
52
|
+
- lib/fort/type/real_type.rb
|
53
|
+
- lib/fort/version.rb
|
54
|
+
- rakefile
|
55
|
+
- spec/fort/src/code_spec.rb
|
56
|
+
- spec/fort/src/lib_test.f90
|
57
|
+
- spec/fort/src/test.f90
|
58
|
+
- spec/fort/src/test_clean_code.f90
|
59
|
+
- test/fort/test_type.rb
|
60
|
+
- test/fort/type/test_character_type.rb
|
61
|
+
- test/fort/type/test_complex_type.rb
|
62
|
+
- test/fort/type/test_integer_type.rb
|
63
|
+
- test/fort/type/test_logical_type.rb
|
64
|
+
- test/fort/type/test_real_type.rb
|
65
|
+
- test/helper_for_test.rb
|
66
|
+
- test/test_fort.rb
|
67
|
+
homepage:
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.9'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.11
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Library for Fortran 90 and newer.
|
91
|
+
test_files:
|
92
|
+
- test/fort/test_type.rb
|
93
|
+
- test/fort/type/test_character_type.rb
|
94
|
+
- test/fort/type/test_complex_type.rb
|
95
|
+
- test/fort/type/test_integer_type.rb
|
96
|
+
- test/fort/type/test_logical_type.rb
|
97
|
+
- test/fort/type/test_real_type.rb
|
98
|
+
- test/test_fort.rb
|
99
|
+
has_rdoc:
|