Skip to content

Adds typecast m as <Type> statement#1140

Merged
markwpearce merged 8 commits into
release-1.0.0from
feature/type_m_as
Apr 24, 2024
Merged

Adds typecast m as <Type> statement#1140
markwpearce merged 8 commits into
release-1.0.0from
feature/type_m_as

Conversation

@markwpearce

@markwpearce markwpearce commented Apr 22, 2024

Copy link
Copy Markdown
Collaborator

Adds ability to add a single statement to beginning of file or function, and every usage of m in that or lower scopes will be typecast as the type given.

Syntax:

typecast m as <type>

eg:

import "types.bs"
typecast m as Thing1

sub func1()
    x = m.value ' x is type of Thing1.value
    print x
end sub

sub func2()
    typecast m as Thing2 
    x = m.value  ' x is type of Thing2.value
    print x
end sub

sub func3()
    aa = {
        innerFunc: sub()
            typecast m as Thing3
            x = m.value  ' x is type of Thing3.value
            print x
        end sub
    }
end sub

class TestKlass
    value as string

    sub method1()
        x = m.value ' x is type of TestKlass.value
        print x
    end sub

    sub method2()
        typecast m as Thing1
        x = m.value  ' x is type of Thing1.value
        print x
    end sub
end class

@markwpearce markwpearce changed the title Feature/type m as Adds typecast m as <Type> statement Apr 22, 2024
@markwpearce markwpearce added this to the v1.0.0 milestone Apr 22, 2024
@markwpearce

Copy link
Copy Markdown
Collaborator Author

addresses: #1036

@TwitchBronBron TwitchBronBron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks pretty good. I have a few high-level changes:

  • let's treat typecast as 1 word (i.e. typecast, typecastStatements, TypecastStatement) instead of uppercasing the c.
  • With respect to the naming of the AST nodes and variables, I'd like this concept to remain generic and not focused on exclusively m (So call it TypecastStatement instead of TypecastMStatement). This PR will remain focused exclusively on only supporting m, but we might expand in the future so I want to be able to reuse the same AST nodes for that.
  • if it's not too much extra work, we should support typecast being used at the top of namespace statement bodies as well, which would apply to only that namespace block (and its enclosed children blocks in that same file). Might be complicated, so it's fine to push off to a future PR after v1 lands.

Comment thread src/DiagnosticMessages.ts Outdated
Comment thread src/bscPlugin/validation/BrsFileValidator.spec.ts
Comment thread src/bscPlugin/validation/BrsFileValidator.ts Outdated
Comment thread src/parser/Parser.spec.ts
Comment thread src/parser/Parser.ts Outdated
Comment thread src/parser/Statement.ts Outdated
Comment thread src/parser/Statement.ts Outdated
Comment thread src/astUtils/CachedLookups.ts Outdated
Comment thread src/DiagnosticMessages.ts Outdated

@TwitchBronBron TwitchBronBron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great!

Comment thread docs/typecasts.md
@markwpearce
markwpearce merged commit 8bfa6fd into release-1.0.0 Apr 24, 2024
@markwpearce
markwpearce deleted the feature/type_m_as branch April 24, 2024 14:26
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.

2 participants