Ejemplo n.º 1
0
 /// <summary>
 /// Rename all the variables in this block
 /// </summary>
 /// <param name="origName"></param>
 /// <param name="newName"></param>
 public override void RenameVariable(string origName, string newName)
 {
     ArrayLength.RenameRawValue(origName, newName);
     InitialValue.RenameRawValue(origName, newName);
     _loopVariable.RenameParameter(origName, newName);
     RenameBlockVariables(origName, newName);
 }
Ejemplo n.º 2
0
        public override int GetHashCode()
        {
            var hashCode = -1129514919;

            hashCode = hashCode * -1521134295 + base.GetHashCode();
            hashCode = hashCode * -1521134295 + ArrayLength.GetHashCode();
            return(hashCode);
        }
Ejemplo n.º 3
0
        public override AstNode VisitArrayLength(ArrayLength ast)
        {
            //push object to e-stack
            Visit(ast.Array);

            m_ilgen.EmitCall(OpCodes.Callvirt, ArrayGetLengthMethod, null);

            return(ast);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Serves as a hash function for a particular type. <see cref="M:System.Object.GetHashCode"/> is suitable for
        /// use in hashing algorithms and data structures like a hash table.
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        public override int GetHashCode()
        {
            unchecked {
                int result = BaseType.GetHashCode();
                result = (result * 397) ^ ArrayLength.GetHashCode();

                return(result);
            }
        }
Ejemplo n.º 5
0
        public void Visit(ArrayLength n)
        {
            Globals.Builder.Start($"array length (int[].length) [{n.Location.StartLine}, {n.Location.StartColumn}]");

            GetPointer(n.Array);
            Globals.Builder.WriteBinaryOp("mov", "rax", "[rax]");

            Globals.Builder.End($"array length (int[].length) [{n.Location.EndLine}, {n.Location.EndColumn}]");
        }
        public SemanticAtom Visit(ArrayLength n)
        {
            if (n.Array.Accept(this) != Primitive.IntArray)
            {
                Globals.Errors.Add($"[{n.Array.Location.StartLine}, {n.Array.Location.StartColumn}] Array is not an {Primitive.IntArray.Name}.");
            }

            n.RealizedType = Primitive.Int;
            return(n.RealizedType);
        }
Ejemplo n.º 7
0
        public void ShouldReturnLengthOfArray()
        {
            //Arrange
            object[]    objects     = new object[0];
            ArrayLength arrayLength = new ArrayLength(objects);

            //Act
            int actual = arrayLength;

            //Assert
            actual.Should().Be(0);
        }
Ejemplo n.º 8
0
        public void Visit(ArrayLength n)
        {
            Helpers.WriteLine($"{_tab}{n.Text} [{n.Location.StartLine}, {n.Location.StartColumn}]");
            Tab();

            Helpers.WriteLine($"{_tab}Array");
            Tab();
            n.Array.Accept(this);
            Untab();

            Untab();
        }
Ejemplo n.º 9
0
        //Extra.Given a list of numbers and a number k, return whether any two
        //numbers from the list add up to k.
        static private bool isKnumbertheAddof2()
        {
            int  K = 17;
            int  S;
            bool boolSRFN;

            int[] ArraySRFN = { 210, 26, 25, 18, 2, 16, 2, 1, 0, 3, 10, 15, 3, 7 };
            int   ArrayLength;

            ArrayLength = ArraySRFN.Length;
            int ArrayLengthMinus1 = ArrayLength - 1;

            Console.WriteLine(ArrayLength.ToString());

            Array.Sort(ArraySRFN);
            Array.Reverse(ArraySRFN);

            for (int i = 0; i < ArrayLength; i++)
            {
                Console.WriteLine("iteration for MAIN number:" + ArraySRFN[i]);
                S = K - ArraySRFN[i];
                for (int j = 0; j < ArrayLength; j++)
                {
                    Console.WriteLine("iteration for SECONDARY number:" + ArraySRFN[j]);
                    if (j == i)
                    {
                        Console.WriteLine("equal number");
                    }
                    else
                    {
                        if (S == ArraySRFN[j])
                        {
                            boolSRFN = true;
                            Console.WriteLine("true");
                            return(boolSRFN);
                        }
                        else
                        {
                            Console.WriteLine("one iteration corresponding with numbers:");
                        };
                    }
                }
            }
            boolSRFN = false;
            Console.WriteLine("false");
            return(boolSRFN);
        }
Ejemplo n.º 10
0
    public static int Main(string[] args)
    {
        ArrayLength aLength = new ArrayLength();  
        TestLibrary.TestFramework.BeginScenario("Testing Array.Length property...");

        if (aLength.RunTests())
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("PASS");
            return 100;
        }
        else
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("FAIL");
            return 0;
        }
    }
Ejemplo n.º 11
0
        public override AstNode VisitArrayLength(ArrayLength ast)
        {
            Visit(ast.Array);

            ArrayType arrayType = ast.Array.ExpressionType as ArrayType;

            if (arrayType == null)
            {
                AddError(c_SE_ExpressionNotArray, ast.LengthSpan);
            }
            else if (arrayType.ElementType != PrimaryType.Int)
            {
                AddError(c_SE_NotSupported, ast.LengthSpan, "Arrays rather than int[] are not operatable");
            }

            ast.ExpressionType = PrimaryType.Int;

            return(ast);
        }
Ejemplo n.º 12
0
    public static int Main(string[] args)
    {
        ArrayLength aLength = new ArrayLength();

        TestLibrary.TestFramework.BeginScenario("Testing Array.Length property...");

        if (aLength.RunTests())
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("PASS");
            return(100);
        }
        else
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("FAIL");
            return(0);
        }
    }
Ejemplo n.º 13
0
        public override AstNode VisitArrayLength(ArrayLength ast)
        {
            Visit(ast.Array);

            ArrayType arrayType = ast.Array.ExpressionType as ArrayType;
            if (arrayType == null)
            {
                m_errorManager.AddError(c_SE_ExpressionNotArray, ast.LengthSpan);
            }
            else if (arrayType.ElementType != PrimaryType.Int)
            {
                m_errorManager.AddError(c_SE_NotSupported, ast.LengthSpan, "Arrays rather than int[] are not operatable");
            }

            ast.ExpressionType = PrimaryType.Int;

            return ast;
        }
Ejemplo n.º 14
0
 /// <summary cref="Value.ToArgString"/>
 protected override string ToArgString() =>
 $"{base.ToArgString()}{Type.ToString()} [{ArrayLength.Resolve().ToString()}]";
Ejemplo n.º 15
0
 public void Visit(ArrayLength n)
 {
     n.Array.Accept(this);
     Helpers.Write(".length");
 }
Ejemplo n.º 16
0
        public override AstNode VisitArrayLength(ArrayLength ast)
        {
            //push object to e-stack
            Visit(ast.Array);

            m_ilgen.EmitCall(OpCodes.Callvirt, ArrayGetLengthMethod, null);

            return ast;
        }
 public SemanticAtom Visit(ArrayLength n)
 {
     n.Array.Accept(this);
     return(null);
 }
Ejemplo n.º 18
0
 public virtual AstNode VisitArrayLength(ArrayLength ast)
 {
     return(ast);
 }