-
Notifications
You must be signed in to change notification settings - Fork 63
Add optional attribute to Capgen #529
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
Changes from all commits
964b776
bcdb37e
224fad3
aa652cd
462d08b
9248678
7a0c4c9
a1a701b
423dc71
aa59672
7b20265
d7bad29
9337a2e
3e4f88f
80da2a5
c34496f
9125aae
34aa7f5
a9ae401
adad650
00a905f
b4991be
b0ad2df
809fc91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,9 +150,9 @@ class Var: | |
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm s-1', 'dimensions' : '()', 'type' : 'real', 'intent' : 'ino'}, ParseSource('vname', 'SCHEME', ParseContext()), _MVAR_DUMMY_RUN_ENV) #doctest: +IGNORE_EXCEPTION_DETAIL | ||
Traceback (most recent call last): | ||
ParseSyntaxError: Invalid intent variable property, 'ino', at <standard input>:1 | ||
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm s-1', 'dimensions' : '()', 'type' : 'real', 'intent' : 'in', 'optional' : 'false'}, ParseSource('vname', 'SCHEME', ParseContext()), _MVAR_DUMMY_RUN_ENV) #doctest: +IGNORE_EXCEPTION_DETAIL | ||
Traceback (most recent call last): | ||
ParseSyntaxError: Invalid variable property name, 'optional', at <standard input>:1 | ||
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm s-1', 'dimensions' : '()', 'type' : 'real', 'intent' : 'in', 'optional' : 'false'}, ParseSource('vname', 'SCHEME', ParseContext()), _MVAR_DUMMY_RUN_ENV) #doctest: +ELLIPSIS | ||
<metavar.Var hi_mom: foo at 0x...> | ||
|
||
# Check that two variables that differ in their units - m vs km - are compatible | ||
>>> Var({'local_name' : 'foo', 'standard_name' : 'hi_mom', 'units' : 'm', \ | ||
'dimensions' : '()', 'type' : 'real', 'intent' : 'in'}, \ | ||
|
@@ -207,6 +207,8 @@ class Var: | |
default_in=False), | ||
VariableProperty('top_at_one', bool, optional_in=True, | ||
default_in=False), | ||
VariableProperty('optional', bool, optional_in=True, | ||
default_in=False), | ||
VariableProperty('target', bool, optional_in=True, | ||
default_in=False)] | ||
|
||
|
@@ -1025,7 +1027,7 @@ def conditional(self, vdicts): | |
vars_needed.append(dvar) | ||
return (conditional, vars_needed) | ||
|
||
def write_def(self, outfile, indent, wdict, allocatable=False, | ||
def write_def(self, outfile, indent, wdict, allocatable=False, target=False, | ||
dummy=False, add_intent=None, extra_space=0, public=False): | ||
"""Write the definition line for the variable to <outfile>. | ||
If <dummy> is True, include the variable's intent. | ||
|
@@ -1077,23 +1079,30 @@ def write_def(self, outfile, indent, wdict, allocatable=False, | |
raise CCPPError(errmsg.format(name)) | ||
# end if | ||
# end if | ||
optional = self.get_prop_value('optional') | ||
if protected and dummy: | ||
intent_str = 'intent(in) ' | ||
elif allocatable: | ||
if dimstr or polymorphic: | ||
intent_str = 'allocatable ' | ||
intent_str = 'allocatable ' | ||
if target: | ||
intent_str = 'allocatable,' | ||
dustinswales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
intent_str += ' target' | ||
else: | ||
intent_str = ' '*13 | ||
# end if | ||
elif intent is not None: | ||
alloval = self.get_prop_value('allocatable') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be True here given the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure of the purpose of alloval here? |
||
if (intent.lower()[-3:] == 'out') and alloval: | ||
intent_str = f"allocatable, intent({intent})" | ||
elif optional: | ||
intent_str = f"intent({intent}),{' '*(5 - len(intent))}" | ||
intent_str += 'target, optional ' | ||
else: | ||
intent_str = f"intent({intent}){' '*(5 - len(intent))}" | ||
# end if | ||
elif not dummy: | ||
intent_str = '' | ||
intent_str = ' '*20 | ||
else: | ||
intent_str = ' '*13 | ||
# end if | ||
|
@@ -1111,26 +1120,40 @@ def write_def(self, outfile, indent, wdict, allocatable=False, | |
extra_space -= len(targ) | ||
if self.is_ddt(): | ||
if polymorphic: | ||
dstr = "class({kind}){cspc}{intent} :: {name}{dims} ! {sname}" | ||
cspc = comma + ' '*(extra_space + 12 - len(kind)) | ||
dstr = "class({kind}){cspace}{intent} :: {name}{dims}" | ||
cspace = comma + ' '*(extra_space + 12 - len(kind)) | ||
else: | ||
dstr = "type({kind}){cspc}{intent} :: {name}{dims} ! {sname}" | ||
cspc = comma + ' '*(extra_space + 13 - len(kind)) | ||
dstr = "type({kind}){cspace}{intent} :: {name}{dims}" | ||
cspace = comma + ' '*(extra_space + 13 - len(kind)) | ||
# end if | ||
else: | ||
if kind: | ||
dstr = "{type}({kind}){cspc}{intent} :: {name}{dims} ! {sname}" | ||
cspc = comma + ' '*(extra_space + 17 - len(vtype) - len(kind)) | ||
dstr = "{type}({kind}){cspace}{intent} :: {name}{dims}" | ||
cspace = comma + ' '*(extra_space + 17 - len(vtype) - len(kind)) | ||
else: | ||
dstr = "{type}{cspc}{intent} :: {name}{dims} ! {sname}" | ||
cspc = comma + ' '*(extra_space + 19 - len(vtype)) | ||
dstr = "{type}{cspace}{intent} :: {name}{dims}" | ||
cspace = comma + ' '*(extra_space + 19 - len(vtype)) | ||
# end if | ||
# end if | ||
|
||
outfile.write(dstr.format(type=vtype, kind=kind, intent=intent_str, | ||
name=name, dims=dimstr, cspc=cspc, | ||
name=name, dims=dimstr, cspace=cspace, | ||
sname=stdname), indent) | ||
|
||
def write_ptr_def(self, outfile, indent, name, kind, dimstr, vtype, extra_space=0): | ||
"""Write the definition line for local null pointer declaration to <outfile>.""" | ||
comma = ', ' | ||
if kind: | ||
dstr = "{type}({kind}){cspace}pointer :: {name}{dims}{cspace2} => null()" | ||
cspace = comma + ' '*(extra_space + 20 - len(vtype) - len(kind)) | ||
cspace2 = ' '*(20 -len(name) - len(dimstr)) | ||
else: | ||
dstr = "{type}{cspace}pointer :: {name}{dims}{cspace2} => null()" | ||
cspace = comma + ' '*(extra_space + 22 - len(vtype)) | ||
cspace2 = ' '*(20 -len(name) - len(dimstr)) | ||
# end if | ||
outfile.write(dstr.format(type=vtype, kind=kind, name=name, dims=dimstr, | ||
cspace=cspace, cspace2=cspace2), indent) | ||
|
||
def is_ddt(self): | ||
"""Return True iff <self> is a DDT type.""" | ||
return not self.__intrinsic | ||
|
Uh oh!
There was an error while loading. Please reload this page.