コード例 #1
0
ファイル: DotToken.cs プロジェクト: seljmov/Semantic-IDE
 private void AddUsages(SemanticOperator @operator)
 {
     if (@operator is INameable nameable)
     {
         SemanticItem.AddUsages(nameable, RightOperand.Token);
     }
 }
コード例 #2
0
ファイル: DotToken.cs プロジェクト: seljmov/Semantic-IDE
        private SemanticOperator GetOperatorFromSimpleType(SimpleType leftType)
        {
            if (StringAnalyzer.IsClassOrModuleMember(leftType.Text))
            {
                var classOrModuleName = StringAnalyzer.GetClassOrModuleName(leftType.Text);
                var memberName        = StringAnalyzer.GetMemberName(leftType.Text);

                if (Token.Tree.Project.HasModuleWithName(classOrModuleName))
                {
                    var tree   = Token.Tree.Project.GetModuleByName(classOrModuleName);
                    var record = tree.GetDeclaredTypes().FirstOrDefault(x => x.NameWord.Text == memberName);
                    // record?.
                    if (record != null)
                    {
                        var member = record.GetMembers()
                                     .FirstOrDefault(x => ((INameable)x).NameWord.Text.Equals(Name));

                        if (member != null)
                        {
                            return(member);
                        }

                        SemanticError error = null;
                        if (Parent is FunctionToken)
                        {
                            error = new ClassMissingMethod(Token.Operator, RightOperand.Words, record, Name);
                        }
                        else if (Parent is ArrayToken)
                        {
                            error = new ClassMissingArray(Token.Operator, RightOperand.Words, record, Name);
                        }
                        else
                        {
                            error = new ClassMissingField(Token.Operator, RightOperand.Words, record, Name);
                        }

                        GenerateFind(error);
                    }
                }
            }
            else
            {
                var record = Token.Tree.GetDeclaredTypes()
                             .FirstOrDefault(x => x.NameWord.Text.Equals(leftType.Text));

                if (record != null)
                {
                    var member = record.GetMembers()
                                 .FirstOrDefault(x => ((INameable)x).NameWord.Text.Equals(Name));

                    if (member != null)
                    {
                        return(member);
                    }

                    SemanticError error = null;
                    if (Parent is FunctionToken)
                    {
                        error = new ClassMissingMethod(Token.Operator, RightOperand.Words, record, Name);
                    }
                    else if (Parent is ArrayToken)
                    {
                        error = new ClassMissingArray(Token.Operator, RightOperand.Words, record, Name);
                    }
                    else
                    {
                        error = new ClassMissingField(Token.Operator, RightOperand.Words, record, Name);
                    }

                    GenerateFind(error);
                }
                else
                {
                    var import = Token.Tree.GetImports()
                                 .FirstOrDefault(x => x.NameWord.Text.Equals(leftType.Text));

                    if (import != null)
                    {
                        if (!Token.Tree.Project.HasModuleWithName(import.NameWord.Text))
                        {
                            GenerateFind(new UndeclaredModule(Token.Operator, LeftOperand.Words, import.NameWord.Text));
                        }
                        else
                        {
                            var tree   = Token.Tree.Project.GetModuleByName(import.NameWord.Text);
                            var module = tree.FindModule();

                            if (module != null)
                            {
                                SemanticItem.AddUsages(module, LeftOperand.Token);
                                var member = tree.GetMembers()
                                             .FirstOrDefault(x => ((INameable)x).NameWord.Text.Equals(Name));

                                if (member != null)
                                {
                                    return(member);
                                }

                                SemanticError error = null;
                                if (Parent is FunctionToken)
                                {
                                    error = new ModuleMissingFunction(Token.Operator, RightOperand.Words, tree.FindModule(), Name);
                                }
                                else if (Parent is ArrayToken)
                                {
                                    error = new ModuleMissingArray(Token.Operator, RightOperand.Words, tree.FindModule(), Name);
                                }
                                else
                                {
                                    error = new ModuleMissingVariable(Token.Operator, RightOperand.Words, tree.FindModule(), Name);
                                }

                                GenerateFind(error);
                            }
                        }
                    }
                }
            }

            return(null);
        }
コード例 #3
0
ファイル: FunctionToken.cs プロジェクト: seljmov/Semantic-IDE
        public override ISemanticType GetSemanticType()
        {
            if (Function is DotToken dotToken)
            {
                dotToken.GetSemanticType();
                if (dotToken.LeftType is ArrayType && SystemNames.ArraySizes.Contains(dotToken.Name))
                {
                    return(SimpleType.Integer);
                }

                var subprogram = dotToken.GetSubprogram();
                if (subprogram != null)
                {
                    ValidateParameters(subprogram.ParametersWord);
                    return(GetSubprogramType(subprogram));
                }

                GenerateFind(new ObjectIsNotSubprogram(
                                 dotToken.RightOperand.Token.Operator,
                                 dotToken.RightOperand.Token.Words,
                                 dotToken.RightOperand.Token.Text));
            }
            if (Function is OperandToken operandToken)
            {
                if (operandToken.Name.Equals(SyntaxNames.New))
                {
                    const int formalCount = 1;
                    var       actualCount = Arguments.Count;
                    for (var i = 0; i < actualCount; ++i)
                    {
                        var actualType = Arguments[i].GetSemanticType();
                        if (i < formalCount)
                        {
                            if (!actualType.IsUserType)
                            {
                                GenerateFind(new ArgumentHasIncorrectType(Token.Operator, Arguments[i].Words));
                            }
                        }
                    }

                    if (actualCount != formalCount)
                    {
                        GenerateFind(new IncorrectArgumentCount(Token.Operator, Function.Words, actualCount, formalCount));
                        return(SimpleType.Undefined);
                    }

                    return(new PointerType(null)
                    {
                        TypeWord = (SemanticItem)Arguments[0].GetSemanticType()
                    });
                }

                if (operandToken.Name.StartsWith(SystemNames.SystemFuncDog))
                {
                    foreach (var token in Arguments)
                    {
                        token.GetSemanticType();
                    }

                    return(SimpleType.SystemType);
                }

                var name = Token.GetNameInSameScope(operandToken.Name);
                if (name is Subprogram subNameable)
                {
                    SemanticItem.AddUsages(name, Function.Token);
                    ValidateParameters(subNameable.ParametersWord);
                    return(GetSubprogramType(subNameable));
                }

                if (name is TypeParameter {
                    TypeWord : ProcedureType type
                })