protected void EmitClassDeclaration(ObjectExpression classDecl) { var attrs = AphidAttributeParser.Parse <ObjectStatementAttributes>( classDecl.Identifier, out var unparsed); if (attrs.IsInterface && attrs.IsAbstract) { throw new InvalidOperationException("Interfaces cannot be abstract."); } else if ((attrs.IsInterface && attrs.IsClass) || (!attrs.IsInterface && !attrs.IsClass)) { throw new InvalidOperationException("Type must be interface or class."); } if (attrs.IsAbstract) { Append("abstract "); } Append(attrs.IsClass ? "class " : "interface "); Append(classDecl.Identifier.Identifier); bool first = true, extend = true; foreach (var attr in unparsed) { if (extend) { if (attr == "impl") { extend = false; first = true; } else { if (first) { Append(" extends "); first = false; } else { Append(", "); } Append(attr); } } else { if (first) { Append(" implements "); first = false; } else { Append(", "); } Append(attr); } } Append(" {\r\n"); Indent(); foreach (var member in classDecl.Pairs) { EmitClassMember(classDecl, member); } Unindent(); Append(GetTabs() + "}"); }
public override ObjectExpression <T> ReadJson(JsonReader reader, Type objectType, ObjectExpression <T> existingValue, bool hasExistingValue, JsonSerializer serializer) { if (reader.ValueType == typeof(string)) { return(new ObjectExpression <T>((string)reader.Value)); } else { return(new ObjectExpression <T>(JToken.Load(reader))); } }
public JintObjectExpression(Engine engine, ObjectExpression expression) : base(engine, expression) { _initialized = false; }
public override object?Visit(ObjectExpression node) { AddNodeInfo(); VisitChildren(node.Elements.Cast <Node>().ToArray()); return(null); }
public Type CreateType(ObjectExpression type, HashSet <string> imports) { if (type.Identifier == null || type.Identifier.Attributes.Count == 0) { throw new InvalidOperationException("ObjectExpression has no type class attributes."); } var state = ClassAttributeScanState.Starting; var scanner = new AphidAttributeScanner(type.Identifier); scanner.Next(); var defaultType = "System.Object"; var defaultTypeSet = false; var interfaces = new List <Type>(); Type baseType = null; do { switch (state) { case ClassAttributeScanState.Starting: scanner.Require(AphidName.Class); state = ClassAttributeScanState.InClass; break; case ClassAttributeScanState.InClass: if (scanner.Match(AphidName.Of)) { if (defaultTypeSet || scanner.CurrentAttribute == null) { throw Interpreter.CreateRuntimeException("Invalid 'of' attribute."); } defaultType = scanner.CurrentAttribute; defaultTypeSet = true; scanner.Next(); break; } else if (!scanner.EndOfStream()) { var superType = ResolveBaseType(scanner.CurrentAttribute); scanner.Next(); if (superType == null) { throw Interpreter.CreateRuntimeException( "Could not resolve base type {0} in class declaration '{1}'.", scanner.CurrentAttribute, type.ToString()); } else if (superType.IsInterface) { interfaces.Add(superType); } else { baseType = baseType == null ? superType : throw Interpreter.CreateRuntimeException( "Type is already subclass of {0}, cannot inherit from {1}.", baseType, superType); } } else { throw Interpreter.CreateRuntimeException( "Invalid class attribute '{0}'.", scanner.CurrentAttribute); } break; default: throw Interpreter.CreateRuntimeException( "Invalid class attribute '{0}'.", scanner.CurrentAttribute); } } while (!scanner.EndOfStream()); if (state != ClassAttributeScanState.InClass) { throw new AphidParserException("Invalid class attributes."); } var name = type.Identifier.Identifier; TypeBuilder typeBuilder = baseType == null && interfaces.Count == 0 ? _moduleBuilder.Value.DefineType( name, TypeAttributes.Public) : interfaces.Count == 0 ? _moduleBuilder.Value.DefineType( name, TypeAttributes.Public, baseType) : _moduleBuilder.Value.DefineType( name, TypeAttributes.Public, baseType, interfaces.ToArray()); foreach (var kvp in type.Pairs) { if (kvp.LeftOperand.Type != AphidExpressionType.IdentifierExpression) { throw Interpreter.CreateRuntimeException("Invalid class property lhs."); } if (kvp.RightOperand.Type == AphidExpressionType.IdentifierExpression && kvp.LeftOperand.ToIdentifier().Identifier == kvp.RightOperand.ToIdentifier().Identifier) { AddProperty(typeBuilder, defaultType, kvp.LeftOperand.ToIdentifier(), imports); } else { throw new NotImplementedException(); } } var t = typeBuilder.CreateType(); _types.Add(t.FullName); return(t); }
protected override void VisitObjectExpression(ObjectExpression objectExpression) { using (StartNodeObject(objectExpression)) Member("properties", objectExpression.Properties); }
/// <summary> /// Deserializes the given JSON object expression to an object of the given type. /// </summary> /// <param name="objectExpression">JSON object expression to deserialize.</param> /// <param name="type">Type to deserialize to.</param> /// <returns>Deserialized object for the JSON expression tree.</returns> private static object DeserializeObject(ObjectExpression objectExpression, Type type) { if (type == typeof(object)) { type = typeof(Dictionary <string, object>); } var res = Activator.CreateInstance(type); var iDict = type.GetInterface("System.Collections.Generic.IDictionary`2", false); if (iDict != null) { var args = iDict.GetGenericArguments(); if (args[0] != typeof(string) && args[0] != typeof(object)) { throw new SerializationException("Objects can only be deserialized to generic dictionary types if a string key is used."); } Type valuesType = args[1]; var add = iDict.GetMethod("Add"); foreach (var member in objectExpression.Members) { var memberName = member.Key; add.Invoke(res, new object[] { memberName, Deserialize(member.Value, valuesType) }); } } else if (typeof(IDictionary).IsAssignableFrom(type)) { var iDictObj = (IDictionary)res; foreach (var member in objectExpression.Members) { var memberName = member.Key; iDictObj.Add(memberName, Deserialize(member.Value, typeof(object))); } } else { foreach (var member in objectExpression.Members) { var memberName = member.Key; var property = type.GetProperty(memberName, BindingFlags.Public | BindingFlags.Instance); var field = type.GetField(memberName, BindingFlags.Public | BindingFlags.Instance); if (property != null) { if (property.GetSetMethod(false) == null) { throw new SerializationException("Property '" + memberName + "' on " + type + " is not settable."); } try { property.SetValue(res, Deserialize(member.Value, property.PropertyType), null); } catch (TargetInvocationException ex) { throw new SerializationException("Failed to set property '" + property.Name + "' on " + type + ".", ex); } } else if (field != null) { field.SetValue(res, Deserialize(member.Value, field.FieldType)); } else { throw new SerializationException("Can't find property or field '" + memberName + "' on " + type + "."); } } } return(res); }
/// <summary> /// Evaluates the expression and populates an existing object with the expression's properties /// </summary> /// <param name="expression">json object expression</param> /// <param name="existingObject">the existing object to populate</param> /// <param name="deserializer">deserializer for deserializing key values</param> /// <returns>deserialized object</returns> public override object Evaluate(Expression expression, object existingObject, IDeserializerHandler deserializer) { TypeData typeHandler = Context.GetTypeHandler(existingObject.GetType()); ObjectExpression objectExpression = (ObjectExpression)expression; foreach (KeyValueExpression Item in objectExpression.Properties) { // evaluate the item and let it assign itself? IPropertyData hndlr = typeHandler.FindProperty(Item.Key); if (hndlr == null) { throw new Exception(string.Format("Could not find property {0} for type {1}", Item.Key, typeHandler.ForType)); } if (hndlr.Ignored) { switch (Context.IgnoredPropertyAction) { case SerializationContext.IgnoredPropertyOption.Ignore: continue; case SerializationContext.IgnoredPropertyOption.SetIfPossible: if (!hndlr.CanWrite) { continue; } break; case SerializationContext.IgnoredPropertyOption.ThrowException: throw new Exception(string.Format("Can not set property {0} for type {1} because it is ignored and IgnorePropertyAction is set to ThrowException", Item.Key, typeHandler.ForType)); } } Expression valueExpression = Item.ValueExpression; valueExpression.ResultType = hndlr.PropertyType; object result = null; TypeConverterExpressionHandler converterHandler = null; IJsonTypeConverter converter = null; if (hndlr.HasConverter) { converterHandler = (TypeConverterExpressionHandler)Context.ExpressionHandlers.Find(typeof(TypeConverterExpressionHandler)); converter = hndlr.TypeConverter; } if (!hndlr.CanWrite) { result = hndlr.GetValue(existingObject); if (converterHandler != null) { converterHandler.Evaluate(valueExpression, result, deserializer, converter); } else { deserializer.Evaluate(valueExpression, result); } } else { if (hndlr.HasConverter) { hndlr.SetValue(existingObject, converterHandler.Evaluate(valueExpression, deserializer, converter)); } else { hndlr.SetValue(existingObject, deserializer.Evaluate(valueExpression)); } } } return(existingObject); }
/// <summary> /// Evaluate the method call. Use a list of evaluators to try to accomplish the call. /// </summary> /// <param name="c"></param> /// <returns></returns> public object Evaluate(IScopeContext c) { // All functions and the source object must evaluate correctly. Further, since we want to do the // evaluate only once, we do it here, at the top. var obj = ObjectExpression.Evaluate(c); var args = FunctionCall.Arguments.Select(a => a.Evaluate(c)).ToArray(); // Find the first evaluator that can figure out what this is. var goodEval = ExtensibilityControl.Get().MethodEvaluators .Select(e => e.Evaluate(c, obj, FunctionCall.FunctionName, args)).Where(r => r.Item1).FirstOrDefault(); if (goodEval != null) { return(c.ExecutionContext.ExecutePostCallHook(FunctionCall.FunctionName, obj, goodEval.Item2)); } throw new InvalidOperationException(string.Format("Don't know how to call the function {0} on the object {1} of type {2}.", FunctionCall.ToString(), ObjectExpression.ToString(), obj.GetType().Name)); }
protected override void Visit(ObjectExpression node) { Encode(node, Member("properties", node.Properties)); }
[DebuggerStepThrough] protected virtual void EmitObjectExpression(ObjectExpression expression, bool isStatement = false) { throw new NotImplementedException(); }
protected override IndexerExpression?Transform(ObjectExpression ox) { return(null); }
public abstract T Visit(ObjectExpression node);
protected void EmitClassMember( ObjectExpression classDecl, BinaryOperatorExpression member) { if (member.LeftOperand.Type != AphidExpressionType.IdentifierExpression) { throw new InvalidOperationException("Expected identifier expression on lhs of class member."); } var id = member.LeftOperand.ToIdentifier(); var attrs = AphidAttributeParser.Parse <MemberDeclarationAttributes>(id); if ((attrs.IsPrivate && attrs.IsProtected) || (attrs.IsPrivate && attrs.IsPublic) || (attrs.IsProtected && attrs.IsPrivate) || (attrs.IsProtected && attrs.IsPublic) || (attrs.IsPublic && attrs.IsPrivate) || (attrs.IsPublic && attrs.IsProtected)) { throw new InvalidOperationException("Member must be private, protected, or public."); } if (!attrs.IsPrivate && !attrs.IsProtected && !attrs.IsPublic) { attrs.IsPrivate = true; } if (attrs.IsPrivate && attrs.IsAbstract) { throw new InvalidOperationException("Member cannot be both private and abstract."); } var access = attrs.IsPrivate ? "private " : attrs.IsProtected ? "protected " : "public "; Append(GetTabs() + access); if (attrs.IsAbstract) { Append("abstract "); } if (member.RightOperand.Type == AphidExpressionType.FunctionExpression) { attrs.IsFunction = true; } if (attrs.IsFunction) { Append("function "); } else { Append("$"); } Append(id.Identifier); var hasInitializer = member.RightOperand.Type != AphidExpressionType.IdentifierExpression || id.Identifier != member.RightOperand.ToIdentifier().Identifier; if (!attrs.IsFunction) { if (hasInitializer) { Append(" = "); Emit(member.RightOperand); } } else { if (hasInitializer) { if (member.RightOperand.Type != AphidExpressionType.FunctionExpression) { throw new InvalidOperationException(); } var func = member.RightOperand.ToFunction(); Append("("); EmitTuple(func.Args); Append(") {\r\n"); Indent(); Emit(func.Body); Unindent(); Append(GetTabs() + "}\r\n\r\n"); } } if (!attrs.IsFunction || !hasInitializer) { Append(";\r\n"); } }
/// <summary> /// Generates an expression for an item and adds it to the object /// </summary> /// <param name="data">the item being serialized</param> /// <param name="currentPath">the current path to the object</param> /// <param name="serializer">serializer instance</param> /// <param name="expression">the object expression</param> /// <param name="prop">the property being serialized</param> protected virtual void GenerateItemExpression(object data, JsonPath currentPath, IExpressionBuilder serializer, ObjectExpression expression, IPropertyData prop) { object value = prop.GetValue(data); if (!prop.ShouldWriteValue(this.Settings, value)) { return; } Expression valueExpr; if (prop.HasConverter) { valueExpr = serializer.Serialize(value, currentPath.Append(prop.Alias), prop.TypeConverter); } else { valueExpr = serializer.Serialize(value, currentPath.Append(prop.Alias)); } if (value != null && !ReflectionUtils.AreEquivalentTypes(value.GetType(), prop.PropertyType)) { valueExpr = new CastExpression(value.GetType(), valueExpr); } expression.Add(prop.Alias, valueExpr); }
/// <summary> /// Pretty-print to help with debugging and testing. /// </summary> /// <returns></returns> public override string ToString() { return(string.Format("{0}.{1}", ObjectExpression.ToString(), FunctionCall.ToString())); }
protected internal override void VisitObjectExpression(ObjectExpression objectExpression) { VisitingObjectExpression?.Invoke(this, objectExpression); base.VisitObjectExpression(objectExpression); VisitedObjectExpression?.Invoke(this, objectExpression); }
public void evalInstruction(InstructionExpression instr) { if (instr is ValueExpression) { valueExp = (ValueExpression)instr; if (valueExp.type == ObjectType.intType) { variables.Add(valueExp.name, new ObjectExpression(valueExp.type, 0)); } else if (valueExp.type == ObjectType.booleanType) { variables.Add(valueExp.name, new ObjectExpression(valueExp.type, false)); } else if (valueExp.type == ObjectType.stringType) { variables.Add(valueExp.name, new ObjectExpression(valueExp.type, "")); } if (valueExp.value != null) { variables[valueExp.name] = new ObjectExpression(valueExp.type, evalSimpleExpression(valueExp.value).value); } return; } else if (instr is AssignExpression) { assignExp = (AssignExpression)instr; variables[assignExp.name] = evalSimpleExpression(assignExp.value); return; } else if (instr is OpenMsgDialogInstruction) { gScreen.msgBox.openBox(); return; } else if (instr is MsgDisplayInstruction) { msgExp = (MsgDisplayInstruction)instr; o1 = evalSimpleExpression(msgExp.msg); if (o1.type != ObjectType.stringType) { return; } gScreen.msgBox.setText((string)o1.value); return; } else if (instr is NextMsgDialogInstruction) { shouldEvalSeq = false; gScreen.msgBox.showNextButton(); return; } else if (instr is CloseMsgDialogInstruction) { shouldEvalSeq = false; gScreen.msgBox.showCloseButton(); return; } else if (instr is SwitchCharacterInstruction) { try { gScreen.msgBox.switchCharacter(IrisData.characters[((SwitchCharacterInstruction)instr).character.name]); } catch (Exception e) { return; } return; } else if (instr is RemoveCharacter) { gScreen.msgBox.removeCharacter(); return; } else if (instr is SetVariableInstruction) { setExp = (SetVariableInstruction)instr; /*if (!playerVariables.ContainsKey(setExp.variable.name)) * { * playerVariables.Add(setExp.variable.name, -1); * } * * playerVariables[setExp.variable.name] = (int)(evalSimpleExpression(setExp.value).value);*/ IrisData.setPlayerVariable(setExp.variable.name, (int)(evalSimpleExpression(setExp.value).value)); return; } else if (instr is InputInstruction) { inputExp = (InputInstruction)instr; o1 = variables[inputExp.name]; shouldEvalSeq = false; if (o1.type == ObjectType.intType) { gScreen.iBox.openBox(InputBox.InputType.INT_INPUT); lastInstr = inputExp; } else if (o1.type == ObjectType.stringType) { gScreen.iBox.openBox(InputBox.InputType.STRING_INPUT); lastInstr = inputExp; } return; } else if (instr is MenuInstruction) { menuExp = (MenuInstruction)instr; shouldEvalSeq = false; gScreen.menBox.setChoices(((MenuInstruction)instr).choices); gScreen.menBox.openMenu(); lastInstr = menuExp; return; } else if (instr is PlayMediaInstruction) { playExp = (PlayMediaInstruction)instr; /*if (!IrisData.sounds.ContainsKey(playExp.name)) * { * return; * }*/ //else if(IrisData. try { gScreen.playMedia(IrisData.sounds[playExp.name]); } catch (Exception e) { return; } return; } else if (instr is StopMediaInstruction) { gScreen.stopMedia(); return; } else if (instr is ShowImageInstruction) { showExp = (ShowImageInstruction)instr; if (showExp.image is VariableExpression) { img = IrisData.images[((VariableExpression)showExp.image).name]; } else { memberExp = (MemberAccessExpression)showExp.image; charac = IrisData.characters[memberExp.name]; img = charac.getImage(memberExp.field); } gScreen.showImage(img, showExp.position); return; } else if (instr is SetBackgroundInstruction) { bgdInstr = (SetBackgroundInstruction)instr; try { gScreen.setBackground(IrisData.backgrounds[bgdInstr.image.name]); } catch (Exception e) { return; } return; } else if (instr is CleanBackgroundInstruction) { gScreen.clearBackground(); return; } else if (instr is CleanForegroundInstruction) { gScreen.clearForeGround(); return; } else if (instr is GotoInstruction) { gotoExp = (GotoInstruction)instr; npcExp = gotoExp.npc; evalExpression(IrisData.npcs[npcExp.npc].labels[npcExp.label]); return; } }
private IRequireConfiguration ParseFromObjectExpression(SyntaxNode root, ObjectExpression expression) { return(_configurationParser.Parse(expression, root)); }
public void evalExpression(Expression exp) { if (exp == null) { return; } if (exp is InstructionExpression) { evalInstruction((InstructionExpression)exp); return; } else if (exp is SequenceExpression) { SequenceExpression seqExp = (SequenceExpression)exp, seqTmp; Expression expTmp; int index = insertIndex; seqTmp = new SequenceExpression(new List <Expression>(seqExp.exps)); seqs.Add(seqExp); runningSeqs.Add(seqTmp); index = runningSeqs.Count - 1; while (seqTmp.exps.Count > 0) { expTmp = seqTmp.exps.ElementAt(0); evalExpression(expTmp); seqTmp.exps.RemoveAt(0); if (!shouldEvalSeq) { if (seqTmp.exps.Count == 0) { runningSeqs.RemoveAt(index); } return; } } runningSeqs.RemoveAt(runningSeqs.Count - 1); removeDeclaredVariables(seqs.ElementAt(seqs.Count - 1).declaredVariables()); seqs.RemoveAt(seqs.Count - 1); return; } else if (exp is IfExpression) { ifExp = (IfExpression)exp; o1 = evalSimpleExpression(ifExp.condition); if ((bool)o1.value) { evalExpression(ifExp.body); return; } if (ifExp.elseIfList != null) { foreach (ElseIfExpression elseIfExp in ifExp.elseIfList) { o1 = evalSimpleExpression(elseIfExp.condition); if ((bool)o1.value) { evalExpression(elseIfExp.corps); return; } } } if (ifExp.elseBlock != null) { evalExpression(ifExp.elseBlock.body); return; } return; } else if (exp is SwitchExpression) { switchExp = (SwitchExpression)exp; o1 = evalSimpleExpression(switchExp.exp); foreach (SwitchCaseExpression sce in switchExp.cases) { if (sce is CaseExpression) { if (o1.type == ObjectType.stringType && isCatched((string)o1.value, sce, false)) { return; } else if (o1.type == ObjectType.intType && isCatched((int)o1.value, sce, false)) { return; } } else if (sce is DefaultExpression) { evalExpression(((DefaultExpression)sce).body); return; } } return; } else if (exp is WhileExpression) { whileExp = (WhileExpression)exp; while (true) { o1 = evalSimpleExpression(whileExp.condition); if (!(bool)o1.value) { return; } evalExpression(whileExp.body); } } else if (exp is DoWhileExpression) { doWhileExp = (DoWhileExpression)exp; do { evalExpression(doWhileExp.body); o1 = evalSimpleExpression(doWhileExp.condition); if (!(bool)o1.value) { return; } } while (true); } else if (exp is ForExpression) { forExp = (ForExpression)exp; evalExpression(forExp.init); while (true) { o1 = evalSimpleExpression(forExp.condition); if (!(bool)o1.value) { return; } evalExpression(forExp.body); evalExpression(forExp.maj); } } }
protected override ExpressionBody Transform(ObjectExpression ox) { var names = new List <string>(); var values = new List <ExpressionBody>(); var i = 0; for (; i < ox.Members.Length; ++i) { var member = ox.Members[i]; if (member is PropertyMember property) { if (names.Contains(property.Name)) { var oldPos = names.IndexOf(property.Name); values[oldPos] = Transform(property.Value); } else { names.Add(property.Name); values.Add(Transform(property.Value)); } } else { break; } } var namesConstant = LX.Constant(names.ToArray(), typeof(string[])); var valuesArr = LX.NewArrayInit(typeof(LogEventPropertyValue), values.ToArray()); var properties = LX.Call(CollectStructurePropertiesMethod, namesConstant, valuesArr); if (i == ox.Members.Length) { // No spreads; more efficient than `Complete*` because erasure is not required. return(LX.Call(ConstructStructureValueMethod, properties)); } for (; i < ox.Members.Length; ++i) { var member = ox.Members[i]; if (member is PropertyMember property) { properties = LX.Call( ExtendStructureValueWithPropertyMethod, properties, LX.Constant(property.Name), Transform(property.Value)); } else { var spread = (SpreadMember)member; properties = LX.Call( ExtendStructureValueWithSpreadMethod, properties, Transform(spread.Content)); } } return(LX.Call(CompleteStructureValueMethod, properties)); }
public ObjectExpression evalSimpleExpression(SimpleExpression exp) { if (exp is LiteralExpression) { lit = (LiteralExpression)exp; switch (lit.value.type) { case ParserUtils.Token.TokenValue.STRING: return(new ObjectExpression(ObjectType.stringType, lit.value.stringValue)); case ParserUtils.Token.TokenValue.INT: return(new ObjectExpression(ObjectType.intType, lit.value.intValue)); case ParserUtils.Token.TokenValue.CHAR: return(new ObjectExpression(ObjectType.charType, lit.value.charValue)); case ParserUtils.Token.TokenValue.BOOLEAN: return(new ObjectExpression(ObjectType.booleanType, lit.value.booleanValue)); default: break; } } else if (exp is SubSimpleExpression) { return(evalSimpleExpression(((SubSimpleExpression)exp).exp)); } else if (exp is NullExpression) { return(null); } else if (exp is BinaryOperatorExpression) { BinaryOperatorExpression binExp = (BinaryOperatorExpression)exp; ObjectExpression oLeft = evalSimpleExpression(binExp.e1), oRight; switch (binExp.op) { case ParserUtils.Token.TokenValue.AND: if ((bool)oLeft.value) { oRight = evalSimpleExpression(binExp.e2); return(new ObjectExpression(ObjectType.booleanType, (bool)oRight.value)); } return(new ObjectExpression(ObjectType.booleanType, false)); case ParserUtils.Token.TokenValue.OR: if ((bool)oLeft.value) { return(new ObjectExpression(ObjectType.booleanType, true)); } oRight = evalSimpleExpression(binExp.e2); return(new ObjectExpression(ObjectType.booleanType, (bool)oRight.value)); case ParserUtils.Token.TokenValue.PLUS: oRight = evalSimpleExpression(binExp.e2); if (oLeft.type == ObjectType.stringType || oRight.type == ObjectType.stringType) { return(new ObjectExpression(ObjectType.stringType, oLeft.value.ToString() + oRight.value.ToString())); } if (oLeft.type == ObjectType.intType && oRight.type == ObjectType.intType) { return(new ObjectExpression(ObjectType.intType, (int)oLeft.value + (int)oRight.value)); } break; case ParserUtils.Token.TokenValue.MINUS: oRight = evalSimpleExpression(binExp.e2); return(new ObjectExpression(ObjectType.intType, (int)oLeft.value - (int)oRight.value)); case ParserUtils.Token.TokenValue.TIMES: oRight = evalSimpleExpression(binExp.e2); return(new ObjectExpression(ObjectType.intType, (int)oLeft.value * (int)oRight.value)); case ParserUtils.Token.TokenValue.DIV: oRight = evalSimpleExpression(binExp.e2); return(new ObjectExpression(ObjectType.intType, (int)oLeft.value / (int)oRight.value)); case ParserUtils.Token.TokenValue.LT: oRight = evalSimpleExpression(binExp.e2); return(new ObjectExpression(ObjectType.booleanType, (int)oLeft.value < (int)oRight.value)); case ParserUtils.Token.TokenValue.GT: oRight = evalSimpleExpression(binExp.e2); return(new ObjectExpression(ObjectType.booleanType, (int)oLeft.value > (int)oRight.value)); case ParserUtils.Token.TokenValue.LEQ: oRight = evalSimpleExpression(binExp.e2); return(new ObjectExpression(ObjectType.booleanType, (int)oLeft.value <= (int)oRight.value)); case ParserUtils.Token.TokenValue.GEQ: oRight = evalSimpleExpression(binExp.e2); return(new ObjectExpression(ObjectType.booleanType, (int)oLeft.value >= (int)oRight.value)); case ParserUtils.Token.TokenValue.EQBOOL: oRight = evalSimpleExpression(binExp.e2); if (oLeft.type == ObjectType.intType) { return(new ObjectExpression(ObjectType.booleanType, (int)oLeft.value == (int)oRight.value)); } if (oLeft.type == ObjectType.stringType) { return(new ObjectExpression(ObjectType.booleanType, ((string)oLeft.value).Equals((string)oRight.value))); } if (oLeft.type == ObjectType.booleanType) { return(new ObjectExpression(ObjectType.booleanType, (bool)oLeft.value == (bool)oRight.value)); } if (oLeft.type == ObjectType.charType) { return(new ObjectExpression(ObjectType.booleanType, (char)oLeft.value == (char)oRight.value)); } break; default: break; } } else if (exp is UnaryOperatorExpression) { unExp = (UnaryOperatorExpression)exp; switch (unExp.op) { case ParserUtils.Token.TokenValue.NEG: o1 = evalSimpleExpression(((UnaryOperatorExpression)exp).exp); return(new ObjectExpression(ObjectType.booleanType, !((bool)o1.value))); } } else if (exp is VariableExpression) { return(variables[((VariableExpression)exp).name]); } else if (exp is CharacterVariableExpression) { return(new ObjectExpression(ObjectType.intType, IrisData.getPlayerVariable(((CharacterVariableExpression)exp).name))); } return(null); }
protected abstract void Visit(ObjectExpression node);
/// <summary> /// Called on an object expression after the properties and constructor arguments are visited /// </summary> /// <param name="expression"></param> public virtual void OnObjectEnd(ObjectExpression expression) { }
/// <summary> /// Compiles this OPathQuery using the mappings found in the specified ObjectSpace instance. /// </summary> /// <param name="os">ObjectSpace instance to use.</param> /// <returns>A CompiledQuery that is the result of this instance being compiled.</returns> public new CompiledQuery <T> Compile(ObjectSpace os) { ObjectExpression oe = OPath.Parse(this, os.context.Mappings); return(new CompiledQuery <T>(oe)); }
/// <summary> /// Called on an object expression before the properties and constructor arguments are visited /// </summary> /// <param name="expression"></param> public virtual void OnObjectStart(ObjectExpression expression) { }
public JsValue EvaluateObjectExpression(ObjectExpression objectExpression) { // http://www.ecma-international.org/ecma-262/5.1/#sec-11.1.5 var obj = _engine.Object.Construct(Arguments.Empty); foreach (var property in objectExpression.Properties) { var propName = property.Key.GetKey(); var previous = obj.GetOwnProperty(propName); PropertyDescriptor propDesc; switch (property.Kind) { case PropertyKind.Data: var exprValue = _engine.EvaluateExpression(property.Value); var propValue = _engine.GetValue(exprValue); propDesc = new PropertyDescriptor(propValue, true, true, true); break; case PropertyKind.Get: var getter = property.Value as FunctionExpression; if (getter == null) { throw new JavaScriptException(_engine.SyntaxError); } ScriptFunctionInstance get; using (new StrictModeScope(getter.Strict)) { get = new ScriptFunctionInstance( _engine, getter, _engine.ExecutionContext.LexicalEnvironment, StrictModeScope.IsStrictModeCode ); } propDesc = new PropertyDescriptor(get: get, set: null, enumerable: true, configurable: true); break; case PropertyKind.Set: var setter = property.Value as FunctionExpression; if (setter == null) { throw new JavaScriptException(_engine.SyntaxError); } ScriptFunctionInstance set; using (new StrictModeScope(setter.Strict)) { set = new ScriptFunctionInstance( _engine, setter, _engine.ExecutionContext.LexicalEnvironment, StrictModeScope.IsStrictModeCode ); } propDesc = new PropertyDescriptor(get: null, set: set, enumerable: true, configurable: true); break; default: throw new ArgumentOutOfRangeException(); } if (previous != PropertyDescriptor.Undefined) { if (StrictModeScope.IsStrictModeCode && previous.IsDataDescriptor() && propDesc.IsDataDescriptor()) { throw new JavaScriptException(_engine.SyntaxError); } if (previous.IsDataDescriptor() && propDesc.IsAccessorDescriptor()) { throw new JavaScriptException(_engine.SyntaxError); } if (previous.IsAccessorDescriptor() && propDesc.IsDataDescriptor()) { throw new JavaScriptException(_engine.SyntaxError); } if (previous.IsAccessorDescriptor() && propDesc.IsAccessorDescriptor()) { if (propDesc.Set != null && previous.Set != null) { throw new JavaScriptException(_engine.SyntaxError); } if (propDesc.Get != null && previous.Get != null) { throw new JavaScriptException(_engine.SyntaxError); } } } obj.DefineOwnProperty(propName, propDesc, false); } return(obj); }
private UstExprs.Expression VisitObjectExpression(ObjectExpression objectExpression) { var properties = VisitProperties(objectExpression.Properties); return(new UstExprs.AnonymousObjectExpression(properties, GetTextSpan(objectExpression))); }
public override void WriteScheme(StringBuilder b) { ObjectExpression.WriteScheme(b); b.Append("."); b.Append(MemberName); }
public JintObjectExpression(ObjectExpression expression) : base(expression) { _initialized = false; }