VB.Net in Oxidizer

Is there anything I can do to get VB.Net supported in Oxidizer?

Hmm. main part would be a VB Parser compatible with out infrastructure. I’ll check with the team to see if thats feasible to be done “outside” of the core elements code, as something we could make pluggable…

If you can do that, it would be nice if you could publish the C# Oxidizer as example code.
Then I can convert this one to VB.

Now with the ExposeEvents/Handles almost implemented, this is the last point for me to be finally able to leave VB.

Turns our, all that parser code is very much ties to our core compiler classes (its essentially the same parsers as the compiler uses, at least for C# and Java)… I’ll see what we can do.

Actually, I think I’ve been overthinking this, as Oxidizer isn actually fairly abstracted in that it “just” needs to generate “CodeGen4” code. CodeGen4 is essentially our version of CodeDom, just more flexible and covering more languages.

What the existing Oxidizer infrastructure does is in two parts:

(1) parse the “source” code and generate a CG4 model of it
(2) let CG4 generate the “target” code from it

Part (1) is done my our compiler (for C# and Java) and by a custom C/ObjC parser we have internally (for Objective-C). The latter part I could share with you, but it probably won’t do you much good, the few bits of useful stuff you’d learn will be hidden in a barrage of stuff that just deals with C.

What you’d need to do is

(a) create (y)our own VB parser from scratch (or find an existing one. Maybe the one in Roslyn is a starting point? maybe there’s other open source code out there? or maybe a simple “language parser generator” tool can help — after all, this doesn’t have to be compiler-level performance code. Just googling “vb.net parser roslyn” gives a loti of hits that sound promising, such as https://msdn.microsoft.com/en-us/magazine/dn879356.aspx).

(b) turn the info younger from it into a CG4 model. the API form that is very straight-forward and easy to discover, and I can give you a couple sample projects top get you started with it.

Part (2) you get for free, because at that point, the source language no longer matters; we have a CGH4 model, so we can generate Oxygene, C#, Swift, Java and all kinds off other code form it (we can even generate back VB.Net — so you can compare input and output :wink:

To get started with 1b, you can find the CodeGen4 library at http://github.com/remobjects/CodeGen4/. You can find one “sample” code base that uses CG4 to generate code, at https://github.com/remobjects/ROCodeGen/ (and I can provide more). I’m the main author of CG4, so i can provide help and guidance, as I know the code base well.

The end delivery would essentially be a simple method method OxidizeVB(aSource: String): CGCodeUnit;

How does this sound?

I have to do some research first …
Can you tell me more about the CG4 model?

it’s pretty straightforward. essentially, its a whole bunch of classes you create and put together to describe the code structure, language agnostic. “here’s a class. here’s a method on this class. here’s it’s parameters. here’s the statements for that method, here’s a for loop”, etc.

eg:

var unit: = new CGCodeUnit()
var class1 := new CGClassTypeDefinition("MyClass")
var method1 := CGMethodDefinition("foo")
method1.Statements := new List<CGStatement>(...);
class1.Members.Add(method1)

…elsewhere…

new CGOxygeneCodeGenrator.generateUnit(unit);

You’d construct that structure based on the VB code your parser detects, and form that CG4 structure, CG4 can then generate “any” language.

The library (source at GitHub - remobjects/CodeGen4: A Swift library to generate source code for many languages, kit also ships pre-built with Elements int the Bin folder, you can just reference it from here to get started) essentially comes in two portions:

(a) types used to describe there code unit (Base, TypeDefinitions, Statements, Expressions, TypeReferences source files)
(b) generators that can turn that structure into source code (CG*Generator source files).

The beauty is that it completely abstracts (a) from (b); you define the code structure w/o knowing/caring what the output language will be, and you can generate code code from a structure w/o knowing/caring where it came from.

Is see that you already have a VB code generator:
image

yeah. But that’s used to generate VB, not parse it. We use it for or RemObjects SDK services if I remember that correctly.

Starting problem:


I referenced the dll, I can see the objects in the object browser, but Oxygene does not recognize it.

What am I doing wrong?

Solved - changed the project from AnyCPU to x86.

1 Like

That’s weird…

I am looking at RemObjects.EBuild.CodeGen4.CGTypeVisibilityKind.

This enum has 4 values:
Assembly (vb: Friend)
Public (vb: Public)
Unit (vb: Private)
Unspecified

How do I specify Protected and Protected Friend?

Good q. sounds like an omission, I should add those.

Actually, there’s CGMemberVisibilityKind. which has those. CGTypeVisibilityKind is for types.

One other point.

In VB, I can have 1 code unit with N namespaces in it.
In the code model, I can have only one namespace in a unit.
How do I do that?

Clear.

I don’t believe we explicitly support this right now. Workaround, which will work in all 4 Elements languages, is to just use the fully qualified name, as the type name for any time not in the “main” namespace. CG4 should handle this fine.

eg

new CGClassDefinition("One");
new CGClassDefinition("Bar.Two");

would generate

namespace Bar;

type
  One = public class // becomes Bar.One
  end;

  Foo.Two = public class // becomes/stays Foo.Two
  end;

Next question.

How do I inferred types for constants?
Example:
Const x = “a string” -> const x := “a string”

The RemObjects.EBuild.CodeGen4.CGConstantTypeReference has a non nullable parameter of type CGTypeReference, so I have to give a type.

Edit: Never mind. If the value starts with a ", it is a string, if it is a number without a ., it is an integer, otherwise it is a double.

How do I do nested classes?