Exemplo n.º 1
0
        public string TranslateNativeInvocation(object throwToken, Platform.AbstractTranslator translator, string functionName, object[] args)
        {
            if (translationsLookup == null)
            {
                translationsLookup = new Dictionary <string, string>();
                foreach (string inheritedPlatformName in translator.Platform.InheritanceChain.Reverse())
                {
                    // TODO: make this hack less hacky.
                    string effectivePlatformName = inheritedPlatformName.StartsWith("experimental-")
                        ? inheritedPlatformName.Substring("experimental-".Length)
                        : inheritedPlatformName;
                    Dictionary <string, string> translationsForPlatform = this.Metadata.GetMethodTranslations(effectivePlatformName);
                    translationsLookup = Util.MergeDictionaries(translationsLookup, translationsForPlatform);
                }
            }

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            string output = null;
            string lookup = "$" + functionName;

            if (translationsLookup.ContainsKey(lookup))
            {
                output = translationsLookup[lookup];
            }

            if (output != null)
            {
                for (int i = 0; i < args.Length; ++i)
                {
                    translator.TranslateExpression(sb, (Pastel.Nodes.Expression)args[i]);
                    string argAsString = sb.ToString();
                    sb.Clear();
                    output = output.Replace("[ARG:" + (i + 1) + "]", argAsString);
                }
                return(output);
            }

            // Use this to determine which function is causing the problem:
            string MISSING_FUNCTION_NAME_FOR_DEBUGGER = functionName;

            MISSING_FUNCTION_NAME_FOR_DEBUGGER.Trim(); // no compile warnings

            string msg = "The " + this.Metadata.ID + " library does not support " + translator.Platform.Name + " projects.";

            if (throwToken is Token)
            {
                throw new ParserException((Token)throwToken, msg);
            }
            else
            {
                throw new Pastel.ParserException((Pastel.Token)throwToken, msg);
            }
        }
Exemplo n.º 2
0
        public string TranslateNativeInvocation(object throwToken, object legacyAbstractPlatformOrCbxTranslator, string functionName, object[] args)
        {
            if (this.translations == null)
            {
                Platform.AbstractTranslator translator          = (Platform.AbstractTranslator)legacyAbstractPlatformOrCbxTranslator;
                Dictionary <string, string> translationsBuilder = new Dictionary <string, string>();
                foreach (string platformName in translator.Platform.InheritanceChain.Reverse())
                {
                    Dictionary <string, string> translationsForPlatform = this.GetMethodTranslations(platformName);
                    translationsBuilder = Util.MergeDictionaries(translationsBuilder, translationsForPlatform);
                }
                this.translations = translationsBuilder;
            }

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            string output = null;
            string lookup = "$" + functionName;

            if (this.translations.ContainsKey(lookup))
            {
                output = this.translations[lookup];
            }

            if (output != null)
            {
                for (int i = 0; i < args.Length; ++i)
                {
                    ((Platform.AbstractTranslator)legacyAbstractPlatformOrCbxTranslator).TranslateExpression(sb, (Pastel.Nodes.Expression)args[i]);
                    string argAsString = sb.ToString();
                    sb.Clear();
                    output = output.Replace("[ARG:" + (i + 1) + "]", argAsString);
                }
                return(output);
            }

            // Use this to determine which function is causing the problem:
            string MISSING_FUNCTION_NAME_FOR_DEBUGGER = functionName;

            MISSING_FUNCTION_NAME_FOR_DEBUGGER.Trim(); // no compile warnings

            string msg = "The " + this.Name + " library does not support " + this.platformName + " projects.";

            if (throwToken is Token)
            {
                throw new ParserException((Token)throwToken, msg);
            }
            else
            {
                throw new Pastel.ParserException((Pastel.Token)throwToken, msg);
            }
        }