Alexander Morou
Sponsor
Greetings,
Over the past few days I've been working on my compiler foundation, the objectified intermediate language, kid sister project to OILexer.
A while back I had an idea that I call a variadic type-cast; that is, a type-cast that determines the type to cast an object to, based upon whether it is one of the types within the cast. This concept is most useful when the target framework doesn't have a visitor model to use, or implementing the visitor target would bloat the code because the focus of your code is much smaller than that of the visitor model.
Here's how you'd currently do it, without a variadic type-cast:
Lengthy and annoying to type. A variadic type-cast would simplify it, though it would admittedly take some getting used to:
In one instance you'll notice an '| object' this is to indicate that to make the cast work, it must be first cast to object, a rare instance that's common in casting a type-parameter to a specific type that's not an interface.
So the question again is, is this useful, or useless?
Over the past few days I've been working on my compiler foundation, the objectified intermediate language, kid sister project to OILexer.
A while back I had an idea that I call a variadic type-cast; that is, a type-cast that determines the type to cast an object to, based upon whether it is one of the types within the cast. This concept is most useful when the target framework doesn't have a visitor model to use, or implementing the visitor target would bloat the code because the focus of your code is much smaller than that of the visitor model.
Here's how you'd currently do it, without a variadic type-cast:
Code:
[font=courier new][color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]item[/color] [color=#808000]is[/color] [color=Magenta]ILiteralCharReferenceProductionRuleItem[/color][color=#808080])[/color]
[color=#008080]DisplaySyntax[/color][color=#808080]([/color][color=#808080]([/color][color=Magenta]ILiteralCharReferenceProductionRuleItem[/color][color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color]
[color=#0000FF]else[/color] [color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]item[/color] [color=#808000]is[/color] [color=Magenta]ILiteralStringReferenceProductionRuleItem[/color][color=#808080])[/color]
[color=#008080]DisplaySyntax[/color][color=#808080]([/color][color=#808080]([/color][color=Magenta]ILiteralStringReferenceProductionRuleItem[/color][color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color]
[color=#0000FF]else[/color] [color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]item[/color] [color=#808000]is[/color] [color=Magenta]IRuleReferenceProductionRuleItem[/color][color=#808080])[/color]
[color=#008080]DisplaySyntax[/color][color=#808080]([/color][color=#808080]([/color][color=Magenta]IRuleReferenceProductionRuleItem[/color][color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color]
[color=#0000FF]else[/color] [color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]item[/color] [color=#808000]is[/color] [color=Magenta]ITokenReferenceProductionRuleItem[/color][color=#808080])[/color]
[color=#008080]DisplaySyntax[/color][color=#808080]([/color][color=#808080]([/color][color=Magenta]ITokenReferenceProductionRuleItem[/color][color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color]
[color=#0000FF]else[/color] [color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]item[/color] [color=#808000]is[/color] [color=Purple][b]InlinedTokenReferenceTokenItem[/b][/color][color=#808080])[/color]
[color=#008080]DisplaySyntax[/color][color=#808080]([/color][color=#808080]([/color][color=Purple][b]InlinedTokenReferenceTokenItem[/b][/color][color=#808080])[/color][color=#808080]([/color][color=#0000FF]object[/color][color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color]
[color=#0000FF]else[/color] [color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]item[/color] [color=#808000]is[/color] [color=Magenta]ILiteralCharTokenItem[/color][color=#808080])[/color]
[color=#008080]DisplaySyntax[/color][color=#808080]([/color][color=#808080]([/color][color=Magenta]ILiteralCharTokenItem[/color][color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color]
[color=#0000FF]else[/color] [color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]item[/color] [color=#808000]is[/color] [color=Magenta]ILiteralStringTokenItem[/color][color=#808080])[/color]
[color=#008080]DisplaySyntax[/color][color=#808080]([/color][color=#808080]([/color][color=Magenta]ILiteralStringTokenItem[/color][color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color]
[color=#0000FF]else[/color] [color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]item[/color] [color=#808000]is[/color] [color=Magenta]ICharRangeTokenItem[/color][color=#808080])[/color]
[color=#008080]DisplaySyntax[/color][color=#808080]([/color][color=#808080]([/color][color=Magenta]ICharRangeTokenItem[/color][color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color]
[color=#0000FF]else[/color] [color=#0000FF]if[/color] [color=#808080]([/color][color=#008080]item[/color] [color=#808000]is[/color] [color=Magenta]ICommandTokenItem[/color][color=#808080])[/color]
[color=#008080]DisplaySyntax[/color][color=#808080]([/color][color=#808080]([/color][color=Magenta]ICommandTokenItem[/color][color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color][/font]
Lengthy and annoying to type. A variadic type-cast would simplify it, though it would admittedly take some getting used to:
Code:
[font=courier new][color=#008080]DisplaySyntax[/color][color=#808080]([/color]
[color=#808080]([/color]
[color=Magenta]ILiteralCharReferenceProductionRuleItem[/color][color=#808080],[/color]
[color=Magenta]ILiteralStringReferenceProductionRuleItem[/color][color=#808080],[/color]
[color=Magenta]IRuleReferenceProductionRuleItem[/color][color=#808080],[/color]
[color=Magenta]ITokenReferenceProductionRuleItem[/color][color=#808080],[/color]
[color=Purple][b]InlinedTokenReferenceTokenItem[/b][/color] [color=#808000]|[/color] [color=#0000FF]object[/color][color=#808080],[/color]
[color=Magenta]ILiteralCharTokenItem[/color][color=#808080],[/color]
[color=Magenta]ILiteralStringTokenItem[/color][color=#808080],[/color]
[color=Magenta]ICharRangeTokenItem[/color][color=#808080],[/color]
[color=Magenta]ICommandTokenItem[/color]
[color=#808080])[/color][color=#008080]item[/color][color=#808080],[/color] [color=#0000FF]ref[/color] [color=#008080]startingLine[/color][color=#808080],[/color] [color=#008080]depth[/color][color=#808080])[/color][color=#808080];[/color][/font]
In one instance you'll notice an '| object' this is to indicate that to make the cast work, it must be first cast to object, a rare instance that's common in casting a type-parameter to a specific type that's not an interface.
So the question again is, is this useful, or useless?