Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.

Enum variables become empty #13

Open
mingodad opened this issue May 19, 2016 · 2 comments
Open

Enum variables become empty #13

mingodad opened this issue May 19, 2016 · 2 comments

Comments

@mingodad
Copy link

Hello !
Testing the C++ generated by skew I noticed that the generated enums are all empty, adding some debugging to console I can see that at parse time the enum variables has content but at emit time the variables content is empty, I'm still trying to find why this happen.

Cheers !

    switch (symbol.kind) {
      case Skew.SymbolKind.OBJECT_ENUM:
      case Skew.SymbolKind.OBJECT_FLAGS: {
        this._adjustNamespace(symbol);
        this._emitNewlineBeforeSymbol(symbol, Skew.CPlusPlusEmitter.CodeMode.DECLARE);

///////////////////////////// to debug variables empty 
    this._emit(this._indent + '// ' + symbol.name + ' : ' + symbol.variables.length + '\n');
///////////////////////////// to debug variables empty 
        if (symbol.kind == Skew.SymbolKind.OBJECT_FLAGS) {
          this._emit(this._indent + 'namespace ' + Skew.CPlusPlusEmitter._mangleName(symbol) + ' {\n');
          this._increaseIndent();

          if (!(symbol.variables.length == 0)) {
            this._emit(this._indent + 'enum {\n');
          }
        }
Enum: PassKind : EMITTING : 1

Enum: EmitMode : ALWAYS_EMIT : 1

Enum: EmitMode : SKIP_IF_EMPTY : 2

Enum: QuoteStyle : DOUBLE : 1

Enum: QuoteStyle : SINGLE : 2

Enum: QuoteStyle : SHORTEST : 3

Enum: QuoteOctal : NORMAL : 1

Enum: QuoteOctal : OCTAL_WORKAROUND : 2

Enum: Associativity : NONE : 1

Enum: Associativity : LEFT : 2

Enum: Associativity : RIGHT : 3

Enum: CodeMode : DECLARE : 1

Enum: CodeMode : DEFINE : 2

Enum: CodeMode : IMPLEMENT : 3

Enum: CppEmitMode : BARE : 1

Enum: CppEmitMode : NORMAL : 2

Enum: CppEmitMode : DECLARATION : 3

Enum: OperatorKind : FIXED : 1

Enum: OperatorKind : OVERRIDABLE : 2
    // Special-case enum and flags symbols
    if (Skew.in_SymbolKind.isEnumOrFlags(parent.kind) && tokenKind == Skew.TokenKind.IDENTIFIER && kind == Skew.SymbolKind.OBJECT_GLOBAL) {
      while (true) {
        if (text in Skew.Parsing.identifierToSymbolKind || !context.expect(Skew.TokenKind.IDENTIFIER)) {
          break;
        }

        var variable = new Skew.VariableSymbol(Skew.SymbolKind.VARIABLE_ENUM_OR_FLAGS, text);
        variable.range = token.range;
        variable.parent = parent;
        variable.flags |= Skew.SymbolFlags.IS_CONST;
        parent.variables.push(variable);
///////////////////////////// to debug variables empty 
    process.stdout.write('\nEnum: ' + parent.name + ' : ' + text + ' : ' + parent.variables.length + '\n');
///////////////////////////// to debug variables empty 
        symbol = variable;
        var comma = context.current();

        if (!context.eat(Skew.TokenKind.COMMA)) {
          break;
        }
namespace Skew {
  struct SourceMapping;
  struct SourceMapGenerator;

  // PassKind : 0
  enum struct PassKind {
  };

  // EmitMode : 0
  enum struct EmitMode {
  };

  struct Emitter;
  struct JavaScriptEmitter;

  // QuoteStyle : 0
  enum struct QuoteStyle {
  };

  // QuoteOctal : 0
  enum struct QuoteOctal {
  };

  // Associativity : 0
  enum struct Associativity {
  };

  // Precedence : 0
  enum struct Precedence {
  };
@mingodad
Copy link
Author

I tested without "--release" and then the enums are complete, probably for C++ it doesn't make sense to empty then even in release mode.

@evanw
Copy link
Owner

evanw commented May 19, 2016

The Skew compiler is an optimizing compiler and anything that's internal to your code is fair game for optimization. If you need to ensure that something is present because external code depends on it, just add the @export annotation to it and the optimizer won't touch it. That should make sure it appears in the output, even in release mode. Does that work?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants