Пример #1
0
        static void defineFunction(
			mysSymbol symbol,
			mysFunction f,
			mysSymbolSpace ss
		)
        {
            mysFunctionGroup fg = null;

            // if symbol defined and of wrong type, undef it
            if (
                ss.Defined( symbol ) &&
                ss.GetValue( symbol ).Type != typeof(mysFunctionGroup)
            ) {
                // we could just overwrite it with define,
                // but I'd rather be entirely sure that we delete
                // the old value beforehand.
                ss.Undefine( symbol );
            }

            // if we're defined at this point, we know it's a function group
            if  ( ss.Defined( symbol ) ) {
                fg = ss.GetValue( symbol ).Value as mysFunctionGroup;
            } else {
                // create
                fg = new mysFunctionGroup();

                ss.Define( symbol, new mysToken( fg ) );
            }

            mysFunction collision = fg.Variants.FirstOrDefault( v =>
                v.Signature.Count() == f.Signature.Count() &&
                v.Signature
                    .Zip( f.Signature, (a, b) => a == b )
                    .Count() == v.Signature.Count()
            );

            if ( collision != null ) {
                // overwrite a conflicting sig! should probably
                // notify the user about this when it happens.
                fg.Variants.Remove( collision );
            }

            fg.Variants.Add( f );
        }