예제 #1
0
    public CoreClassifier parseType(
        EnvironmentImpl environment,
        string name)
    {
        CSTNode       node  = null;
        List <object> nodes = null;

        try {
            nodes = compileOclStream(name, "", new StreamWriter(new MemoryStream()), typeof(CSTTypeCS));
            node  = (CSTNode)nodes[0];
        } catch (Exception e) {
            Console.WriteLine(e.Message);
        }

        if (node != null)
        {
            CSTTypeCS typeNode = (CSTTypeCS)node;
            parsedTypes.Add(typeNode.getAst().getFullPathName(), nodes);
            return(typeNode.getAst());
        }
        else
        {
            return(null);
        }
    }
예제 #2
0
        private CoreClassifier checkResult(CSTNode rootNode, String expectedTypeName)
        {
            CSTArgumentCS argument = (CSTArgumentCS)rootNode;
            OclExpression ast      = argument.getAst();

            Assert.AreEqual(expectedTypeName, ast.getType().getName());
            return(ast.getType());
        }
예제 #3
0
        protected VariableDeclaration getVariableDeclaration(String literal)
        {
            CSTNode node = parseOK(literal, this.getCurrentMethodName());

            Assert.IsTrue(node is CSTVariableDeclarationCS);
            CSTVariableDeclarationCS variable = (CSTVariableDeclarationCS)node;

            return((VariableDeclaration)variable.getAst());
        }
        public CollectionLiteralExp doTestOK(String literal)
        {
            CSTNode node = parseOK(literal, this.getCurrentMethodName());

            Assert.IsTrue(node is CSTCollectionLiteralExpCS);
            CSTCollectionLiteralExpCS literalExp = (CSTCollectionLiteralExpCS)node;

            Assert.IsNotNull(literalExp.getAst());
            Assert.IsTrue(literalExp.getAst() is CollectionLiteralExp);
            return((CollectionLiteralExp)literalExp.getAst());
        }
        public TupleLiteralExp doTestOK(String literal, String typeName, String callerMethodName)
        {
            CSTNode node = parseOK(literal, callerMethodName);

            Assert.IsTrue(node is CSTTupleLiteralExpCS);
            CSTTupleLiteralExpCS literalExp = (CSTTupleLiteralExpCS)node;

            Assert.IsNotNull(literalExp.getAst());
            Assert.IsTrue(literalExp.getAst() is TupleLiteralExp);
            Assert.AreEqual(typeName, literalExp.getAst().getType().getName());
            return((TupleLiteralExp)literalExp.getAst());
        }
 protected virtual List <object> getConstraints(CSTNode rootNode)
 {
     if (rootNode is CSTClassifierContextDeclCS)
     {
         CSTClassifierContextDeclCS context = (CSTClassifierContextDeclCS)rootNode;
         List <object> constraints          = context.getConstraintsNodesCS();
         return(constraints);
     }
     else
     {
         return(null);
     }
 }
예제 #7
0
    protected List <object> parseNode(OCLWorkbenchParser parser, Type nodeClass)
    {
        List <object> result = null;
        CSTNode       node   = null;

        if (nodeClass == null)
        {
            result = parser.expressionStream();
        }
        else if (nodeClass == typeof(CSTExpressionInOclCS))
        {
            node = parser.expressionInOCLCS();
        }
        else if (nodeClass == typeof(CSTTypeCS))
        {
            node = parser.typeCS();
        }
        else if (nodeClass == typeof(CSTContextDeclarationCS))
        {
            node = parser.contextDeclarationCS();
        }
        else if (nodeClass == typeof(CSTArgumentCS))
        {
            List <object> arguments = parser.argumentsCS();
            node = (CSTNode)arguments[0];
        }
        else if (nodeClass == typeof(CSTLiteralExpCS))
        {
            node = parser.literalExpCS();
        }
        else if (nodeClass == typeof(CSTVariableDeclarationCS))
        {
            node = parser.variableDeclarationCS();
        }
        else if (nodeClass == typeof(CSTVariableDeclarationCS))
        {
            node = parser.variableDeclarationCS();
        }
        else if (nodeClass == typeof(CSTClassifierAttributeCallExpC))
        {
            node = parser.classifierAttributeCallExpCS();
        }

        if ((result == null) && (node != null))
        {
            result = new List <object>();
            result.Add(node);
        }

        return(result);
    }
        protected List <object> doTestContextOK(String expression, String testName)
        {
            source = testName;
            CSTNode rootNode = parseOK(expression, testName);

            Assert.IsNotNull(rootNode);
            if (rootNode != null)
            {
                return(getConstraints(rootNode));
            }
            else
            {
                return(null);
            }
        }
 private void doTestPackageOK(String expression, String testName)
 {
     try {
         rootNode = getRootNode(expression, testName);
         oclSemanticAnalyzer.analyze(environment, rootNode);
     }
     catch (OCLSemanticException ex) {
         OCLWorkbenchToken token = ex.getNode().getToken();
         Console.WriteLine(token.getFilename() + ":" + token.getLine() + "[" + token.getColumn() + "]" + ex.Message);
         throw new AssertFailedException();
     }
     catch (Exception e) {
         Console.WriteLine(e.Message);
         throw new AssertFailedException();
     }
 }
