Esempio n. 1
0
 public GlobalDefinitions(Parser yyp, GlobalDefinitions gd, GlobalVariableDeclaration gvd) : base((yyp))
 {
     while (0 < gd.kids.Count) kids.Add(gd.kids.Pop());
     kids.Add(gvd);
 }
        /// <summary>
        ///     Generates the code for a GlobalVariableDeclaration node.
        /// </summary>
        /// <param name="gv">The GlobalVariableDeclaration node.</param>
        /// <returns>String containing C# code for GlobalVariableDeclaration gv.</returns>
        private string GenerateGlobalVariableDeclaration(GlobalVariableDeclaration gv)
        {
            StringBuilder retVal = new StringBuilder();

            foreach (SYMBOL s in gv.kids)
            {
                retVal.Append(Indent());
                retVal.Append("public ");
                if (s is Assignment)
                {
                    Assignment a = s as Assignment;
                    List<string> identifiers = new List<string>();

                    checkForMultipleAssignments(identifiers, a);

                    IsaGlobalVar = true;
                    SYMBOL variableName = (SYMBOL) a.kids.Pop();
                    string VarName = GenerateNode(variableName);
                    retVal.Append(VarName);
                    IsaGlobalVar = false;

                    #region Find the var name and type

                    Declaration dec = variableName as Declaration;
                    string type = dec.Datatype;
                    string varName = dec.Id;

                    #endregion

                    if (DuplicatedGlobalVariables.ContainsKey(((Declaration) variableName).Id))
                    {
                        if (a.kids.Count == 1)
                        {
                            SYMBOL assignmentChild = (SYMBOL) a.kids[0];
                            if (assignmentChild is IdentExpression)
                            {
                                IdentExpression identEx = (IdentExpression) assignmentChild;
                            }
                            else if (assignmentChild is ListConstant)
                            {
                                ListConstant listConst = (ListConstant) assignmentChild;
                                foreach (SYMBOL listChild in listConst.kids)
                                {
                                    if (listChild is ArgumentList)
                                    {
                                        ArgumentList argList = (ArgumentList) listChild;
                                        int i = 0;
                                        bool changed = false;
                                        object[] p = new object[argList.kids.Count];
                                        foreach (SYMBOL objChild in argList.kids)
                                        {
                                            p[i] = objChild;
                                            if (objChild is IdentExpression)
                                            {
                                                IdentExpression identEx = (IdentExpression) objChild;
                                            }
                                            i++;
                                        }
                                        if (changed)
                                        {
                                            argList.kids = new ObjectList();
                                            foreach (object o in p)
                                                argList.kids.Add(o);
                                        }
                                    }
                                }
                            }
                            else if (assignmentChild is Constant)
                            {
                                Constant identEx = (Constant) assignmentChild;
                                string value = GetValue(identEx);
                                Constant dupConstant = (Constant) DuplicatedGlobalVariables[dec.Id];
                                dupConstant.Value = dupConstant.Value == null
                                                        ? GetValue(dupConstant)
                                                        : dupConstant.Value;
                                if (value != dupConstant.Value)
                                {
                                    return "";
                                }
                            }
                        }
                    }

                    retVal.Append(Generate(String.Format(" {0} ", a.AssignmentType), a));
                    foreach (SYMBOL kid in a.kids)
                    {
                        retVal.Append(CheckIfGlobalVariable(varName, type, kid));
                    }
                }
                else
                    retVal.Append(GenerateNode(s));

                retVal.Append(GenerateLine(";"));
            }

            return retVal.ToString();
        }
Esempio n. 3
0
 public GlobalDefinitions(Parser yyp, GlobalVariableDeclaration gvd) : base((yyp))
 {
     kids.Add(gvd);
 }