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> string GenerateGlobalVariableDeclaration(GlobalVariableDeclaration gv) { // ## TO DO ## // Does this do anything as some of the assignments are never used?? 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) { // 20131224 not used 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[] pObj = new object[argList.kids.Count]; foreach (SYMBOL objChild in argList.kids) { pObj[i] = objChild; if (objChild is IdentExpression) { // 20131224 not used IdentExpression identEx = (IdentExpression) objChild; } i++; } // TODO: 20160607 -greythane- This is never executed, check implmentation /*if (changed) { argList.kids = new ObjectList(); foreach (object o in pObj) 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(); }
public GlobalDefinitions(Parser yyp, GlobalVariableDeclaration gvd) : base((yyp)) { kids.Add(gvd); }