Exemple #1
0
        AST.OclExpression ProcessIteratorCall(AST.OclExpression expr, List <IToken> tokenPath, List <VariableDeclaration> decls, List <AST.OclExpression> args)
        {
            if (TestNull(expr, tokenPath, decls, args))
            {
                return(new AST.ErrorExp(Library.Invalid));
            }

            // apply oclAsSet opretion on not collect type
            if (expr.Type is CollectionType == false)
            {
                Operation asSetOp = expr.Type.LookupOperation(Library.OclAsSet, new Classifier[0]);
                if (asSetOp == null)
                {
                    Errors.AddError(new ErrorItem(String.Format(CompilerErrors.OCLParser_OperationNotFound_1, Library.OclAsSet)));
                    return(new AST.ErrorExp(Library.Invalid));
                }
                expr = new AST.OperationCallExp(expr, false, asSetOp, new List <AST.OclExpression>(), Environment)
                       .SetCodeSource(new CodeSource(tokenPath[0]));
            }

            List <string> path = tokenPath.ToStringList();

            if (path.Count != 1)
            {
                Errors.AddError(new CodeErrorItem(string.Format(CompilerErrors.OCLAst_ProcessIteratorCall_Unknow_iterator_operation), tokenPath.First(), tokenPath.Last()));
                return(new AST.ErrorExp(Library.Invalid));
            }
            if (args.Count > 1)
            {
                Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_ProcessIteratorCall_Iterator_ma_jenom_jedno_tělo_výrazu, tokenPath.First(), tokenPath.Last()));
            }

            string name = path[0];

            IteratorOperation iteratorOperation = ((CollectionType)(expr.Type)).LookupIteratorOperation(name);

            // Iterator variable muze byt NULL -> pak se pouziji defaultni nazvy ... neni implementovano
            if (iteratorOperation != null)
            {
                // Pozadovany typ na telo iteratoru, podle pouzite funkce
                Classifier bodyType = iteratorOperation.BodyType(expr.Type as CollectionType, args[0].Type, TypesTable);
                if (args[0].Type.ConformsTo(bodyType) == false)
                {
                    Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_ProcessIteratorCall_Body_type_inconsistency, tokenPath.First(), tokenPath.Last()));
                }
                //Navratovy typ iteratoru podle pouzite operace
                Classifier returnType = iteratorOperation.ExpressionType(expr.Type as CollectionType, args[0].Type, TypesTable);

                return(new AST.IteratorExp(expr, args[0], name, decls, returnType)
                       .SetCodeSource(new CodeSource(tokenPath[0])));
            }

            Errors.AddError(new CodeErrorItem(string.Format(CompilerErrors.OCLAst_ProcessIteratorCall_Bad_iterator_operation_1, name), tokenPath.First(), tokenPath.Last()));
            return(new AST.ErrorExp(Library.Invalid));
        }
Exemple #2
0
        AST.OclExpression ProcessCollectionOperationCall(AST.OclExpression expr, List <IToken> tokenPath, List <AST.OclExpression> args)
        {
            if (TestNull(expr, tokenPath))
            {
                return(new AST.ErrorExp(Library.Invalid));
            }

            // v pripade ze funkce ma nula argumentu neprovedese vytvoreni prazdneho listu v gramatice
            if (args == null)
            {
                args = new List <AST.OclExpression>();
            }
            List <string> path = tokenPath.ToStringList();

            if (path.Count != 1)
            {
                Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_ProcessIteratorCall_Unknow_iterator_operation, tokenPath.First(), tokenPath.Last()));
                return(new AST.ErrorExp(Library.Invalid));
            }
            string name = path[0];

            // apply oclAsSet opretion on not collect type
            if (expr.Type is CollectionType == false)
            {
                Operation asSetOp = expr.Type.LookupOperation(Library.OclAsSet, new Classifier[0]);
                if (asSetOp == null)
                {
                    Errors.AddError(new ErrorItem(String.Format(CompilerErrors.OCLParser_OperationNotFound_1, Library.OclAsSet)));
                    return(new AST.ErrorExp(Library.Invalid));
                }
                expr = new AST.OperationCallExp(expr, false, asSetOp, new List <AST.OclExpression>(), Environment)
                       .SetCodeSource(new CodeSource(tokenPath[0]));
            }

            Operation collectionOperation = expr.Type.LookupOperation(name,
                                                                      args.Select(arg => arg.Type));

            if (collectionOperation != null)   // 36b
            {
                return(new AST.OperationCallExp(expr, false, collectionOperation, args, Environment)
                       .SetCodeSource(new CodeSource(tokenPath[0])));
            }

            Errors.AddError(new CodeErrorItem(String.Format(CompilerErrors.OCLAst_ProcessCollectionOperationCall_Unknown_collection_operation, name), tokenPath.First(), tokenPath.Last()));
            return(new AST.ErrorExp(Library.Invalid));
        }
Exemple #3
0
        public string Visit(OperationCallExp node)
        {
            if (node.Source != null)
            {
                node.Source.Accept(this);
            }
            sb.Append(".");
            sb.Append(node.ReferredOperation.Name);
            sb.Append("(");
            foreach (var arg in node.Arguments)
            {
                arg.Accept(this);
                sb.Append(",");
            }
            sb.Append(")");

            return(string.Empty);
        }
Exemple #4
0
        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));
        }