Esempio n. 1
0
        public void Load(FFDatabase db)
        {
            _fields.Clear();

            using (var cmd = db.CreateCommand(@"
				select name, pos, data_type, alt_file.file_name as alt_file_name from permex_col
				left outer join alt_file on alt_file.rowid = permex_col.alt_file_id
				where permex_id = @id
				"                ))
            {
                cmd.Parameters.AddWithValue("@id", _id);

                using (var rdr = cmd.ExecuteReader())
                {
                    var ordName        = rdr.GetOrdinal("name");
                    var ordAltFileName = rdr.GetOrdinal("alt_file_name");
                    var ordPos         = rdr.GetOrdinal("pos");
                    var ordDataType    = rdr.GetOrdinal("data_type");

                    while (rdr.Read())
                    {
                        var name = rdr.GetString(ordName);

                        var fileName = rdr.GetStringOrNull(ordAltFileName);
                        if (string.IsNullOrEmpty(fileName))
                        {
                            fileName = _file.FileName;
                        }
                        var pos     = rdr.GetInt32(ordPos);
                        var filePos = new FilePosition(fileName, pos);

                        var fieldDef = new ExtractFieldDefinition(name, filePos, _def);
                        _fields.Add(fieldDef);
                        _def.AddField(fieldDef);

                        var dataTypeString = rdr.GetString(ordDataType);
                        if (!string.IsNullOrEmpty(dataTypeString))
                        {
                            var dataType = DataType.TryParse(new DataType.ParseArgs {
                                Code = new CodeParser(dataTypeString)
                            });
                            if (dataType == null)
                            {
                                Log.Debug("Failed to parse permanent extract data type from database: {0}", dataTypeString);
                                dataType = new CodeModel.DataType(ValType.Unknown, null,
                                                                  new Classifier.ProbeClassifiedString(Classifier.ProbeClassifierType.DataType, dataTypeString));
                            }
                            fieldDef.SetDataType(dataType);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void ReadExtract(Span extractWordSpan)
        {
            var errorSpan = extractWordSpan;
            var permanent = _code.ReadExact("permanent");

            if (permanent)
            {
                errorSpan = _code.Span;
            }

            // Table name
            if (!_code.ReadWord())
            {
                return;
            }
            var name = _code.Text;
            ExtractTableDefinition exDef = null;

            if (!_defProv.GetGlobalFromFile <ExtractTableDefinition>(name).Any())               // Don't add a definition if it's already there (extracts can be called multiple times)
            {
                var localPos = _source.GetFilePosition(_code.TokenStartPostion);
                exDef = new ExtractTableDefinition(name, localPos, permanent);
            }

            string lastToken    = null;
            var    lastTokenPos = 0;
            var    fields       = new List <string>();

            if (exDef != null)
            {
                var rownoDef = new ExtractFieldDefinition("rowno", exDef.FilePosition, exDef);
                rownoDef.SetDataType(DataType.Unsigned9);
                exDef.AddField(rownoDef);
            }

            var done = false;

            while (!_code.EndOfFile && !done)
            {
                if (!_code.PeekExact("==") && _code.ReadExact('=') && lastToken != null)
                {
                    if (exDef != null)
                    {
                        var localPos = _source.GetFilePosition(lastTokenPos);
                        var fieldDef = new ExtractFieldDefinition(lastToken, localPos, exDef);
                        exDef.AddField(fieldDef);
                    }
                    if (fields == null)
                    {
                        fields = new List <string>();
                    }
                    fields.Add(lastToken);
                    lastToken = null;
                }
                else if (_code.ReadWord())
                {
                    lastToken    = _code.Text;
                    lastTokenPos = _code.TokenStartPostion;
                }
                else
                {
                    _code.Read();
                    switch (_code.Text)
                    {
                    case ";":
                        done = true;
                        break;

                    case "{":
                    case "}":
                        done = true;
                        break;

                    case "(":
                        ReadNestable(")");
                        break;

                    case "[":
                        ReadNestable("]");
                        break;
                    }
                }
            }

            if (exDef != null)
            {
                _defProv.AddGlobalFromFile(exDef);
            }
        }
Esempio n. 3
0
        public static ExtractStatement Parse(Scope scope, KeywordToken extractKeywordToken)
        {
            var code = scope.Code;

            var tokens = new List <Token>();

            tokens.Add(extractKeywordToken);

            var permanent = false;

            if (code.ReadExactWholeWord("permanent"))
            {
                var permToken = new KeywordToken(scope, code.Span, "permanent");
                tokens.Add(permToken);
                permanent = true;
            }

            ExtractTableDefinition exDef = null;
            string name = null;

            if (!code.ReadWord())
            {
                // Not correct syntax; exit here.
                return(new ExtractStatement(scope, tokens)
                {
                    _fields = new ExtractFieldDefinition[0]
                });
            }
            else if ((exDef = scope.DefinitionProvider.GetGlobalFromFile <ExtractTableDefinition>(code.Text).FirstOrDefault()) == null)
            {
                // The extract definition would have been added by the preprocessor. If it's not recognized here, then it's incorrect syntax.
                return(new ExtractStatement(scope, tokens)
                {
                    _fields = new ExtractFieldDefinition[0]
                });
            }
            else
            {
                name = code.Text;
                tokens.Add(new ExtractTableToken(scope, code.Span, name, exDef));
            }

            var ret = new ExtractStatement(scope, tokens);

            ret._name      = name;
            ret._permanent = permanent;

            var scope2 = scope.CloneIndent();

            scope2.Hint |= ScopeHint.SuppressControlStatements | ScopeHint.SuppressFunctionDefinition | ScopeHint.SuppressVarDecl;

            var fieldTokens = new List <ExtractFieldToken>();

            while (!code.EndOfFile)
            {
                if (code.ReadExact(';'))
                {
                    ret.AddToken(new StatementEndToken(scope2, code.Span));
                    break;
                }

                ExtractFieldDefinition fieldDef;
                if ((fieldDef = exDef.GetField(code.PeekWordR())) != null)
                {
                    var fieldToken = new ExtractFieldToken(scope, code.MovePeekedSpan(), code.Text, fieldDef);
                    fieldTokens.Add(fieldToken);
                    ret.AddToken(fieldToken);
                }
                else
                {
                    break;
                }

                if (!code.PeekExact("==") && code.PeekExact('='))
                {
                    var equalsToken = new OperatorToken(scope, code.MovePeekedSpan(), code.Text);
                    ret.AddToken(equalsToken);
                }
                else
                {
                    break;
                }

                var oldValue = code.StopAtLineEnd;
                code.StopAtLineEnd = true;
                try
                {
                    while (true)
                    {
                        var exp = ExpressionToken.TryParse(scope, null, expectedDataType: fieldDef.DataType);
                        if (exp != null)
                        {
                            ret.AddToken(exp);
                            if (fieldDef.DataType == null)
                            {
                                fieldDef.SetDataType(exp.ValueDataType);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                finally
                {
                    code.StopAtLineEnd = oldValue;
                }
            }

            var fields   = new List <ExtractFieldDefinition>();
            var rownoDef = new ExtractFieldDefinition("rowno", exDef.FilePosition, exDef);

            rownoDef.SetDataType(DataType.Unsigned9);
            fields.Add(rownoDef);
            fields.AddRange(from f in fieldTokens select f.SourceDefinition as ExtractFieldDefinition);
            ret._fields = fields.ToArray();

            return(ret);
        }