Beispiel #1
0
 def _EvaluatePath(self, host, expr):
     if isinstance(expr, Identifier):
         try:
             return self._variables[
                 expr.
                 Name]  # self._variables only available via late binding
         except KeyError as ex:
             raise ParserException("Identifier '{0}' not found.".format(
                 expr.Name)) from ex
     elif isinstance(expr, StringLiteral):
         return expr.Value
     elif isinstance(expr, IntegerLiteral):
         return str(expr.Value)
     elif isinstance(expr, InterpolateLiteral):
         config = host.PoCConfig
         return config.Interpolation.interpolate(config,
                                                 "CONFIG.DirectoryNames",
                                                 "xxxx", str(expr), {})
     elif isinstance(expr, SubDirectoryExpression):
         l = self._EvaluatePath(host, expr.LeftChild)
         r = self._EvaluatePath(host, expr.RightChild)
         return l + "/" + r
     elif isinstance(expr, ConcatenateExpression):
         l = self._EvaluatePath(host, expr.LeftChild)
         r = self._EvaluatePath(host, expr.RightChild)
         return l + r
     else:
         raise ParserException(
             "Unsupported path expression type '{0!s}'".format(type(expr)))
Beispiel #2
0
 def _ResolveRule(self, ruleStatement, lst):
     if isinstance(ruleStatement, CopyStatement):
         sourceFile = ruleStatement.SourcePath
         destinationFile = ruleStatement.DestinationPath
         rule = self._classCopyRule(sourceFile, destinationFile)
         lst.append(rule)
     elif isinstance(ruleStatement, DeleteStatement):
         file = ruleStatement.FilePath
         rule = self._classDeleteRule(file)
         lst.append(rule)
     elif isinstance(ruleStatement, FileStatement):
         # FIXME: Currently, all replace and append rules are stored in individual rule instances.
         # FIXME: This prevents the system from creating a single task of multiple sub-rules -> just one open/close would be required
         filePath = ruleStatement.FilePath
         for nestedStatement in ruleStatement.Statements:
             if isinstance(nestedStatement, ReplaceStatement):
                 rule = self._classReplaceRule(
                     filePath, nestedStatement.SearchPattern,
                     nestedStatement.ReplacePattern,
                     nestedStatement.MultiLine, nestedStatement.DotAll,
                     nestedStatement.CaseInsensitive)
                 lst.append(rule)
             elif isinstance(nestedStatement, AppendLineStatement):
                 rule = self._classAppendLineRule(
                     filePath, nestedStatement.AppendPattern)
                 lst.append(rule)
             else:
                 ParserException(
                     "Found unknown statement type '{0}'.".format(
                         nestedStatement.__class__.__name__))
     else:
         ParserException("Found unknown statement type '{0}'.".format(
             ruleStatement.__class__.__name__))
Beispiel #3
0
 def _Evaluate(self, host, expr):  # mccabe:disable=MC0001
     if isinstance(expr, Identifier):
         try:
             return self._variables[
                 expr.
                 Name]  #self._variables only available via late binding
         except KeyError as ex:
             raise ParserException("Identifier '{0}' not found.".format(
                 expr.Name)) from ex
     elif isinstance(expr, StringLiteral):
         return expr.Value
     elif isinstance(expr, IntegerLiteral):
         return expr.Value
     elif isinstance(expr, ExistsFunction):
         path = self._EvaluatePath(host, expr.Expression)
         return (self._rootDirectory / path).exists()
     elif isinstance(expr, ListConstructorExpression):
         return [self._Evaluate(host, item) for item in expr.List]
     elif isinstance(expr, NotExpression):
         return not self._Evaluate(host, expr.Child)
     elif isinstance(expr, InExpression):
         return self._Evaluate(host, expr.LeftChild) in self._Evaluate(
             host, expr.RightChild)
     elif isinstance(expr, NotInExpression):
         return self._Evaluate(host, expr.LeftChild) not in self._Evaluate(
             host, expr.RightChild)
     elif isinstance(expr, AndExpression):
         return self._Evaluate(host, expr.LeftChild) and self._Evaluate(
             host, expr.RightChild)
     elif isinstance(expr, OrExpression):
         return self._Evaluate(host, expr.LeftChild) or self._Evaluate(
             host, expr.RightChild)
     elif isinstance(expr, XorExpression):
         l = self._Evaluate(host, expr.LeftChild)
         r = self._Evaluate(host, expr.RightChild)
         return (not l and r) or (l and not r)
     elif isinstance(expr, EqualExpression):
         return self._Evaluate(host, expr.LeftChild) == self._Evaluate(
             host, expr.RightChild)
     elif isinstance(expr, UnequalExpression):
         return self._Evaluate(host, expr.LeftChild) != self._Evaluate(
             host, expr.RightChild)
     elif isinstance(expr, LessThanExpression):
         return self._Evaluate(host, expr.LeftChild) < self._Evaluate(
             host, expr.RightChild)
     elif isinstance(expr, LessThanEqualExpression):
         return self._Evaluate(host, expr.LeftChild) <= self._Evaluate(
             host, expr.RightChild)
     elif isinstance(expr, GreaterThanExpression):
         return self._Evaluate(host, expr.LeftChild) > self._Evaluate(
             host, expr.RightChild)
     elif isinstance(expr, GreaterThanEqualExpression):
         return self._Evaluate(host, expr.LeftChild) >= self._Evaluate(
             host, expr.RightChild)
     else:
         raise ParserException("Unsupported expression type '{0!s}'".format(
             type(expr)))
