示例#1
0
		public  GlobalDefinitions (Parser yyp, GlobalDefinitions  gd , GlobalVariableDeclaration  gvd ):base(((LSLSyntax
		                                                                                                      )yyp)){ while (0< gd . kids . Count ) kids . Add ( gd . kids . Pop ());
			kids . Add ( gvd );
		}
示例#2
0
        /// <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)
        {
            string retstr = "";

            foreach (SYMBOL s in gv.kids)
            {
                retstr += Indent();
                retstr += "public ";
                if (s is Assignment)
                {
                    string innerretstr = "";

                    Assignment a = s as Assignment;
                    List<string> identifiers = new List<string>();

                    checkForMultipleAssignments(identifiers, a);

                    string VarName = GenerateNode((SYMBOL)a.kids.Pop());
                    innerretstr += VarName;

                    #region Find the var name and type

                    string[] vars = VarName.Split(' ');
                    string type = vars[0];
                    string varName = vars[1];
                    string globalVarValue = "";

                    #endregion

                    innerretstr += Generate(String.Format(" {0} ", a.AssignmentType), a);
                    foreach (SYMBOL kid in a.kids)
                    {
                        if (kid is Constant)
                        {
                            Constant c = kid as Constant;
                            // Supprt LSL's weird acceptance of floats with no trailing digits
                            // after the period. Turn float x = 10.; into float x = 10.0;
                            if ("LSL_Types.LSLFloat" == c.Type)
                            {
                                int dotIndex = c.Value.IndexOf('.') + 1;
                                if (0 < dotIndex && (dotIndex == c.Value.Length || !Char.IsDigit(c.Value[dotIndex])))
                                    globalVarValue = c.Value.Insert(dotIndex, "0");
                                globalVarValue = "new LSL_Types.LSLFloat(" + c.Value + ") ";
                            }
                            else if ("LSL_Types.LSLInteger" == c.Type)
                            {
                                globalVarValue = "new LSL_Types.LSLInteger(" + c.Value + ") ";
                            }
                            else if ("LSL_Types.LSLString" == c.Type)
                            {
                                globalVarValue = "new LSL_Types.LSLString(\"" + c.Value + "\") ";
                            }
                            if(globalVarValue == "")
                                globalVarValue = c.Value;

                            if (globalVarValue == null)
                                globalVarValue = GenerateNode(c);
                            if (GlobalVariables.ContainsKey(globalVarValue))
                            {
                                //Its an assignment to another global var!
                                //reset the global value to the other's value
                                GlobalVar var;
                                GlobalVariables.TryGetValue(globalVarValue, out var);
                                //Do one last additional test before we set it.
                                if (type == var.Type)
                                {
                                    globalVarValue = var.Value;
                                }
                                c.Value = globalVarValue;
                            }
                            innerretstr += globalVarValue;
                        }
                        else if (kid is IdentExpression)
                        {
                            IdentExpression c = kid as IdentExpression;
                            globalVarValue = c.Name;
                            if (GlobalVariables.ContainsKey(globalVarValue))
                            {
                                //Its an assignment to another global var!
                                //reset the global value to the other's value
                                GlobalVar var;
                                GlobalVariables.TryGetValue(globalVarValue, out var);
                                //Do one last additional test before we set it.
                                if (type == var.Type)
                                {
                                    globalVarValue = var.Value;
                                }
                            }
                            innerretstr += globalVarValue;
                        }
                        else
                            innerretstr += GenerateNode(kid);
                    }
                    GlobalVariables.Add(varName, new GlobalVar()
                        {
                            Type = type,
                            Value = globalVarValue
                        });

                    retstr += innerretstr.ToString();
                }
                else
                    retstr += GenerateNode(s);

                retstr += GenerateLine(";");
            }

            return retstr.ToString();
        }
示例#3
0
		public  GlobalDefinitions (Parser yyp, GlobalVariableDeclaration  gvd ):base(((LSLSyntax
		                                                                              )yyp)){ 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 retstr = new StringBuilder();

            foreach (SYMBOL s in gv.kids)
            {
                retstr.Append(Indent());
                retstr.Append("public ");
                retstr.Append(GenerateNode(s));
                retstr.Append(GenerateLine(";"));
            }

            return retstr.ToString();
        }