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)); }
bool IsIteratorOperation(AST.OclExpression expr, List <IToken> tokenPath) { if (tokenPath == null && tokenPath.Count != 1) { return(false); } if (expr.Type is InvalidType) { return(false); } string name = tokenPath[0].Text; IteratorOperation iteratorOperation = ((CollectionType)(expr.Type)).LookupIteratorOperation(name); return(iteratorOperation != null); }