Skip to content
This repository has been archived by the owner on May 9, 2018. It is now read-only.

Adds support for basic structs #25

Merged
merged 6 commits into from
Nov 11, 2017
Merged

Adds support for basic structs #25

merged 6 commits into from
Nov 11, 2017

Conversation

armcburney
Copy link
Member

@armcburney armcburney commented Nov 11, 2017

Issue

#3

Usage

Adds a SyntaxNode for structs with the following usage:

const structure = new cgl.Struct(qualifier, 'structName', variables);

/**
 * structure.source() =>
 * ----------------------------
 *
 * <qualifierType> struct structName {
 *   // variables
 * };
 */

@davepagurek
Copy link
Member

davepagurek commented Nov 11, 2017

Thoughts:

  • we should separate the type and the instance
  • probably doesn't need the array type in here if we're going to support arrays of arbitrary types
  • this is a good time to separate variables and interfaces

For the Variable and Interface thing: you'll see in your test you've got in as a qualifier on the struct member, which we don't actually want. Instead, the whole struct would have the qualifier, since the struct is the type. What I think we should do is have the type+name be a Variable, and have Interface be a variable+qualifier.

@abhimadan
Copy link
Member

abhimadan commented Nov 11, 2017 via email

@armcburney
Copy link
Member Author

Hey @abhimadan, I've almost completed the separation, and I was going to update this PR with it when I was finished.

@abhimadan
Copy link
Member

abhimadan commented Nov 11, 2017 via email

constructor(qualifier: Qualifier, variable: Variable) {
this.qualifier = qualifier;
this.name = variable.name;
this.kind = variable.kind;
Copy link
Member

Choose a reason for hiding this comment

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

Why not just store the variable and read these off the variable?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to expose the variable as part of the public interface (even if readonly). Also, I didn't want to breach the law of demeter.

Copy link
Member Author

@armcburney armcburney Nov 11, 2017

Choose a reason for hiding this comment

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

I can change it if we want, but it would propagate to a lot of changes in the current code which utilizes the old Variable class. I was trying to go for "least amount of changes to other code" while creating this new class.

src/struct.ts Outdated
/**
* struct type-name {
* members
* } struct-name;
Copy link
Member

Choose a reason for hiding this comment

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

Correct me if I'm wrong but the struct-name at the end makes an instance of the struct, when we really just want the type. e.g.

// define the struct
struct s {
  int x;
};

// now make an instance
s some_instance;

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, my bad - good catch

Copy link
Member

Choose a reason for hiding this comment

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

and also change the comment :)

src/interface.ts Outdated
import Type from './type';
import Variable from './variable';

export default class Interface implements Hashable {
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename this class InterfaceVariable? Interface is a really generic name.

@armcburney armcburney merged commit 8868c8b into master Nov 11, 2017
@armcburney armcburney deleted the structs branch November 11, 2017 21:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants