コード例 #1
0
ファイル: operators.cs プロジェクト: Sciumo/gaigen
        private static void WriteOperator(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, bool declOnly, G25.fgs FGS, G25.Operator op)
        {
            bool comment = declOnly || S.m_inlineOperators;
            bool returnTypeEqualsFirstArgument = FGS.ReturnTypeName == FGS.ArgumentTypeNames[0];

            foreach (string floatName in FGS.FloatNames)
            {
                G25.FloatType FT = S.GetFloatType(floatName);

                string funcName = FGS.OutputName;

                { // regular operator
                    bool assign = false;
                    bool returnByReference = returnTypeEqualsFirstArgument && op.IsPrefixUnary() && op.IsUnaryInPlace(); // for unary prefix ++ and --, needs to return by reference (&)
                    bool constVal = !(op.IsUnaryInPlace() && returnTypeEqualsFirstArgument);
                    string funcDecl = GetFuncDecl(S, declOnly, FGS, op, FT, assign, constVal, returnByReference);

                    if (comment) // comment?
                        SB.AppendLine("/// " + GetComment(S, declOnly, FGS, op, FT, assign));
                    SB.Append(funcDecl);
                    if (declOnly) SB.AppendLine(";");
                    else
                    {
                        SB.AppendLine(" {");
                        WriteOperatorBody(SB, S, cgd, FGS, op, funcName);
                        SB.AppendLine("}");
                    }
                }

                // add an extra operator with assignment (like +=) ?
                if (op.IsBinary() && returnTypeEqualsFirstArgument)
                {
                    bool assign = true;
                    bool constVal = false;
                    bool returnByReference = true; // todo: for unary prefix ++ needs to return by reference (&)
                    string funcDecl = GetFuncDecl(S, declOnly, FGS, op, FT, assign, constVal, returnByReference);

                    if (comment) // comment?
                        SB.AppendLine("/// " + GetComment(S, declOnly, FGS, op, FT, assign));
                    SB.Append(funcDecl);
                    if (declOnly) SB.AppendLine(";");
                    else
                    {
                        SB.AppendLine(" {");
                        SB.Append("\treturn (" + FGS.ArgumentVariableNames[0] + " = " + funcName + "(" + FGS.ArgumentVariableNames[0]);
                        SB.AppendLine(", " + FGS.ArgumentVariableNames[1] + "));");
                        SB.AppendLine("}");
                    }
                }

            }
        }