コード例 #1
0
ファイル: OCLAst.g3.cs プロジェクト: mff-uk/exolutio
        AST.OclExpression ResolveImplicitOperation(List <IToken> tokenPath, bool isPre, List <AST.OclExpression> callArgs)
        {
            if (TestNull(tokenPath, callArgs))
            {
                return(new AST.ErrorExp(Library.Invalid));
            }

            var           codeSource = new CodeSource(tokenPath[0]);
            List <string> path       = tokenPath.ToStringList();

            if (path.Count == 1)
            {
                // simple name
                //35 d,f
                ImplicitOperationData operation = Environment.LookupImplicitOperation(path[0], callArgs.Select(arg => arg.Type));
                if (operation == null)
                {
                    Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_ResolveImplicitOperation_Operation_not_found_1, path[0])));
                    return(new AST.ErrorExp(Library.Any));
                }
                //self problem
                // tady by melo byt vyreseno self
                AST.VariableExp operationSource = new AST.VariableExp(operation.Source)
                                                  .SetCodeSource(codeSource);
                return(new AST.OperationCallExp(operationSource, isPre, operation.Operation, callArgs, Environment)
                       .SetCodeSource(codeSource));
            }
            else
            {
                //path
                // 35 g
                // lookupPathName neresi pretizeni nazvu => a nezohlednuje operace s ruznymi signaturami
                throw new NotSupportedException();
            }
        }
コード例 #2
0
ファイル: OCLAst.g3.cs プロジェクト: mff-uk/exolutio
        private AST.OclExpression CreateImplicitPropertyIterator(AST.OclExpression expr, IToken token, Classifier sourceType, Property property)
        {
            if (TestNull(expr, property))
            {
                return(new AST.ErrorExp(Library.Invalid));
            }

            var codeSource = new CodeSource(token);
            VariableDeclaration        varDecl = new VariableDeclaration("", sourceType, null);
            List <VariableDeclaration> varList = new List <VariableDeclaration>();

            varList.Add(varDecl);
            AST.VariableExp localVar = new AST.VariableExp(varDecl)
                                       .SetCodeSource(codeSource);
            AST.PropertyCallExp localProp = CheckAmbiguous(new AST.PropertyCallExp(localVar, false, null, null, property))
                                            .SetCodeSource(codeSource);
            //Napevno zafixovany navratovy typ collect
            // JM > kdyz je typ Set(Class) nebo Bag(Class) tak by mel implicit collect vracet Bag(Class)
            Classifier returnType;

            if (property.Type is CollectionType)
            {
                returnType = Library.CreateCollection(CollectionKind.Bag, ((CollectionType)property.Type).ElementType);
            }
            else
            {
                returnType = Library.CreateCollection(CollectionKind.Collection, property.Type);
            }
            return(new AST.IteratorExp(expr, localProp, @"collect", varList, returnType)
                   .SetCodeSource(codeSource));
        }
コード例 #3
0
ファイル: OCLAst.g3.cs プロジェクト: mff-uk/exolutio
        AST.OclExpression ResolvePath(List <IToken> tokenPath, bool isPre)
        {
            if (TestNull(tokenPath))
            {
                return(new AST.ErrorExp(Library.Invalid));
            }

            var           codeSource = new CodeSource(tokenPath[0]);
            List <string> path       = tokenPath.ToStringList();

            if (path.Count == 1)
            {
                // simpleName
                IModelElement element = Environment.Lookup(path[0]);

                //Variable
                if (element is VariableDeclaration)
                {
                    if (isPre)
                    {
                        Errors.AddError(new ErrorItem(CompilerErrors.OCLAst_ResolvePath_Modifikator__pre_se_nepoji_s_promenou));
                    }
                    return(new AST.VariableExp((VariableDeclaration)element)
                           .SetCodeSource(codeSource));
                }
                //Property 36B
                ImplicitPropertyData implProperty = Environment.LookupImplicitAttribute(path[0]);
                if (implProperty != null)
                {
                    // self problem
                    AST.VariableExp propertySource = new AST.VariableExp(implProperty.Source)
                                                     .SetCodeSource(codeSource);
                    return(CheckAmbiguous(new AST.PropertyCallExp(propertySource, isPre, null, null, implProperty.Property))
                           .SetCodeSource(codeSource));
                }
                // chyby naky to pravidlo

                // JM > type exp
                if (element is Classifier)
                {
                    return(new AST.TypeExp((Classifier)element, Library.Type)
                           .SetCodeSource(codeSource));
                }
            }
            else
            {
                // path
                IModelElement element = Environment.LookupPathName(path);
                //Chyby enum !!!!!!!!!!!!!!!!!!!!!!!!
                if (element is Classifier)
                {
                    return(new AST.TypeExp((Classifier)element, Library.Type)
                           .SetCodeSource(codeSource));
                }
                // Chyby 36C
            }
            Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_ResolvePath_Chyba_nebo_nepodporovane_pravidlo, tokenPath.First(), tokenPath.Last()));
            return(new AST.ErrorExp(Library.Invalid));
        }
コード例 #4
0
ファイル: OCLAst.g3.cs プロジェクト: mff-uk/exolutio
        private AST.OclExpression CreateImplicitCollectIterator(AST.OclExpression expr, IToken token, List <AST.OclExpression> args, Classifier sourceType, Operation op)
        {
            if (TestNull(expr, args, sourceType, op))
            {
                return(new AST.ErrorExp(Library.Invalid));
            }

            var codeSource = new CodeSource(token);
            VariableDeclaration        varDecl = new VariableDeclaration(string.Empty, sourceType, null);
            List <VariableDeclaration> varList = new List <VariableDeclaration>();

            varList.Add(varDecl);
            AST.VariableExp localVar = new AST.VariableExp(varDecl)
                                       .SetCodeSource(codeSource);
            AST.OperationCallExp localOp = new AST.OperationCallExp(localVar, false, op, args, Environment)
                                           .SetCodeSource(codeSource);
            //Napevno zafixovany navratovy typ collect
            Classifier returnType = Library.CreateCollection(CollectionKind.Collection, op.ReturnType);

            return(new AST.IteratorExp(expr, localOp, @"collect", varList, returnType)
                   .SetCodeSource(codeSource));
        }