Inheritance: Tools.SYMBOL
        /// <summary>
        ///     Generates the code for an Assignment node.
        /// </summary>
        /// <param name="a">The Assignment node.</param>
        /// <returns>String containing C# code for Assignment a.</returns>
        private string GenerateAssignment(Assignment a)
        {
            StringBuilder retVal = new StringBuilder();
            List<string> identifiers = new List<string>();

            bool marc = FuncCallsMarc();
            checkForMultipleAssignments(identifiers, a);

            if (a.kids[a.kids.Count - 1] is ListConstant && isAdditionExpression) //Deal with the list memory hack
            {
                a.kids.Pop(); //Get rid of the first one
                foreach (SYMBOL kid in a.kids)
                    retVal.Append(GenerateNode(kid));
                return retVal.ToString(); //If it is a list, and we are in an addition expression, we drop the assignment
            }

            retVal.Append(GenerateNode((SYMBOL) a.kids.Pop()));
            retVal.Append(Generate(String.Format(" {0} ", a.AssignmentType), a));
            foreach (SYMBOL kid in a.kids)
                retVal.Append(GenerateNode(kid));
            //fCalls += ";";//Add a ; at the end.
            //lock (AfterFuncCalls)
            //    AfterFuncCalls.Add (fCalls);

            return DumpFunc(marc) + retVal.ToString() + DumpAfterFunc(marc);
        }
Ejemplo n.º 2
0
 public Statement(Parser yyp, Assignment a) : base((yyp))
 {
     kids.Add(a);
 }
        /// <summary>
        ///     Replaces an instance of the node at s.kids[didx] with an assignment
        ///     node. The assignment node has the Declaration node on the left hand
        ///     side and a default initializer on the right hand side.
        /// </summary>
        /// <param name="s">
        ///     The node containing the Declaration node that needs replacing.
        /// </param>
        /// <param name="didx">Index of the Declaration node to replace.</param>
        private void AddImplicitInitialization(SYMBOL s, int didx)
        {
            // We take the kids for a while to play with them.
            int sKidSize = s.kids.Count;
            object[] sKids = new object[sKidSize];
            for (int i = 0; i < sKidSize; i++)
                sKids[i] = s.kids.Pop();

            // The child to be changed.
            Declaration currentDeclaration = (Declaration) sKids[didx];

            // We need an assignment node.
            Assignment newAssignment = new Assignment(currentDeclaration.yyps,
                                                      currentDeclaration,
                                                      GetZeroConstant(currentDeclaration.yyps,
                                                                      currentDeclaration.Datatype),
                                                      "=");
            sKids[didx] = newAssignment;

            // Put the kids back where they belong.
            for (int i = 0; i < sKidSize; i++)
                s.kids.Add(sKids[i]);
        }
Ejemplo n.º 4
0
 public GlobalVariableDeclaration(Parser yyp, Assignment a) : base((yyp))
 {
     kids.Add(a);
 }