public void CallKnownMethodeOnItselfWithThis() { var tmpProject = new ProjectInformation(); var tmpClass1 = Create.AddClass("Class1"); tmpProject.FillClasses(new List <ClassContainer> { tmpClass1 }); var tmpMethodeName = "compareTo"; tmpClass1.AddMethode(tmpMethodeName, new TypeContainer { Name = "void" }); var tmpMethode = tmpClass1.MethodeList[0]; tmpMethode.Code = new CodeBlock(); var tmpMethodeCall = Create.CallMethode(new CodeBlock(), tmpMethodeName); var tmpVarAccess = new VariableAccess() { Access = new ConstantValue("this"), Child = tmpMethodeCall, }; tmpMethode.Code.CodeEntries.Add(tmpVarAccess); new AnalyzerCore().LinkProjectInformation(tmpProject); tmpMethode.Name = "Blah"; Assert.AreEqual(tmpMethode, tmpMethodeCall.MethodeLink); }
public static async Task <T> CreateVariable <T>(string name, string model, string eqn, GraphicalFunction graph, Range range, Range scale, NonNegative nonNegative, VariableAccess access) where T : IVariable, new() { var variable = new T { Model = model, Name = StringUtils.CleanName(name), GraphicalFunction = graph, Range = range, Scale = scale, Units = Units.CreateInstanceFromEquation(eqn), NonNegative = nonNegative, Access = access }; variable.FullName = StringUtils.FullName(variable.Model, variable.Name); var factory = await EquationFactory.CreateInstance(model, eqn); variable.Equation = factory.Equation; variable.Value = factory.Value; variable.AdjustValue(factory.Value); variable.Initialize(); variable.SetChildren(); return(variable); }
public void VariableAccess(VariableAccess variableAccess) { _il.Emit(OpCodes.Ldarg_0); ILUtil.EmitConstant(_il, variableAccess.ParameterIndex); _il.Emit(OpCodes.Ldelem_Ref); _compiler.ExtendedConvertToType(typeof(object), variableAccess.Type, false); }
/// <summary> /// Génère le code d'un accès à une variable. /// </summary> /// <param name="access"></param> /// <returns></returns> string GenerateVariableAccess(VariableAccess access) { if (access.Left.Type.GetFullName() == Core.Model.Language.SemanticConstants.StateClass) { return("this." + access.VariableName); } return(GenerateEvaluable(access.Left) + "." + access.VariableName); }
private static IExpression VariableAccess(int identifierIndex, Type identifierType) { var variableAccess = new VariableAccess(identifierType, identifierIndex); if (typeof(DynamicExpression).IsAssignableFrom(identifierType)) { var methodCall = new Expressions.MethodCall( variableAccess, typeof(DynamicExpression).GetMethod("Invoke", new Type[0]), null ); if (variableAccess.Type.IsGenericType) { var resultType = identifierType.GetGenericArguments()[0]; return(new Expressions.Cast(methodCall, resultType)); } else { return(methodCall); } } else if (typeof(IBoundExpression).IsAssignableFrom(identifierType)) { var methodCall = new Expressions.MethodCall( variableAccess, typeof(IBoundExpression).GetMethod("Invoke", new Type[0]), null ); foreach (var @interface in identifierType.GetInterfaces()) { if ( @interface.IsGenericType && @interface.GetGenericTypeDefinition() == typeof(IBoundExpression <>) ) { var resultType = identifierType.GetGenericArguments()[0]; return(new Expressions.Cast(methodCall, resultType)); } } return(methodCall); } else { return(variableAccess); } }
public static async Task <Flow> CreateInstance(string name, XMileModel model, string eqn, GraphicalFunction graph, Range range, Range scale, NonNegative nonNegative, VariableAccess access) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var variable = await CreateFlow(name, model.Name, eqn, graph, range, scale, nonNegative, access); model.Variables.Add(variable); return(variable); }
/// <summary> /// Génère le code d'un accès à une variable. /// </summary> /// <param name="access"></param> /// <returns></returns> string GenerateVariableAccess(VariableAccess access) { if (access.Left.Type.GetFullName() == Core.Model.Language.SemanticConstants.StateClass) { return("this->" + access.VariableName); } string left = GenerateEvaluable(access.Left); if (left == "this") { return(left + "->" + access.VariableName); } else { return(left + "." + access.VariableName); } }
public IEnumerable <Expression> ExtractTemporaryVariables(VariableAccess variableAccess, Expression node) { return(new ExtractorProcess(variableAccess).ExtractTemporaryVariables(node)); }
public bool HasAccess(VariableAccess access) { return((Access & access) != 0); }
private void PrintResolvedVariableAccess(VariableAccess node, int indent) { AppendLine(indent, "ParameterIndex = " + node.ParameterIndex); }
public VariableAccessException(VariableAccess requested, VariableAccess available) : base(string.Format("{0} access required for VariableStore with access {1}", requested, available)) { RequestedAccess = requested; AvailableAccess = available; }
public void RestrictAccess(VariableAccess access) { Access &= ~access; }
public void AddAccess(VariableAccess access) { Access |= access; }
public ExtractorProcess(VariableAccess variableAccess) { this.variableAccess = variableAccess; }
private static async Task <Auxiliary> CreateAuxiliary(string name, string model, string eqn, GraphicalFunction graph, Range range, Range scale, NonNegative nonNegative, VariableAccess access) { return(await CreateVariable <Auxiliary>(name, model, eqn, graph, range, scale, nonNegative, access)); }
private static async Task <Stock> CreateStock(string name, string model, string eqn, List <string> inflow, List <string> outflow, GraphicalFunction graph, Range range, Range scale, NonNegative nonNegative, VariableAccess access) { var stock = await CreateVariable <Stock>(name, model, eqn, graph, range, scale, nonNegative, access); stock.Inflow = StringUtils.CleanNames(inflow); stock.Outflow = StringUtils.CleanNames(outflow); stock.SetChildren(); return(stock); }
/// <summary> /// Génère le code d'un accès à une variable. /// </summary> /// <param name="access"></param> /// <returns></returns> static string GenerateVariableAccess(VariableAccess access) { // TODO : gérer state etc...s return(GenerateEvaluable(access.Left) + "." + access.VariableName); }
/// <summary> /// Handling of an Expression Block /// </summary> /// <param name="inCodeBlock"></param> /// <param name="inBlockStatement"></param> public void HandleExpressionContext(CodeBlock inCodeBlock, ExpressionContext inBlockStatement, VariableDeclaration inVariable = null) { if (inBlockStatement == null) { return; } //if (inBlockStatement.IDENTIFIER() != null) //{ // inCodeBlock.CodeEntries.Add(new ConstantValue { Value = inBlockStatement.IDENTIFIER().GetText() }); //} //else if (inBlockStatement.THIS() != null) //{ // throw new NotImplementedException("Not done yet"); //} //else if (inBlockStatement.NEW() != null) //{ // throw new NotImplementedException("Not done yet"); //} //else if (inBlockStatement.SUPER() != null) //{ // throw new NotImplementedException("Not done yet"); //} //else if (inBlockStatement.INSTANCEOF() != null) //{ // throw new NotImplementedException("Not done yet"); //} //else { if (inBlockStatement.primary() != null) { //Primary Value analyse type var tmpPrimary = inBlockStatement.primary(); var tmpPrimaryAsText = tmpPrimary.GetText(); if (tmpPrimary.expression() != null) { var tmpCodeBlock = new CodeBlockContainer(); HandleExpressionContext(tmpCodeBlock.InnerBlock, tmpPrimary.expression(), inVariable); inCodeBlock.CodeEntries.Add(tmpCodeBlock); } else if (tmpPrimary.literal() != null) { inCodeBlock.CodeEntries.Add(new ConstantValue { Value = tmpPrimaryAsText }); } else if (tmpPrimary.typeTypeOrVoid() != null) { var tmpType = JavaAntlrClassLoader.CreateTypeContainerFromType(tmpPrimary.typeTypeOrVoid()); var tmpConst = new ConstantValue { Type = tmpType, Value = tmpPrimary.typeTypeOrVoid().typeType().GetText() }; if (tmpPrimary.CLASS() != null) { var tmpVariableAccess = new VariableAccess(); tmpVariableAccess.Access = tmpConst; tmpVariableAccess.Child = new ConstantValue { Value = "class" }; inCodeBlock.CodeEntries.Add(tmpConst); } else { inCodeBlock.CodeEntries.Add(tmpConst); } } else if (tmpPrimary.nonWildcardTypeArguments() != null) { throw new NotImplementedException("Not done yet"); } else if (tmpPrimary.explicitGenericInvocationSuffix() != null) { throw new NotImplementedException("Not done yet"); } else if (tmpPrimary.arguments() != null) { throw new NotImplementedException("Not done yet"); } else { inCodeBlock.CodeEntries.Add(new ConstantValue { Value = tmpPrimaryAsText }); } } else if (inBlockStatement.expression().Length == 1 && inBlockStatement.typeType() != null) { //Type Conversion var tmpInfo = inBlockStatement.expression(); var tmpConverter = new TypeConversion(); tmpConverter.PreconversionValue = new CodeBlock(); HandleExpressionContext(tmpConverter.PreconversionValue, tmpInfo[0]); var tmpType = inBlockStatement.typeType(); tmpConverter.Type = JavaAntlrClassLoader.GetTypeContainer(tmpType); inCodeBlock.CodeEntries.Add(tmpConverter); } else if (inBlockStatement.expression().Length == 2 && inBlockStatement.children[1].GetText() == "[") { var tmpAccess = new VariableAccess { }; var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, inBlockStatement.expression()[0], null); tmpAccess.Access = tmpCodeBlock.CodeEntries[0]; tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, inBlockStatement.expression()[1], null); tmpAccess.Child = new CodeBlockContainer { InnerBlock = tmpCodeBlock }; tmpAccess.IsArrayAccess = true; inCodeBlock.CodeEntries.Add(tmpAccess); } else if (inBlockStatement.expression().Length == 2 && inBlockStatement.children[1].GetText() != "=") { var tmpCodeExpression = new CodeExpression { Manipulator = JavaStaticInfo.GetManipulator(string.Join("", inBlockStatement.children .Where(inItem => inItem is ITerminalNode) .Select(inItem => inItem.GetText()))) }; var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, inBlockStatement.expression()[0], inVariable); tmpCodeExpression.SubClauseEntries.Add(tmpCodeBlock); tmpCodeBlock = new CodeBlock();//Second Code Block HandleExpressionContext(tmpCodeBlock, inBlockStatement.expression()[1], inVariable); tmpCodeExpression.SubClauseEntries.Add(tmpCodeBlock); inCodeBlock.CodeEntries.Add(tmpCodeExpression); } else { var tmpChildList = inBlockStatement.children; if (tmpChildList.Count > 2) { var tmpSecondChildText = tmpChildList[1].GetText(); if (tmpSecondChildText == "=") { //SetVariable with Value var tmpVarSetter = new SetFieldWithValue(); HandleExpressionContext(tmpVarSetter.VariableToAccess, tmpChildList[0] as ExpressionContext, inVariable); HandleExpressionContext(tmpVarSetter.ValueToSet, tmpChildList[2] as ExpressionContext, inVariable); inCodeBlock.CodeEntries.Add(tmpVarSetter); } else if (JavaStaticInfo.VariableOperators.ContainsKey(tmpSecondChildText)) { var tmpCodeExpression = new CodeExpression { Manipulator = JavaStaticInfo.GetManipulator(tmpSecondChildText) }; var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChildList[0] as ExpressionContext, inVariable); tmpCodeExpression.SubClauseEntries.Add(tmpCodeBlock); tmpCodeBlock = new CodeBlock();//Second Code Block HandleExpressionContext(tmpCodeBlock, tmpChildList[2] as ExpressionContext, inVariable); tmpCodeExpression.SubClauseEntries.Add(tmpCodeBlock); inCodeBlock.CodeEntries.Add(tmpCodeExpression); } //Multi Part Property Access else if (tmpSecondChildText == ".") { VariableAccess tmpParent = null; for (var tmpI = 0; tmpI < tmpChildList.Count; tmpI += 2) { var tmpChild = tmpChildList[tmpI]; var tmpAccess = new VariableAccess(); if (tmpChild is ExpressionContext) { var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChild as ExpressionContext, null); tmpAccess.Access = tmpCodeBlock.CodeEntries[0]; } else if (tmpChild is MethodCallContext) { var tmpResult = HandleMethodeCall(tmpChild as MethodCallContext); tmpAccess.Access = tmpResult; } else if (tmpChild is TerminalNodeImpl) { var tmpChildText = tmpChild.GetText(); if (tmpChildText == ".") { } else if (RegexHelper.WordCheck.IsMatch(tmpChildText)) { tmpAccess.Access = new ConstantValue(tmpChildText); } else { throw new NotImplementedException("Not done yet"); } } else { throw new NotImplementedException("Not done yet"); } if (tmpParent != null) { tmpParent.Child = tmpAccess; } else { inCodeBlock.CodeEntries.Add(tmpAccess); } tmpParent = tmpAccess; } } else if (tmpSecondChildText == "?") { //Implement Elvis var tmpStatement = new StatementCode { StatementType = StatementTypeEnum.Elvis, StatementCodeBlocks = new List <CodeBlock>() }; //Boolean query var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChildList[0] as ExpressionContext, inVariable); tmpStatement.StatementCodeBlocks.Add(tmpCodeBlock); //First Result tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChildList[2] as ExpressionContext, inVariable); tmpStatement.StatementCodeBlocks.Add(tmpCodeBlock); //Second Result tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChildList[4] as ExpressionContext, inVariable); tmpStatement.StatementCodeBlocks.Add(tmpCodeBlock); inCodeBlock.CodeEntries.Add(tmpStatement); } else { throw new NotImplementedException("Not done yet"); } } else if (tmpChildList.Count == 1) { var tmpValue = tmpChildList[0] as MethodCallContext; MethodeCall tmpMethodeCall = HandleMethodeCall(tmpValue); inCodeBlock.CodeEntries.Add(tmpMethodeCall); } else if (tmpChildList.Count == 2 && tmpChildList[1] is ExpressionContext) { if (tmpChildList[0].GetText() == "!") { var tmpCodeExpression = new CodeExpression { Manipulator = JavaStaticInfo.GetManipulator(tmpChildList[0].GetText()) }; tmpCodeExpression.SubClauseEntries = new List <CodeBlock> { new CodeBlock() }; HandleExpressionContext(tmpCodeExpression.SubClauseEntries[0], tmpChildList[1] as ExpressionContext, inVariable); inCodeBlock.CodeEntries.Add(tmpCodeExpression); } else if (tmpChildList[0].GetText() != "-") { throw new NotImplementedException("Not done yet"); } else { HandleExpressionContext(inCodeBlock, tmpChildList[1] as ExpressionContext, inVariable); (inCodeBlock.CodeEntries.Last() as ConstantValue).Value = "-" + (inCodeBlock.CodeEntries.Last() as ConstantValue).Value; } } else if (tmpChildList.Count == 2 && tmpChildList[0] is ExpressionContext) { if (tmpChildList[1].GetText() != "--" && tmpChildList[1].GetText() != "++") { throw new NotImplementedException("Not done yet"); } var tmpCodeExpression = new CodeExpression { Manipulator = JavaStaticInfo.GetManipulator(tmpChildList[1].GetText()) }; tmpCodeExpression.SubClauseEntries = new List <CodeBlock> { new CodeBlock() }; HandleExpressionContext(tmpCodeExpression.SubClauseEntries[0], tmpChildList[0] as ExpressionContext, inVariable); inCodeBlock.CodeEntries.Add(tmpCodeExpression); } else if (tmpChildList.Count == 2) { if (tmpChildList[0].GetText() != "new") { throw new NotImplementedException("Not done yet"); } inCodeBlock.CodeEntries.Add(HandleCreatorContext(tmpChildList[1] as CreatorContext, inVariable)); } else { throw new NotImplementedException("Not done yet"); } } } }
public virtual IExpression VariableAccess(VariableAccess variableAccess) { return(variableAccess); }
public static async Task <Flow> CreateFlow(string name, string model, string eqn, GraphicalFunction graph, Range range, Range scale, NonNegative nonNegative, VariableAccess access) { return(await CreateVariable <Flow>(name, model, eqn, graph, range, scale, nonNegative, access)); }
public string VisitVariableAccess(VariableAccess variableAccess) { throw new NotImplementedException(); }