internal override bool Resolve(Environment env) { set_prefix(); set_function_type(); if (func_obj.name != null && func_obj.name != String.Empty) { env.Enter(String.Empty, Symbol.CreateSymbol(func_obj.name), this); } env.BeginScope(String.Empty); ((ICanModifyContext)func_obj).PopulateContext(env, String.Empty); FormalParameterList p = func_obj.parameters; if (p != null) { p.Resolve(env); } Block body = func_obj.body; if (body != null) { body.Resolve(env); } locals = env.CurrentLocals(String.Empty); env.EndScope(String.Empty); return(true); }
void ICanModifyContext.PopulateContext(Environment env, string ns) { // // In the case of function // expressions we add // function's name to the // table but we resolve its // body until later, as free // variables can be referenced // in function's body. // string name = func_obj.name; AST binding = null; if (name != null && name != String.Empty) { binding = (AST)env.Get(ns, Symbol.CreateSymbol(name)); } if (binding == null) { env.Enter(ns, Symbol.CreateSymbol(name), new FunctionDeclaration()); } else { Console.WriteLine("repeated functions are not handled yet"); throw new NotImplementedException(); } }
void ICanModifyContext.PopulateContext(Environment env, string ns) { // // In the case of function // declarations we add // function's name to the // table but we resolve its // body until later, as free // variables can be referenced // in function's body. // string name = func_obj.name; AST binding = (AST)env.Get(String.Empty, Symbol.CreateSymbol(name)); if (binding == null) { env.Enter(String.Empty, Symbol.CreateSymbol(name), this); } else if (binding is FunctionDeclaration || binding is VariableDeclaration) { Console.WriteLine("{0}({1},0) : warning JS1111: '{2}' is already defined", Location.SourceName, Location.LineNumber, name); } if (binding is VariableDeclaration) { VariableDeclaration var_decl = (VariableDeclaration)binding; string error_msg = Location.SourceName + "(" + var_decl.Location.LineNumber + ",0) : " + "error JS5040: '" + var_decl.id + "' is read-only"; throw new Exception(error_msg); } }
internal override bool Resolve(Environment env) { bool r = true; if (guarded_block != null) { r &= guarded_block.Resolve(env); } if (catch_blocks != null && catch_blocks.Count > 0) { foreach (Catch c in catch_blocks) { env.BeginScope(String.Empty, true); env.Enter(String.Empty, Symbol.CreateSymbol(c.id), c); r &= c.Resolve(env); env.EndScope(String.Empty); } } if (finally_block != null) { r &= finally_block.Resolve(env); } return(r); }
internal static object defined_in_current_scope(string id) { if (infos.InCurrentScope(Symbol.CreateSymbol(id))) { return(Get(id)); } return(null); }
void ICanModifyContext.PopulateContext(Environment env, string ns) { Symbol _id = Symbol.CreateSymbol(id); if (!env.InCurrentScope(ns, _id)) { env.Enter(ns, _id, this); } }
internal void BuildGlobalEnv() { // // built in print function // if (SemanticAnalyser.print) { Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("print"), new BuiltIn("print", false, true)); } /* value properties of the Global Object */ Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("NaN"), new BuiltIn("NaN", false, false)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("Infinity"), new BuiltIn("Infinity", false, false)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("undefined"), new BuiltIn("undefined", false, false)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("null"), new BuiltIn("null", false, false)); /* function properties of the Global Object */ object [] custom_attrs; Type global_object = typeof(GlobalObject); MethodInfo [] methods = global_object.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly); foreach (MethodInfo mi in methods) { custom_attrs = mi.GetCustomAttributes(typeof(JSFunctionAttribute), false); foreach (JSFunctionAttribute attr in custom_attrs) { if (attr.IsBuiltIn) { Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol(mi.Name), new BuiltIn(SemanticAnalyser.ImplementationName(attr.BuiltIn.ToString()), false, true)); } } } /* built in objects */ Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("Object"), new BuiltIn("Object", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("Function"), new BuiltIn("Function", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("Array"), new BuiltIn("Array", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("String"), new BuiltIn("String", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("Boolean"), new BuiltIn("Boolean", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("Number"), new BuiltIn("Number", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("Math"), new BuiltIn("Math", false, false)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("Date"), new BuiltIn("Date", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("RegExp"), new BuiltIn("RegExp", true, true)); /* built in Error objects */ Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("Error"), new BuiltIn("Error", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("EvalError"), new BuiltIn("EvalError", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("RangeError"), new BuiltIn("RangeError", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("ReferenceError"), new BuiltIn("ReferenceError", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("SyntaxError"), new BuiltIn("SyntaxError", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("TypeError"), new BuiltIn("TypeError", true, true)); Enter(SemanticAnalyser.GlobalNamespace, Symbol.CreateSymbol("URIError"), new BuiltIn("URIError", true, true)); }
void ICanModifyContext.PopulateContext(Environment env, string ns) { AST ast; for (int i = 0; i < elems.Count; i++) { ast = (AST)elems [i]; if (ast is FunctionDeclaration) { string name = ((FunctionDeclaration)ast).func_obj.name; AST binding = (AST)env.Get(ns, Symbol.CreateSymbol(name)); if (binding == null) { SemanticAnalyser.Ocurrences.Enter(ns, Symbol.CreateSymbol(name), new DeleteInfo(i, this)); } else { DeleteInfo delete_info = (DeleteInfo)SemanticAnalyser.Ocurrences.Get(ns, Symbol.CreateSymbol(name)); if (delete_info != null) { delete_info.Block.elems.RemoveAt(delete_info.Index); SemanticAnalyser.Ocurrences.Remove(ns, Symbol.CreateSymbol(name)); if (delete_info.Block == this) { if (delete_info.Index < i) { i--; } } SemanticAnalyser.Ocurrences.Enter(ns, Symbol.CreateSymbol(name), new DeleteInfo(i, this)); } } } if (ast is ICanModifyContext) { ((ICanModifyContext)ast).PopulateContext(env, ns); } } }
internal static bool ContainsLabel(string name) { object r = label_set.Get(Symbol.CreateSymbol(name)); return(r != null); }
internal static void AddLabel(string name, AST binding) { label_set.Enter(Symbol.CreateSymbol(name), binding); }
internal static object GetLocalScriptFunction(string name) { return(local_script_functions.Get(Symbol.CreateSymbol(name))); }
internal static void AddLocalScriptFunction(string name, object o) { local_script_functions.Enter(Symbol.CreateSymbol(name), o); }
internal static void Add(string name, object o) { infos.Enter(Symbol.CreateSymbol(name), o); }
internal override bool Resolve(Environment env) { env.Enter(String.Empty, Symbol.CreateSymbol(id), this); return(true); }
internal static object GetLabel(string name) { return(label_set.Get(Symbol.CreateSymbol(name))); }
internal static void RemoveLabel(string name) { label_set.Remove(Symbol.CreateSymbol(name)); }
internal static object Get(string name) { return(infos.Get(Symbol.CreateSymbol(name))); }