Exemple #1
0
        Classifier PropertyContextHead(List <string> path, string selfName, Classifier declaredPropertyType, out VariableDeclaration selfOut, out Property property)
        {
            if (path.Count < 2)
            {
                // error
                selfOut = null; property = null;
                Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_PropertyContextHead_Incorrect_context_declaration___0___Class_and_operation_name_expected_1, path.ConcatWithSeparator("::"))));
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                return(null);
            }

            string        propertyName = path.Last();
            IModelElement element      = Environment.LookupPathName(path.Take(path.Count - 1));

            if (element is Classifier == false)
            {
                // error
                selfOut = null; property = null;
                Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_ClassifierContextHead_ClassifierNotFound_1, path.Take(path.Count - 1).ConcatWithSeparator(@"::"))));
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                return(null);
            }
            Classifier contextClassifier = element as Classifier;

            property = contextClassifier.LookupProperty(propertyName);
            if (property == null)
            {
                // error
                selfOut = null;
                Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_PropertyContextHead_PropertyNotFound_2, propertyName, contextClassifier)));
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                return(null);
            }

            if (property.Type != declaredPropertyType)
            {
                // error
                selfOut = null;
                Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_PropertyContextHead_TypeMismatch_3, property.Name, property.Type, declaredPropertyType)));
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                return(null);
            }

            VariableDeclaration varSelf = new VariableDeclaration(selfName, contextClassifier, null);// tady by to chtelo doplnit initValue

            selfOut = varSelf;
            Environment classifierEnv = Environment.CreateFromClassifier(contextClassifier, varSelf);

            EnvironmentStack.Push(classifierEnv);

            Environment self = Environment.AddElement(selfName, contextClassifier, varSelf, true);

            EnvironmentStack.Push(self);

            return(contextClassifier);
        }
Exemple #2
0
        VariableDeclaration LetDecl(IToken letToken, VariableDeclarationBag varBag)
        {
            if (TestNull(letToken, varBag, varBag != null ? varBag.Type : null))
            {
                return(new VariableDeclaration("", Library.Invalid, new AST.ErrorExp(Library.Invalid)));
            }

            if (Environment.Lookup(varBag.Name) != null)
            {
                Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_LetDecl_The_variable_name_must_be_unique_in_the_current_scope, letToken, letToken));
                return(null);
            }

            Classifier type = varBag.Type ?? varBag.Expression.Type;

            if (varBag.Expression.Type.ConformsTo(varBag.Type) == false)
            {
                Errors.AddError(new CodeErrorItem(CompilerErrors.OCLAst_LetDecl_Variable_type_does_not_conform_to_variable_expression_type, letToken, letToken));
            }

            VariableDeclaration var = new VariableDeclaration(varBag.Name, varBag.Type, varBag.Expression);

            EnvironmentStack.Push(Environment.AddElement(var.Name, var.PropertyType, var, true));
            return(var);
        }
Exemple #3
0
        Classifier ClassifierContextHead(List <IToken> tokenPath, string selfName, out VariableDeclaration selfOut)
        {
            List <string> path    = tokenPath.ToStringList();
            IModelElement element = Environment.LookupPathName(path);

            if (element is Classifier == false)
            {
                // error
                selfOut = null;
                Errors.AddError(new ErrorItem(string.Format(CompilerErrors.OCLAst_ClassifierContextHead_ClassifierNotFound_1, path.ConcatWithSeparator(@"::"))));
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                EnvironmentStack.Push(ErrorEnvironment.Instance);
                return(null);
            }
            Classifier          contextClassifier = element as Classifier;
            VariableDeclaration varSelf           = new VariableDeclaration(selfName, contextClassifier, null);// tady by to chtelo doplnit initValue

            selfOut = varSelf;
            Environment classifierEnv = Environment.CreateFromClassifier(contextClassifier, varSelf);

            EnvironmentStack.Push(classifierEnv);

            Environment self = Environment.AddElement(selfName, contextClassifier, varSelf, true);

            EnvironmentStack.Push(self);

            return(contextClassifier);
        }
Exemple #4
0
        VariableDeclaration ProcessImplicitVarDef(AST.OclExpression expr, ref int pushedVar)
        {
            if (TestNull(expr))
            {
                return(new VariableDeclaration("", Library.Invalid, new AST.ErrorExp(Library.Invalid)));
            }

            Classifier type;

            if (expr.Type is CollectionType)
            {
                type = ((CollectionType)expr.Type).ElementType;
            }
            else
            {
                type = expr.Type;
            }

            VariableDeclaration decl = new VariableDeclaration("", type, null);
            //add variable to EnviromentStack
            var env = Environment.CreateFromClassifier(decl.PropertyType, decl);

            EnvironmentStack.Push(env);
            //inc pushedVar to future pop EnviromentStack
            //pushedVar is ref variable
            pushedVar++;
            return(decl);
        }
Exemple #5
0
        VariableDeclaration ProcessTypeDef(IToken name, Classifier type, AST.OclExpression initExpr, ref int pushedVar)
        {
            if (TestNull(name))
            {
                return(new VariableDeclaration("", Library.Invalid, new AST.ErrorExp(Library.Invalid)));
            }
            VariableDeclaration decl = new VariableDeclaration(name.Text, type, null);
            //add variable to EnviromentStack
            var env = Environment.AddElement(decl.Name, decl.PropertyType, decl, true);

            EnvironmentStack.Push(env);
            //inc pushedVar to future pop EnviromentStack
            //pushedVar is ref variable
            pushedVar++;
            return(decl);
        }