Ejemplo n.º 1
0
        public SymbolDef DefGlobal(AstSymbol symbol)
        {
            var name = symbol.Name;

            if (Globals !.ContainsKey(name))
            {
                return(Globals ![name]);
Ejemplo n.º 2
0
        public SymbolDef DefVariable(AstSymbol symbol, AstNode?init)
        {
            SymbolDef def;

            if (Variables !.ContainsKey(symbol.Name))
            {
                def = Variables ![symbol.Name];
Ejemplo n.º 3
0
        public SymbolDef DefVariable(AstSymbol symbol, AstNode?init)
        {
            SymbolDef def;

            if (Variables !.ContainsKey(symbol.Name))
            {
                def = Variables[symbol.Name];
                def.Orig.Add(symbol);
                if (def.Init != null && (!ReferenceEquals(def.Scope, symbol.Scope) || def.Init is AstFunction))
                {
                    def.Init = init;
                }
            }
Ejemplo n.º 4
0
        public SymbolDef DefFunction(AstSymbol symbol, AstNode init)
        {
            var def = DefVariable(symbol, init);

            if (def.Init == null || def.Init is AstDefun)
            {
                def.Init = init;
            }
            if (!Functions.ContainsKey(symbol.Name))
            {
                Functions.Add(symbol.Name, def);
            }
            return(def);
        }
Ejemplo n.º 5
0
        public SymbolDef DefGlobal(AstSymbol symbol)
        {
            var name = symbol.Name;

            if (Globals.ContainsKey(name))
            {
                return(Globals[name]);
            }

            var global = new SymbolDef(this, symbol, null);

            global.Undeclared = true;
            global.Global     = true;
            Globals.Add(name, global);
            return(global);
        }
Ejemplo n.º 6
0
        public SymbolDef DefVariable(AstSymbol symbol, AstNode init)
        {
            SymbolDef def;

            if (Variables.ContainsKey(symbol.Name))
            {
                def = Variables[symbol.Name];
                def.Orig.Add(symbol);
                if (def.Init != null && (!ReferenceEquals(def.Scope, symbol.Scope) || def.Init is AstFunction))
                {
                    def.Init = init;
                }
            }
            else
            {
                def = new SymbolDef(this, symbol, init);
                Variables.Add(symbol.Name, def);
                def.Global = ParentScope == null;
            }

            return(symbol.Thedef = def);
        }
Ejemplo n.º 7
0
        public override void CodeGen(OutputContext output)
        {
            string GetName(AstSymbol symbol)
            {
                return(symbol.Thedef?.MangledName ?? symbol.Thedef?.Name ?? symbol.Name);
            }

            var allowShortHand = output.Options.Shorthand;
            var keyString      = Key switch
            {
                AstString str => str.Value,
                AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture),
                AstSymbol key => GetName(key),
                _ => null
            };

            if (allowShortHand &&
                Value is AstSymbol && keyString != null &&
                GetName((AstSymbol)Value) == keyString &&
                OutputContext.IsIdentifierString(keyString) &&
                OutputContext.IsIdentifier(keyString)
                )
            {
                output.PrintPropertyName(keyString);
            }
            else if (allowShortHand &&
                     Value is AstDefaultAssign defAssign && keyString != null &&
                     defAssign.Left is AstSymbol &&
                     OutputContext.IsIdentifierString(keyString) &&
                     GetName((AstSymbol)defAssign.Left) == keyString
                     )
            {
                output.PrintPropertyName(keyString);
                output.Space();
                output.Print("=");
                output.Space();
                defAssign.Right.Print(output);
            }
Ejemplo n.º 8
0
        protected void PrintGetterSetter(OutputContext output, string?type, bool @static)
        {
            if (@static)
            {
                output.Print("static");
                output.Space();
            }

            if (type != null)
            {
                output.Print(type);
                output.Space();
            }

            var keyString = Key switch
            {
                AstString str => str.Value,
                AstNumber num => num.Value.ToString("R", CultureInfo.InvariantCulture),
                AstSymbol key => key.Name,
                _ => null
            };

            if (keyString != null)
            {
                output.PrintPropertyName(keyString);
            }
            else
            {
                output.Print("[");
                Key.Print(output);
                output.Print("]");
            }

            ((AstLambda)Value).DoPrint(output, true);
        }
    }
Ejemplo n.º 9
0
 public AstSymbolFunarg(AstSymbol from) : base(from)
 {
 }
Ejemplo n.º 10
0
 public AstSymbolImport(AstSymbol init) : base(init)
 {
 }
Ejemplo n.º 11
0
 protected AstSymbolDeclaration(AstSymbol symbol, AstNode?init = null) : base(symbol)
 {
     Init = init;
 }
Ejemplo n.º 12
0
 public AstNameMapping(Parser parser, Position startLoc, Position endLoc, AstSymbol foreignName, AstSymbol name)
     : base(parser, startLoc, endLoc)
 {
     ForeignName = foreignName;
     Name        = name;
 }
Ejemplo n.º 13
0
 public AstSymbolVar(AstSymbol name) : base(name)
 {
 }
Ejemplo n.º 14
0
 public AstSymbolProperty(AstSymbol symbol) : base(symbol)
 {
 }
Ejemplo n.º 15
0
        static bool IsVarLetConst(AstSymbol astSymbol)
        {
            var t = astSymbol.GetType();

            return(t == typeof(AstSymbolVar) || t == typeof(AstSymbolLet) || t == typeof(AstSymbolConst));
        }
Ejemplo n.º 16
0
 public AstSymbolExport(AstSymbol symbol) : base(symbol)
 {
 }
Ejemplo n.º 17
0
 public AstSymbolExportForeign(AstSymbol symbol) : base(symbol)
 {
 }
Ejemplo n.º 18
0
 public AstSymbolDeclaration(AstSymbol symbol, AstNode?init = null) : base(symbol)
 {
     Init = init;
 }
Ejemplo n.º 19
0
 public SymbolDef FindVariable(AstSymbol symbol)
 {
     return(FindVariable(symbol.Name));
 }
Ejemplo n.º 20
0
 public AstSymbolLet(AstSymbol name) : base(name)
 {
 }
Ejemplo n.º 21
0
 public AstSymbolLambda(AstSymbol from) : base(from)
 {
 }
Ejemplo n.º 22
0
 protected AstSymbolBlockDeclaration(AstSymbol symbol, AstNode?init = null) : base(symbol, init)
 {
 }
Ejemplo n.º 23
0
 public AstSymbolConst(AstSymbol name) : base(name)
 {
 }
Ejemplo n.º 24
0
 protected AstSymbolRef(AstSymbol symbol) : base(symbol)
 {
 }
Ejemplo n.º 25
0
 public AstSymbolDefClass(AstSymbol name, AstNode?init = null) : base(name, init)
 {
 }
Ejemplo n.º 26
0
 public AstNameMapping(string?source, Position startLoc, Position endLoc, AstSymbol foreignName, AstSymbol name)
     : base(source, startLoc, endLoc)
 {
     ForeignName = foreignName;
     Name        = name;
 }
Ejemplo n.º 27
0
 public AstLabelRef(AstSymbol symbol) : base(symbol)
 {
 }
Ejemplo n.º 28
0
 protected AstSymbol(AstSymbol symbol) : base(symbol)
 {
     Name = symbol.Name;
 }
Ejemplo n.º 29
0
 public AstSymbolCatch(AstSymbol name) : base(name)
 {
 }
Ejemplo n.º 30
0
 public override void Transform(TreeTransformer tt)
 {
     base.Transform(tt);
     Name        = (AstSymbol)tt.Transform(Name);
     ForeignName = (AstSymbol)tt.Transform(ForeignName);
 }