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

Handle Procedure Attributes #786

Closed
retailcoder opened this Issue Sep 22, 2015 · 7 comments

Comments

@retailcoder
Copy link
Member

retailcoder commented Sep 22, 2015

There are a number of opened issues that have been around since 0.x:

  • #52 toggle default instance attribute
  • #53 toggle default member attribute
  • #54 edit procedure description attribute
  • #55 toggle iterator getter attribute

2.0 is going to have to make them happen. I'm tagging with [code-parsing], but really this isn't about the parser - it's purely about parsing: the VBE doesn't support member attributes, but honors them - this will be dirty string parsing work, without a net*; the VBE API can't help here.

*technically we could use the parser here, although I'm not sure how/whether it handles procedure attributes.

This feature will work off the current selection in the active code pane, and work when the selection is within a procedure:

  • Export the code module to a temp file (don't remove it from the project just yet)
    • Find all procedure attributes
  • Present the user with a modal UI to manage procedure attributes; allow user to cancel, or confirm changes.
  • If changes were made:
    • Remove the code module from the project
    • Insert the appropriate attributes and values where applicable
    • Save the temp file
    • Import the temp file back into the project

Default member attribute: there can only be one, implementation must validate that. Sets value 0 to attribute VB_UserMemId, where [MemberName] is the name of the member/procedure:

Attribute [MemberName].VB_UserMemId = 0

A default member should be a property getter. Given a Text property:

Dim foo As New Bar
foo.Text = "123"

Can turn into:

Dim foo As New Bar
foo = "123"

Iterator getter attribute: there can only be one, implementation must validate that. Sets value -4 to attribute VB_UserMemId, on a Property Get member named NewEnum:

Attribute NewEnum.VB_UserMemId = -4

The feature could create the member if it doesn't exist, and prompt whether to remove it when it does and user is un-checking the box.

This member makes a type usable with a For Each loop, e.g. useful for a custom List class implementation.


Procedure description attribute: one per method, implementation must validate that. Displays a short description for the member when the module is viewed in the Object Browser:

Attribute [MemberName].VB_Description = "Short description of what the procedure does."

Default instance attribute is toggled in a class module's header:

Attribute VB_PredeclaredId = False

When set to True, VBA creates a default instance of the class, which can then be accessed in a similar way to static classes in C# - instead of this:

Dim foo As New Bar
foo.DoSomething

You can now have that:

Bar.DoSomething
@retailcoder

This comment has been minimized.

Copy link
Member

retailcoder commented Sep 22, 2015

This could also be implemented similarly to the VB6 way:

But that requires the user to know what VB_UserMemId values to use. I'd prefer to use checkboxes. Actually, the different VB_UserMemId values are mutually exlcusive, so they should be radiobuttons.

@rubberduck203

This comment has been minimized.

Copy link
Member

rubberduck203 commented Nov 14, 2015

All the ground work is laid, we just need someone to volunteer to implement it. I'm happy to guide someone in how to go about exporting/importing the code files.

@retailcoder

This comment has been minimized.

Copy link
Member

retailcoder commented Mar 18, 2016

Moving this to v2.1; for 2.0 we're going to be reading member and procedure attributes, and the resolver is making good use of them. Writing them is more work than we can fit into the 2.0 timeline.

@comintern

This comment has been minimized.

Copy link
Contributor

comintern commented Jan 23, 2017

Module attributes should probably be refactored to correspond with the Instancing property of the module. These are written in defined combinations. This is described in 5.2.4.1.1 and 5.2.4.1.2 of the VB6 language spec.

They appear to set the following flags (although the VB6 ones need to be verified with a compiler):

Instancing		VB_Exposed	VB_Creatable	VB_GlobalNamespace	VB_PredeclaredId	MultiUse
Private			FALSE		FALSE		FALSE			FALSE			TRUE
PublicNotCreatable	TRUE		FALSE		FALSE			FALSE			TRUE
SingleUse		TRUE		TRUE		FALSE			TRUE			FALSE
GlobalSingleUse		TRUE		TRUE		TRUE			TRUE			FALSE
MultiUse		TRUE		TRUE		FALSE			FALSE			TRUE
GlobalMultiUse		TRUE		TRUE		TRUE			TRUE			TRUE

These attributes seem to correspond with the following TYPEFLAGS:

VB_Creatable = TYPEFLAG_FCANCREATE
VB_Exposed = Unclear if these even make it to the tlb, but if they do - TYPEFLAG_FRESTRICTED
VB_GlobalNamespace = TYPEFLAGS.TYPEFLAG_FAPPOBJECT
VB_PredeclaredId = TYPEFLAG_FPREDECLID

In addition, the following attributes might make it easier to determine the type of document modules by examining the storage stream (see MS-OVBA 3.1.3):

VB_Base (Corresponds to GUID for parent class)
VB_TemplateDerived (Corresponds to TYPEFLAG_FAGGREGATABLE?)
VB_Customizable (Corresponds to !TYPEFLAG_FNONEXTENSIBLE)

It isn't clear if these are used in VB6 (need to test some compiles)

@rkapka

This comment has been minimized.

Copy link
Contributor

rkapka commented Oct 10, 2017

Can someone tell me what is the state of this issue? I see that there are already annotation classes created for all the four attributes types. But apart from that, are these annotations actually doing anything?

If there's anything to be implemented, I would like to start with the procedure description.

@retailcoder

This comment has been minimized.

Copy link
Member

retailcoder commented Oct 10, 2017

@rkapka it's all pretty much done (in my fork), but I'm holding back on the final fixes because they require some tweaking to the parsing infrastructure, which aren't going to happen this close to a green release.

@rkapka

This comment has been minimized.

Copy link
Contributor

rkapka commented Oct 10, 2017

@retailcoder Alrighty. I'll go check out something else, then. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment