public IErrorReporter Basics() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { }.SetMutability(mutability)); var root_ns = env.Root; var func_def = FunctionBuilder.Create( "foo", ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })); var type_def = root_ns.AddBuilder(TypeBuilder.Create("Foo").With(func_def)); resolver = NameResolver.Create(env); Assert.AreEqual(0, resolver.ErrorManager.Errors.Count); } return(resolver); }
public IErrorReporter ErrorCallingConstructorFromBody() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { }.SetMutability(mutability)); var root_ns = env.Root; FunctionCall constructor_call = FunctionCall.Create(NameReference.Create(NameFactory.ThisVariableName, NameFactory.InitConstructorName)); var type_def = root_ns.AddBuilder(TypeBuilder.Create("Foo") .SetModifier(EntityModifier.Base) .With(FunctionDefinition.CreateInitConstructor(EntityModifier.None, null, Block.CreateStatement())) .With(FunctionBuilder.Create("foo", null, ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new IExpression[] { constructor_call, Return.Create(RealLiteral.Create("3.3")) })) .SetModifier(EntityModifier.Base))); resolver = NameResolver.Create(env); Assert.AreEqual(1, resolver.ErrorManager.Errors.Count); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.ConstructorCallFromFunctionBody, constructor_call)); } return(resolver); }
public IErrorReporter ErrorDefaultUndef() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { }.SetMutability(mutability)); var root_ns = env.Root; Undef default_value = Undef.Create(); root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), Variadic.None, default_value, false, usageMode: ExpressionReadMode.CannotBeRead))); resolver = NameResolver.Create(env); Assert.AreEqual(1, resolver.ErrorManager.Errors.Count); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.InitializationWithUndef, default_value)); } return(resolver); }
public static string GetRealLiteralOperand(RealLiteral expression, VHDLCompilerInterface compiler) { string value = expression.RealValue.ToString(CultureInfo.InvariantCulture); NewStatementTemplate template = new NewStatementTemplate("VHDLFloatingPointValue", value); return(template.TransformText()); }
public IErrorReporter TemplateSpecializationOverload() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(FunctionBuilder.Create( "foo", "T", VarianceMode.None, ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })) .Parameters(FunctionParameter.Create("x", NameReference.Create("T"), usageMode: ExpressionReadMode.CannotBeRead))); root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), usageMode: ExpressionReadMode.CannotBeRead))); resolver = NameResolver.Create(env); Assert.AreEqual(0, resolver.ErrorManager.Errors.Count); } return(resolver); }
public IErrorReporter ConflictingAdditionalOptionalOverload() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { }.SetMutability(mutability)); var root_ns = env.Root; var func_def1 = root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) }))); var func_def2 = root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })).Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), Variadic.None, Int64Literal.Create("3"), false, usageMode: ExpressionReadMode.CannotBeRead))); resolver = NameResolver.Create(env); Assert.AreEqual(1, resolver.ErrorManager.Errors.Count()); Assert.AreEqual(ErrorCode.OverloadingDuplicateFunctionDefinition, resolver.ErrorManager.Errors.Single().Code); } return(resolver); }
public IErrorReporter ErrorIgnoringFunctionResult() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { GlobalVariables = true, RelaxedMode = true }.SetMutability(mutability)); var root_ns = env.Root; var func_def = root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.ReadRequired, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), usageMode: ExpressionReadMode.CannotBeRead))); root_ns.AddNode(VariableDeclaration.CreateStatement("i", NameFactory.Int64NameReference(), Undef.Create())); var call = FunctionCall.Create(NameReference.Create("foo"), FunctionArgument.Create(NameReference.Create("i"))); root_ns.AddNode(Block.CreateStatement(new[] { call })); resolver = NameResolver.Create(env); Assert.AreEqual(1, resolver.ErrorManager.Errors.Count); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.ExpressionValueNotUsed, call)); } return(resolver); }
public IErrorReporter ErrorVariadicParametersInvalidLimits() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { GlobalVariables = true, RelaxedMode = true }.SetMutability(mutability)); var root_ns = env.Root; var param1 = FunctionParameter.Create("x", NameFactory.Int64NameReference(), Variadic.Create(4, 3), null, isNameRequired: false, usageMode: ExpressionReadMode.CannotBeRead); var func_def = root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })) .Parameters(param1)); root_ns.AddNode(VariableDeclaration.CreateStatement("i", NameFactory.Int64NameReference(), null, EntityModifier.Public)); resolver = NameResolver.Create(env); Assert.AreEqual(1, resolver.ErrorManager.Errors.Count); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.InvalidVariadicLimits, param1)); } return(resolver); }
public CodeExpression VisitRealLiteral(RealLiteral r) { if (r.NumericValue == double.PositiveInfinity) { return(m.Access(m.TypeRefExpr("double"), "PositiveInfinity")); } else if (r.NumericValue == double.NegativeInfinity) { return(m.Access(m.TypeRefExpr("double"), "NegativeInfinity")); } return(m.Prim(r.NumericValue)); }
//----------------------------------------------------------- public Type Visit(RealLiteral node) { var realStr = node.AnchorToken.Lexeme; try { Convert.ToDouble(realStr); } catch (OverflowException) { throw new SemanticError( "Real literal too large to fit in memory: " + realStr, node.AnchorToken); } return(Type.REAL); }
public IErrorReporter DistinctTypesOverloadCall() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { GlobalVariables = true, RelaxedMode = true }.SetMutability(mutability)); var root_ns = env.Root; var system_ns = env.SystemNamespace; var func_def1 = root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), usageMode: ExpressionReadMode.CannotBeRead))); var func_def2 = root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })) .Parameters(FunctionParameter.Create("x", NameFactory.RealNameReference(), usageMode: ExpressionReadMode.CannotBeRead))); root_ns.AddNode(VariableDeclaration.CreateStatement("i", NameFactory.Int64NameReference(), Undef.Create())); root_ns.AddNode(VariableDeclaration.CreateStatement("s", NameFactory.RealNameReference(), Undef.Create())); var call1 = FunctionCall.Create(NameReference.Create("foo"), FunctionArgument.Create(NameReference.Create("i"))); var call2 = FunctionCall.Create(NameReference.Create("foo"), FunctionArgument.Create(NameReference.Create("s"))); root_ns.AddNode(VariableDeclaration.CreateStatement("x", NameFactory.RealNameReference(), call1, modifier: EntityModifier.Public)); root_ns.AddNode(VariableDeclaration.CreateStatement("y", NameFactory.RealNameReference(), call2, modifier: EntityModifier.Public)); resolver = NameResolver.Create(env); Assert.AreEqual(0, resolver.ErrorManager.Errors.Count); Assert.AreEqual(func_def1, call1.Resolution.TargetFunctionInstance.Target); Assert.AreEqual(func_def2, call2.Resolution.TargetFunctionInstance.Target); } return(resolver); }
public IErrorReporter FunctionAssignment() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { GlobalVariables = true, RelaxedMode = true }.SetMutability(mutability)); var root_ns = env.Root; var system_ns = env.SystemNamespace; var func_def = root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.OptionalUse, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })).Parameters(FunctionParameter.Create("t", NameFactory.Int64NameReference(), Variadic.None, null, isNameRequired: false, usageMode: ExpressionReadMode.CannotBeRead))); // x *IFunction<Int,Double> = foo root_ns.AddNode(VariableDeclaration.CreateStatement("x", NameFactory.PointerNameReference(NameReference.Create(NameFactory.IFunctionTypeName, NameFactory.Int64NameReference(), NameFactory.RealNameReference())), initValue: NameReference.Create("foo"), modifier: EntityModifier.Public)); var foo_ref = NameReference.Create("foo"); // y *IFunction<Double,Int> = foo VariableDeclaration decl = VariableDeclaration.CreateStatement("y", NameFactory.PointerNameReference(NameReference.Create(NameFactory.IFunctionTypeName, NameFactory.RealNameReference(), NameFactory.Int64NameReference())), initValue: foo_ref, modifier: EntityModifier.Public); root_ns.AddNode(decl); resolver = NameResolver.Create(env); Assert.AreEqual(1, foo_ref.Binding.Matches.Count); Assert.AreEqual(func_def, foo_ref.Binding.Match.Instance.Target); Assert.AreEqual(1, resolver.ErrorManager.Errors.Count); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.TypeMismatch, decl.InitValue)); } return(resolver); }
public Constant VisitRealLiteral(RealLiteral realLiteral) { return(Constant.Real64(realLiteral.Value)); }
public override bool Visit(RealLiteral node) { Visit((Literal)node); return(true); }
public override void Visit(RealLiteral node) { this.action(node); }
public void genAritExpresion(ILCodeGen cg, ArrayList exp, uint scope, string proc_actual, string store) { int tipo = 0; Symbol s = null; foreach (Expr e in exp) { if (e is IntLiteral) { IntLiteral lit = (IntLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.INT, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is RealLiteral) { RealLiteral lit = (RealLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.REAL, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is BoolLiteral) { BoolLiteral lit = (BoolLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.BOOLEAN, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is StringLiteral) { StringLiteral lit = (StringLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.STRING, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is CharLiteral) { CharLiteral lit = (CharLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.CHAR, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is Variable) { Variable var = (Variable)e; if (scope == 0) { s = symtab.getSymbol(var.Value); } else { s = symtab.getSymbol(proc_actual, var.Value, ref tipo); } if (s != null) { if (tipo == 1) { Param p = (Param)s; cg.loadVariable(s, p.Reference, scope, proc_actual); } else { cg.loadVariable(s, false, scope, proc_actual); } } tipo = 0; } else if (e is Function) { ExpFunction ex = (ExpFunction)e; if (scope == 0) { s = symtab.find(store); } else { s = symtab.getSymbol(proc_actual, store, ref tipo); } if (s != null) { if (s.Type.toString() != ex.Tipo) { throw new fpc2ilException("Cannot assing type " + ex.Tipo + " to variable '" + s.Name + "' (" + s.Type.toString() + ")"); } } tipo = 0; } else if (e is PlusExpresion) { cg.genSuma(); } else if (e is MinusExpresion) { cg.genResta(); } else if (e is ProductoExpresion) { cg.genMult(); } else if (e is DivisionExpresion) { cg.genDivision(); } else if (e is DIVExpresion) { cg.genDivision(); } else if (e is MODExpresion) { cg.genMod(); } } /* Una vez estan generados todos los loads generamos el store */ if (scope == 0) { s = symtab.getSymbol(store); } else { s = symtab.getSymbol(proc_actual, store, ref tipo); } if (s != null) { if (tipo == 1) { Param p = (Param)s; cg.storeVariable(s, p.Reference, scope, proc_actual); } else { /* TODO: Si es una variable de retorno de funcion de momento no hacemos nada */ if (s.Name != proc_actual) { cg.storeVariable(s, false, scope, proc_actual); } } } }
public override void VisitRealLiteral(RealLiteral n) { _gen.Emit(OpCodes.Ldc_R8, n.Value); _lastWalkedType = typeof(double); }
public virtual T Visit(RealLiteral node) { return(Visit((Literal)node)); }
public override bool Visit(RealLiteral node) { outputCode((node.Value as RealValue).val.ToString() + " ", false, false); //Visit((Literal) node); return(true); }
public override void ExplicitVisit(RealLiteral fragment) { _fragments.Add(fragment); }
public void VisitRealLiteral(RealLiteral r) { throw new NotImplementedException(); }
public override void ExplicitVisit(RealLiteral node) { node.Value = "0.1E-2"; base.ExplicitVisit(node); }
public override void ExplicitVisit(RealLiteral node) { base.ExplicitVisit(node); }
public void genRepeatExpresion(ILCodeGen cg, ArrayList exp, uint scope, string proc_actual, Emit.Label ini, Emit.Label body, Emit.Label fin) { int tipo = 0; Symbol s = null; bool hasAnd = hasToGenAndLabel(exp); ReorderWHILEExpression(exp, proc_actual, scope); cg.MarkLabel(ini); foreach (Expr e in exp) { if (e is IntLiteral) { IntLiteral lit = (IntLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.INT, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is RealLiteral) { RealLiteral lit = (RealLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.REAL, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is BoolLiteral) { BoolLiteral lit = (BoolLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.BOOLEAN, 0, null); cg.loadVariable(s, false, scope, proc_actual); if (lit.Value == "true") { cg.genFalseStatement(body); } else { cg.genTrueStatement(body); } } else if (e is StringLiteral) { StringLiteral lit = (StringLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.STRING, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is CharLiteral) { CharLiteral lit = (CharLiteral)e; s = new Symbol(lit.Value, new Type()); s.Type = new Type(Type.T.CHAR, 0, null); cg.loadVariable(s, false, scope, proc_actual); } else if (e is Variable) { Variable var = (Variable)e; if (scope == 0) { s = symtab.getSymbol(var.Value); } else { s = symtab.getSymbol(proc_actual, var.Value, ref tipo); } if (s != null) { if (tipo == 1) { Param p = (Param)s; cg.loadVariable(s, p.Reference, scope, proc_actual); } else { cg.loadVariable(s, false, scope, proc_actual); } } tipo = 0; if (s.Type.toString() == "BOOLEAN") { if (var.Tipo == "NOT") { cg.genTrueStatement(body); } else { cg.genFalseStatement(body); } } } else if (e is Function) { ExpFunction ex = (ExpFunction)e; } else if (e is EQExpresion) { if (hasAnd) { cg.genDFStatement(fin); } else { cg.genDFStatement(body); } hasAnd = false; } else if (e is DFExpresion) { if (hasAnd) { cg.genEQStatement(fin); } else { cg.genEQStatement(body); } hasAnd = false; } else if (e is GEExpresion) { if (hasAnd) { cg.genLTStatement(fin); } else { cg.genLTStatement(body); } hasAnd = false; } else if (e is GTExpresion) { if (hasAnd) { cg.genLEStatement(fin); } else { cg.genLEStatement(body); } hasAnd = false; } else if (e is LEExpresion) { if (hasAnd) { cg.genGTStatement(fin); } else { cg.genGTStatement(body); } hasAnd = false; } else if (e is LTExpresion) { if (hasAnd) { cg.genGEStatement(fin); } else { cg.genGEStatement(body); } hasAnd = false; } } }
public override void VisitRealLiteral(RealLiteral n) { n.InternalType = _lastSeenType = new TypeReal(); }
public virtual void VisitRealLiteral(RealLiteral n) { }
public IErrorReporter MethodNoDominance() { // https://en.wikipedia.org/wiki/Dominance_(C%2B%2B)#Example_without_diamond_inheritance NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.Create("Grandparent") .SetModifier(EntityModifier.Base) .With(FunctionBuilder.Create("f", NameFactory.UnitNameReference(), Block.CreateStatement()) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), ExpressionReadMode.CannotBeRead))) .With(FunctionBuilder.Create("f", NameFactory.UnitNameReference(), Block.CreateStatement()) .Parameters(FunctionParameter.Create("a", NameFactory.RealNameReference(), ExpressionReadMode.CannotBeRead), FunctionParameter.Create("b", NameFactory.RealNameReference(), ExpressionReadMode.CannotBeRead)))); root_ns.AddBuilder(TypeBuilder.Create("Parent") .SetModifier(EntityModifier.Base) .Parents("Grandparent") .With(FunctionBuilder.Create("f", NameFactory.UnitNameReference(), Block.CreateStatement()) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), ExpressionReadMode.CannotBeRead)))); root_ns.AddBuilder(TypeBuilder.Create("Child") .Parents("Parent") .With(FunctionBuilder.Create("g", NameFactory.UnitNameReference(), Block.CreateStatement( // unlike C++ this method is seen as regular overload FunctionCall.Create(NameReference.CreateThised("f"), RealLiteral.Create("2.14"), RealLiteral.Create("3.17")))))); resolver = NameResolver.Create(env); Assert.AreEqual(0, resolver.ErrorManager.Errors.Count); } return(resolver); }
public IInterpreter ResolvingGenericArgumentInRuntime() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(FunctionBuilder.Create("oracle", "O", VarianceMode.None, NameFactory.BoolNameReference(), Block.CreateStatement( Return.Create(IsType.Create(NameReference.Create("thing"), NameReference.Create("O"))) )) .Parameters(FunctionParameter.Create("thing", NameFactory.ReferenceNameReference(NameFactory.IObjectNameReference())))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement( VariableDeclaration.CreateStatement("acc", null, Nat8Literal.Create("0"), env.Options.ReassignableModifier()), VariableDeclaration.CreateStatement("i", null, ExpressionFactory.HeapConstructor(NameFactory.IntNameReference(), IntLiteral.Create("7"))), VariableDeclaration.CreateStatement("d", null, ExpressionFactory.HeapConstructor(NameFactory.RealNameReference(), RealLiteral.Create("3.3"))), IfBranch.CreateIf(FunctionCall.Create(NameReference.Create("oracle", NameFactory.IntNameReference()), NameReference.Create("i")), new[] { ExpressionFactory.IncBy("acc", Nat8Literal.Create("2")) }), IfBranch.CreateIf(FunctionCall.Create(NameReference.Create("oracle", NameFactory.IntNameReference()), NameReference.Create("d")), new[] { ExpressionFactory.IncBy("acc", Nat8Literal.Create("88")) }), Return.Create(NameReference.Create("acc")) ))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual((byte)2, result.RetValue.PlainValue); } return(interpreter); }
public CodeExpression VisitRealLiteral(RealLiteral r) { return(m.Prim(r.Value)); }
public void visit(RealLiteral literal) { baseInfer.AnalyzeType(literal.Type); }
public DataType VisitRealLiteral(RealLiteral r) { return(DataType.Float); }
public override Value Visit(RealLiteral node) { return(Value.CreateConstDouble(node.Value.Val <double>())); }
public SerializedType VisitRealLiteral(RealLiteral realLiteral) { throw new NotImplementedException(); }
public static string GetRealLiteralExpresstionType(RealLiteral expression, VHDLCompilerInterface compiler) { return(compiler.TypeDictionary[expression.Type]); }