Beispiel #4
0
 def _Resolve(self):
     # print("Resolving {0}".format(str(self._file)))
     for stmt in self._document.Statements:
         if isinstance(stmt, PreProcessRulesStatement):
             for ruleStatement in stmt.Statements:
                 self._ResolveRule(ruleStatement, self._preProcessRules)
         elif isinstance(stmt, PostProcessRulesStatement):
             for ruleStatement in stmt.Statements:
                 self._ResolveRule(ruleStatement, self._postProcessRules)
         else:
             ParserException("Found unknown statement type '{0}'.".format(
                 stmt.__class__.__name__))
Beispiel #5
0
    def _Resolve(self, host, statements=None):  # mccabe:disable=MC0001
        if (statements is None):
            statements = self._document.Statements

        for stmt in statements:
            if isinstance(stmt, VHDLStatement):
                path = self._EvaluatePath(host, stmt.PathExpression)
                file = self._rootDirectory / path
                vhdlSrcFile = self._classVHDLSourceFile(file, stmt.LibraryName)
                self._files.append(vhdlSrcFile)
            elif isinstance(stmt, VerilogStatement):
                path = self._EvaluatePath(host, stmt.PathExpression)
                file = self._rootDirectory / path
                verilogSrcFile = self._classVerilogSourceFile(file)
                self._files.append(verilogSrcFile)
            elif isinstance(stmt, CocotbStatement):
                path = self._EvaluatePath(host, stmt.PathExpression)
                file = self._rootDirectory / path
                cocotbSrcFile = self._classCocotbSourceFile(file)
                self._files.append(cocotbSrcFile)
            elif isinstance(stmt, LDCStatement):
                path = self._EvaluatePath(host, stmt.PathExpression)
                file = self._rootDirectory / path
                ldcSrcFile = self._classLDCSourceFile(file)
                self._files.append(ldcSrcFile)
            elif isinstance(stmt, SDCStatement):
                path = self._EvaluatePath(host, stmt.PathExpression)
                file = self._rootDirectory / path
                sdcSrcFile = self._classSDCSourceFile(file)
                self._files.append(sdcSrcFile)
            elif isinstance(stmt, UCFStatement):
                path = self._EvaluatePath(host, stmt.PathExpression)
                file = self._rootDirectory / path
                ucfSrcFile = self._classUCFSourceFile(file)
                self._files.append(ucfSrcFile)
            elif isinstance(stmt, XDCStatement):
                path = self._EvaluatePath(host, stmt.PathExpression)
                file = self._rootDirectory / path
                xdcSrcFile = self._classXDCSourceFile(file)
                self._files.append(xdcSrcFile)
            elif isinstance(stmt, IncludeStatement):
                # add the include file to the fileset
                path = self._EvaluatePath(host, stmt.PathExpression)
                file = self._rootDirectory / path
                includeFile = self._classFileListFile(
                    file
                )  #self._classFileListFile only available via late binding
                self._fileSet.AddFile(
                    includeFile
                )  #self._fileSet only available via late binding
                includeFile.Parse(host)

                self._includes.append(includeFile)
                for srcFile in includeFile.Files:
                    self._files.append(srcFile)
                for lib in includeFile.Libraries:
                    self._libraries.append(lib)
                for warn in includeFile.Warnings:
                    self._warnings.append(warn)
            elif isinstance(stmt, LibraryStatement):
                path = self._EvaluatePath(host, stmt.PathExpression)
                lib = self._rootDirectory / path
                vhdlLibRef = VHDLLibraryReference(stmt.Library, lib)
                self._libraries.append(vhdlLibRef)
            elif isinstance(stmt, PathStatement):
                path = self._EvaluatePath(host, stmt.PathExpression)
                self._variables[stmt.Variable] = path
            elif isinstance(stmt, IfElseIfElseStatement):
                exprValue = self._Evaluate(host, stmt.IfClause.Expression)
                if (exprValue is True):
                    self._Resolve(host, stmt.IfClause.Statements)
                elif (stmt.ElseIfClauses is not None):
                    for elseif in stmt.ElseIfClauses:
                        exprValue = self._Evaluate(host, elseif.Expression)
                        if (exprValue is True):
                            self._Resolve(host, elseif.Statements)
                            break
                if ((exprValue is False) and (stmt.ElseClause is not None)):
                    self._Resolve(host, stmt.ElseClause.Statements)
            elif isinstance(stmt, ReportStatement):
                self._warnings.append("WARNING: {0}".format(stmt.Message))
            else:
                ParserException("Found unknown statement type '{0!s}'.".format(
                    type(stmt)))