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

Allow multi-module processing. #21

Merged
merged 1 commit into from
Nov 22, 2015
Merged

Allow multi-module processing. #21

merged 1 commit into from
Nov 22, 2015

Conversation

james-ward
Copy link
Contributor

During semantic parsing, definitions with reference to other modules
have a member variable set in the ReferencedValue class.
In order to allow base types to be determined by searching the tree
of other modules, the Module class now has a member variable
'referenced_modules' which it searches through. Modules in this list
are also added to the output as import statements.

The main function in pyasn1gen.py has been modified to take a command
line switch to output multiple modules to separate files rather than
stdout.

@kimgr
Copy link
Owner

kimgr commented Sep 10, 2015

Thanks for doing this (and the other one!)

Just to let you know that I've seen these, and I'll try to find time to review and integrate them soon.

@@ -246,7 +246,8 @@ def annotation(t):
defined_type = Optional(module_reference + Suppress('.'), default=None) + typereference + Optional(size_constraint, default=None)

# TODO: consider exception syntax from 24.1
extension_marker = Unique(ELLIPSIS)
# At the moment we do not do anything with ELLIPSIS - so suppress it
extension_marker = Suppress(Unique(ELLIPSIS))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this necessary for something in this patch? If not, I'd prefer it if the extension marker was still included for now, so we can dig it out of sema in codegen.

@kimgr
Copy link
Owner

kimgr commented Sep 20, 2015

Nicely done! Please find lots of small comments inline, but the general approach looks good to me! I can test-run and integrate when these are fixed.

@kimgr
Copy link
Owner

kimgr commented Sep 20, 2015

Also, have you thought anything about mechanisms for testing this?

@james-ward
Copy link
Contributor Author

Okay, your fixes/suggestions have been incorporated.
I'm afraid I can't see any other way to avoid recursions in the children calculation than what I have, but I have made the comments more expansive to explain the logic behind the approach.

print(pygen.auto_generated_header())
generate_pyasn1(module, sys.stdout)
try:
module.referenced_modules = [m for m in modules if not m is module]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a little strange... Could you push this into build_semantic_model?

Actually, when I looked at the full flow, I have another idea:

  • change resolve_type_decl to take the full module list as an argument
  • pass all modules to generate_pyasn1 and pass the list on into Pyasn1Backend, so that you can provide it when you call resolve_type_decl

That way you don't have to change the module from codegen, which seems like a smell.

Also, build_semantic_model, which seems pretty abstract currently, doesn't need any special handling for referenced modules, which is primarily interesting for codegen.

And you can remove the special handling of referenced_modules in SemaNode.children! Win!

@kimgr
Copy link
Owner

kimgr commented Oct 2, 2015

I like this, but I think you can simplify even more by handling referenced modules primarily in codegen. See inline comments.

Also, I noticed that ReferencedValue has the same TODO for module references, can you update that too to store the module?

Finally, it would be great to have tests for this, but I'm not sure how to pull it off with the current cheap infrastructure...

@james-ward
Copy link
Contributor Author

See what you think now - all handled in Sema.py and codegen. Thanks for the pointers!

@@ -474,8 +482,8 @@ def generate_OID(self):
return str(fragment)


def generate_pyasn1(sema_module, out_stream):
return Pyasn1Backend(sema_module, out_stream).generate_code()
def generate_pyasn1(sema_module, out_stream, referenced_modules = None):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please get rid of the default value for referenced_modules here, we're only calling this from one place, and we have them available.

@kimgr
Copy link
Owner

kimgr commented Oct 7, 2015

This looks great to me, can you please fix the nits inline, then I'm ready to merge it!

When generating code, the list of modules is passed through Pyasn1Backend
in order to allow references across modules. Modules in this list
are also added to the output as import statements.

The main function in pyasn1gen.py has been modified to take a command
line switch to output multiple modules to separate files rather than
stdout.
@james-ward
Copy link
Contributor Author

Nits fixed (I think!). I've also added cross-module referenced value resolution.

@kimgr
Copy link
Owner

kimgr commented Nov 14, 2015

Same here! I accidentally turned off GitHub notifications for a while, and didn't see this. Let me get back to you as soon as I can.

kimgr added a commit that referenced this pull request Nov 22, 2015
Allow multi-module processing.

Patch by James Ward.
@kimgr kimgr merged commit 8920583 into kimgr:master Nov 22, 2015
@kimgr
Copy link
Owner

kimgr commented Nov 22, 2015

Thanks, merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants