Example #1
0
            public static void ShowPreprocessor()
            {
                ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    var appSettings = ProbeEnvironment.CurrentAppSettings;

                    string fileName;
                    var codeSource = GetCodeSourceForActiveView(out fileName);
                    if (codeSource == null)
                    {
                        return;
                    }

                    var store = new CodeModel.FileStore();
                    var model = store.CreatePreprocessedModel(appSettings, codeSource, fileName, false,
                                                              "Commands.Debug.ShowPreprocessor()", null);

                    Shell.OpenTempContent(model.Source.Text, Path.GetFileName(fileName), ".preprocessor.txt");
                });
            }
Example #2
0
 public Preprocessor(ProbeAppSettings appSettings, FileStore store)
 {
     _appSettings = appSettings ?? throw new ArgumentNullException(nameof(appSettings));
     _store       = store ?? throw new ArgumentNullException(nameof(store));
 }
Example #3
0
        public DefinitionProvider(ProbeAppSettings appSettings, string fileName)
        {
            // Add definitions from external sources
            if (_builtInDefs == null)
            {
                _builtInDefs = new Definition[]
                {
                    // Functions
                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "abs",
                                                                 "Calculates the absolute value of an expression.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("expression to be evaluated", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "avg",
                                                                 "Calculates the running average of an expression for a set of rows in a select statement.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("expression, where expression, group TableName.ColumnName | all, in SelectName", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "count",
                                                                 "Keeps a running count of the number of rows selected in a select statement that satisfy a condition.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("* , where expression, group TableName.ColumnName | all, in SelectName", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "createobject",
                                                                 "Instantiates a COM object. The parameter iObj becomes a handle to the instance. The interface type of iObj determines what methods and properties the handle can call.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("iObj", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "diag",
                                                                 "Outputs specified expressions to a diagnostic device.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("expressions ...", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Char255, null, "FormatString",
                                                                 "Generates a message from a format string containing placeholder substrings '%1', '%2', '%3' etc., in any order, along with other optional user-specified substrings.",
                                                                 new ArgumentDescriptor[] {
                        new ArgumentDescriptor("FormatControlString", DataType.Char255, PassByMethod.Value),
                        new ArgumentDescriptor("expression1, expression2, ...", null)
                    })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "gofield",
                                                                 "Puts the focus on the requested field on the form.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("TableName.ColumnName", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Int, null, "invokeerror",
                                                                 "Determines whether an instantiated COM or .NET object has encountered an error. If an error, returns the error code of the object.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("iObj", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Char255, null, "invokeerrorstring",
                                                                 "Returns the text of the last error invoked on the object.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("iObj", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Int, null, "isinstance",
                                                                 "Determines whether a variable points to a valid instance of the variable interface type. ",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("iObj", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Char255, null, "makestring",
                                                                 "Creates a string by concatenating a list of expressions.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("expressions ...", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "max",
                                                                 "Determines the running maximum of an expression for a set of rows in a select statement.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("expression, where expression, group TableName.ColumnName | all, in SelectName", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "min",
                                                                 "Determines the running minimum of an expression for a set of rows in a select statement.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("expression, where expression, group TableName.ColumnName | all, in SelectName", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "oldvalue",
                                                                 "Returns the value of a column in the old row buffer.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("TableName.ColumnName", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "qcolsend",
                                                                 "Sends columns of the client's current row buffer to SAM or from SAM to the client. Only the current row buffer (not the old buffer) of the recepient is overwritten.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("TableName.ColumnName ...", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "releaseobject",
                                                                 "Releases the object identified by iObj, and automatically disconnects all events associated with iObj.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("iObj", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Int, null, "SetMessage",
                                                                 "Writes to the error message buffer. CAM displays the contents of that buffer when a trigger encounters an error. " +
                                                                 "In code, you can read that buffer using the getmsg function.\r\n\r\n" +
                                                                 "Provides similar functionality to setmsg, but allows you to maintain one source code for all languages " +
                                                                 "(with one set of resource files per language).",
                                                                 new ArgumentDescriptor[] {
                        new ArgumentDescriptor("MessageControlString", DataType.Char255, PassByMethod.Value),
                        new ArgumentDescriptor("expressions ...", null)
                    })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Char255, null, "STRINGIZE",
                                                                 "Converts macro parameters to strings.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("expression", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "sum",
                                                                 "Calculates the running total of an expression for a set of rows in a select statement.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("expression, where expression, group TableName.ColumnName | all, in SelectName", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Void, null, "UNREFERENCED_PARAMETER",
                                                                 "Prevents a compiler warning if a parameter passed to a function is not used.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("parameter", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.StringVarying, null, "vstring",
                                                                 "Creates a string of varying length by concatenating a list of expressions. ",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("expression, ...", null) })),

                    new FunctionDefinition(new FunctionSignature(true, FunctionPrivacy.Public, DataType.Int, null, "widthof",
                                                                 "Returns the displayable width of a variable or column.",
                                                                 new ArgumentDescriptor[] { new ArgumentDescriptor("name", null) })),

                    // Data types
                    new DataTypeDefinition("int", DataType.Int),

                    // Interfaces
                    new InterfaceTypeDefinition("oleobject", FilePosition.Empty),

                    // Constants
                    new ConstantDefinition("_WINDOWS", FilePosition.Empty, string.Empty),

                    // Indexes / Relationships
                    RelIndDefinition.Physical
                };
            }
            AddGlobalFromAnywhere(_builtInDefs);
            AddGlobalFromAnywhere(DkDict.Dict.AllDictDefinitions);
            if (string.IsNullOrEmpty(fileName) || !System.IO.Path.GetFileName(fileName).Equals("stdlib.i", StringComparison.OrdinalIgnoreCase))
            {
                AddGlobalFromAnywhere(FileStore.GetStdLibModel(appSettings).PreprocessorModel.DefinitionProvider.GlobalsFromFile);
            }

            var ffApp = ProbeToolsPackage.Instance.FunctionFileScanner.CurrentApp;

            AddGlobalFromAnywhere(ffApp.GlobalDefinitions);
        }