예제 #10
0
        public void doTestEnumOK(String enumFullName, String enumName, String enumLiteral, String source)
        {
            CSTNode node = parseOK(enumFullName + "::" + enumLiteral, source);

            Assert.IsTrue(node is CSTClassifierAttributeCallExpCS);
            CSTClassifierAttributeCallExpCS literalExp = (CSTClassifierAttributeCallExpCS)node;

            Assert.IsNotNull(literalExp.getAst());
            Assert.IsTrue(literalExp.getAst() is EnumLiteralExp);
            EnumLiteralExp ast = (EnumLiteralExp)literalExp.getAst();

            Assert.AreEqual(enumLiteral, ast.getReferredEnumLiteral().getName());

            Assert.IsNotNull(ast.getType());
            Assert.AreEqual(enumName, ast.getType().getName());
        }
예제 #11
0
        private void doTestReal(String expectedValueStr, double expectedValue)
        {
            CSTNode node = parseOK(expectedValueStr, this.getCurrentMethodName());

            Assert.IsTrue(node is CSTRealLiteralExpCS);
            CSTRealLiteralExpCS literalExp = (CSTRealLiteralExpCS)node;

            Assert.IsNotNull(literalExp.getAst());
            Assert.IsTrue(literalExp.getAst() is RealLiteralExp);
            RealLiteralExp ast = (RealLiteralExp)literalExp.getAst();

            Assert.AreEqual(expectedValue, Double.Parse(ast.getRealSymbol(), CultureInfo.InvariantCulture));
            CoreClassifier type = ast.getType();

            Assert.IsNotNull(type);
            Assert.AreEqual("Real", type.getName());
        }
예제 #12
0
        private void doTestString(String input, String expectedValue)
        {
            CSTNode node = parseOK(input, this.getCurrentMethodName());

            Assert.IsTrue(node is CSTStringLiteralExpCS);
            CSTStringLiteralExpCS literalExp = (CSTStringLiteralExpCS)node;

            Assert.IsNotNull(literalExp.getAst());
            Assert.IsTrue(literalExp.getAst() is StringLiteralExp);
            StringLiteralExp ast = (StringLiteralExp)literalExp.getAst();

            Assert.AreEqual(expectedValue, ast.getStringSymbol());
            CoreClassifier type = ast.getType();

            Assert.IsNotNull(type);
            Assert.AreEqual("String", type.getName());
        }
 public void testClassifier_05()
 {
     try {
         rootNode = getRootNode("package MyExample::package_1::package_1_1 context  Product inv: expression context Rental inv: exp context Film inv: exp context  Product inv: expression endpackage" +
                                " package java context Integer inv: expression endpackage", "testClassifier_05");
         oclSemanticAnalyzer.analyze(environment, rootNode);
     }
     catch (OCLSemanticException ex) {
         OCLWorkbenchToken token = ex.getNode().getToken();
         Console.WriteLine(token.getFilename() + ":" + token.getLine() + "[" + token.getColumn() + "]" + ex.Message);
         throw new AssertFailedException();
     }
     catch (Exception e) {
         Console.WriteLine(e.Message);
         throw new AssertFailedException();
     }
 }
예제 #14
0
        private void doTestBoolean(bool expectedValue)
        {
            CSTNode node = parseOK(expectedValue.ToString().ToLower(), this.getCurrentMethodName());

            Assert.IsTrue(node is CSTBooleanLiteralExpCS);
            CSTBooleanLiteralExpCS literalExp = (CSTBooleanLiteralExpCS)node;

            Assert.IsNotNull(literalExp.getAst());
            Assert.IsTrue(literalExp.getAst() is BooleanLiteralExp);
            BooleanLiteralExp ast = (BooleanLiteralExp)literalExp.getAst();

            Assert.AreEqual(expectedValue, ast.isBooleanSymbol());
            CoreClassifier type = ast.getType();

            Assert.IsNotNull(type);
            Assert.AreEqual("Boolean", type.getName());
        }
예제 #15
0
        private void doTestInteger(int expectedValue)
        {
            CSTNode node = parseOK(expectedValue.ToString(CultureInfo.InvariantCulture), this.getCurrentMethodName());

            Assert.IsTrue(node is CSTIntegerLiteralExpCS);
            CSTIntegerLiteralExpCS literalExp = (CSTIntegerLiteralExpCS)node;

            Assert.IsNotNull(literalExp.getAst());
            Assert.IsTrue(literalExp.getAst() is IntegerLiteralExp);
            IntegerLiteralExp ast = (IntegerLiteralExp)literalExp.getAst();

            Assert.AreEqual(expectedValue, ast.getIntegerSymbol());
            CoreClassifier type = ast.getType();

            Assert.IsNotNull(type);
            Assert.AreEqual("Integer", type.getName());
        }
        private CSTNode getClassifierRootNode(String source, String inputName)
        {
            OCLWorkbenchParser parser;
            StreamWriter       err;

            StringReader inR    = new StringReader(source);
            String       inName = inputName;

            err = new StreamWriter(Console.OpenStandardOutput());
            err.Flush();

            HashSet <Exception> errorsList = new HashSet <Exception>();
            OCLWorkbenchLexer   lexer      = new OCLWorkbenchLexer(inR, inName, err, errorsList);

            parser = new OCLWorkbenchParser(inName, lexer, err, errorsList);

            CSTNode result = null;

            try {
                result = parser.contextDeclarationCS();
            } catch (antlr.RecognitionException e) {
                err.WriteLine(parser.getFilename() + ":" +
                              "[" + e.getLine() + ", " + e.getColumn() + "]: " +
                              e.Message);
                throw e;
            } catch (antlr.TokenStreamRecognitionException e) {
                err.WriteLine(parser.getFilename() + ":" +
                              "[" + e.recog.getLine() + ", " + e.recog.getColumn() + "]: " +
                              e.recog.Message);
                throw e;
            } catch (antlr.TokenStreamException ex) {
                err.WriteLine(parser.getFilename() + ":" + ex.Message);
                throw ex;
            }   finally {
                err.Flush();
            }

            if (parser.getErrorCount() != 0)
            {
                throw new Exception("syntatic errors in compilation");
            }

            return(result);
        }
예제 #17
0
        public CoreClassifier doParseTestOK(String stream, String inputName, String resultName, Type className)
        {
            try {
                CSTNode node = parseOK(stream, inputName);
                Assert.IsTrue(node is CSTTypeCS);
                CSTTypeCS type = (CSTTypeCS)node;

                CoreClassifier ast = type.getAst();
                Assert.IsNotNull(ast);
                Assert.AreEqual(resultName, ast.getName());
                Assert.IsTrue(className.IsInstanceOfType(ast));
                return(ast);
            }
            catch (Exception e) {
                Console.WriteLine(e.StackTrace);
                throw new AssertFailedException();
            }

            return(null);
        }
예제 #18
0
 public void analyzeFeatureDefinitions(Environment context, CSTNode rootNode)
 {
     oclSemanticAnalyzerVisitor = new OCLDefinedFeaturesVisitor(context, constraintSourceTracker);
     rootNode.accept(oclSemanticAnalyzerVisitor);
 }
예제 #19
0
 public OCLSemanticException(CSTNode node, string message)
     : base(message, new SourceLocation(node.getToken()))
 {
     this.node = node;
 }
예제 #20
0
        protected CoreClassifier doTestOK(String expression, String expectedTypeName, String testName)
        {
            CSTNode rootNode = parseOK(expression, testName);

            return(checkResult(rootNode, expectedTypeName));
        }
예제 #21
0
 public void analyze(Environment context, CSTNode rootNode)
 {
     oclSemanticAnalyzerVisitor = getSemanticAnalyzerVisitor(context);
     rootNode.accept(oclSemanticAnalyzerVisitor);
 }
예제 #22
0
 public void doAction(OCLSemanticAnalyzer analyzer, EnvironmentImpl environment, CSTNode node)
 {
     analyzer.analyze(environment, node);
 }
예제 #23
0
 public OCLMultipleSemanticExceptions(CSTNode node, string message) : base(node, message)
 {
     exceptions = new List <OCLSemanticException>();
 }
예제 #24
0
 public void doAction(OCLSemanticAnalyzer analyzer, Environment environment, CSTNode node)
 {
     analyzer.analyzeFeatureDefinitions(environment, node);
 }
예제 #25
0
 public ConcreteSyntaxTree(CSTNode root = null) : base(root)
 {
 }
예제 #26
0
 protected override List <object> getConstraints(CSTNode rootNode)
 {
     return(null);
 }