# Path: AOR/Declaration.py
# class Type(BasicRepr):
# 
#     # Constructor. Parameters:
#     #
#     # sType -- The basic type
#     #
#     # sType2 -- Used for double precision
#     #
#     def __init__(self, sType, sType2=None):
#         self.sType  = sType
#         self.sType2 = sType2
#         self.sStar  = None
#         self.len    = None
#         self.lKind  = []
#     # --------------------------------------------------------------------------
#     def bIsType(self, sType):
#         return string.upper(self.sType)==string.upper(sType)
#     # --------------------------------------------------------------------------
#     def SetStar(self, sStar): self.sStar = sStar
#     # --------------------------------------------------------------------------
#     def SetLen(self, l) : self.lKind = [l]
#     # --------------------------------------------------------------------------
#     def SetParOpen(self, sParOpen): self.lKind.append(sParOpen)
#     # --------------------------------------------------------------------------
#     def SetParClose(self, sParClose): self.lKind.append(sParClose)
#     # --------------------------------------------------------------------------
#     # Adds the kind information: Either '(5)', or '(kind=5)'
#     def AddKindOrLen(self, sKeyword=None, sEqual=None, obj=None, sComma=None):
#         if sKeyword:
#             self.lKind.append( (sKeyword, sEqual, obj) )
#         else:
#             self.lKind.append(obj)
#         if sComma: self.lKind.append(sComma)
#     # --------------------------------------------------------------------------
#     # The tuple t is either (keyword,'=',exp) or a single exp obj. This will
#     # return a tuple where the keyword is handled by the stylesheet
#     def HandleKeywords(self, t, stylesheet, l):
#         if type(t)==TupleType:
#             l.append(stylesheet.sKeyword(t[0]))
#             l.append(t[1])
#             stylesheet.ToList(t[2], l)
#         else:
#             stylesheet.ToList(t, l)
#     # --------------------------------------------------------------------------
#     # Convert a basic type into a list.
#     def ToList(self, stylesheet, l):
#         l.append(stylesheet.sKeyword(self.sType))
#         if self.sType2:
#             l.append(stylesheet.sKeyword(self.sType2))
#         if self.sStar:
#             l.append(self.sStar)
# 
#         if not self.lKind:
#             return
#         # E.g. integer *8
#         if len(self.lKind)==1:
#             stylesheet.ToList(self.lKind[0], l)
#         # E.g. (4)  or (KIND=4), since ('KIND','=',4) is a single tuple.
#         elif len(self.lKind)==3:
#             l.append(self.lKind[0])                             # (
#             self.HandleKeywords(self.lKind[1], stylesheet, l)   # 3
#             l.append(self.lKind[2])                             # )
#         # E.g. (3, len=5)
#         else:
#             l.append(self.lKind[0])                             # (
#             self.HandleKeywords(self.lKind[1],stylesheet, l)    # 4
#             l.append(self.lKind[2])                             # ,
#             self.HandleKeywords(self.lKind[3], stylesheet, l)   # 5 
#             l.append(self.lKind[4], nIndentNext=1)              # )


import string
from   Variable        import Variable, VariableData
from   AOR.Declaration import Type
    from AOR.Test.VariablesTest import RunTest
    def SetImplicit(self, type, sFrom, sTo=None):
        if not sTo: sTo=sFrom
        # If this is the first implicit statement, a dictionary for the type
        # mapping is created:
        if not self.dImplicit:
            self.dImplit={}
            for i in 'ABCDEFGHOPQRSTUVWXYZ':
                self.dImplicit[i] = Type('REAL')
            for i in 'IJKLMN':
                self.dImplicit[i] = Type('INTEGER')
        # Now add the 
        sFrom = string.upper(sFrom[0])
        sTo   = string.upper(sTo[0]  )
        for i in range(ord(sFrom), ord(sTo)+1):
            self.dImplicit[chr(i)] = type
        # We now have to check if any variables have a wrong implicit
        # type set (e.g. arguments of a subroutine will have the default
        # implicit type set, since when the subroutine statement is parsed
        # no implicit statement is valid).
        for k,v in self.dVarsData.items():
            if v['undefined']:
                v['type']=self.GetImplicitType(`v`)
    # --------------------------------------------------------------------------
    def GetImplicitType(self, s):
        c = string.upper(s[0])
        if self.dImplicit:
            t = self.dImplicit.get(c, None)
            return t
        
        if c>="I" and c <="N":

# Path: AOR/Declaration.py
# class Type(BasicRepr):
# 
#     # Constructor. Parameters:
#     #
#     # sType -- The basic type
#     #
#     # sType2 -- Used for double precision
#     #
#     def __init__(self, sType, sType2=None):
#         self.sType  = sType
#         self.sType2 = sType2
#         self.sStar  = None
#         self.len    = None
#         self.lKind  = []
#     # --------------------------------------------------------------------------
#     def bIsType(self, sType):
#         return string.upper(self.sType)==string.upper(sType)
#     # --------------------------------------------------------------------------
#     def SetStar(self, sStar): self.sStar = sStar
#     # --------------------------------------------------------------------------
#     def SetLen(self, l) : self.lKind = [l]
#     # --------------------------------------------------------------------------
#     def SetParOpen(self, sParOpen): self.lKind.append(sParOpen)
#     # --------------------------------------------------------------------------
#     def SetParClose(self, sParClose): self.lKind.append(sParClose)
#     # --------------------------------------------------------------------------
#     # Adds the kind information: Either '(5)', or '(kind=5)'
#     def AddKindOrLen(self, sKeyword=None, sEqual=None, obj=None, sComma=None):
#         if sKeyword:
#             self.lKind.append( (sKeyword, sEqual, obj) )
#         else:
#             self.lKind.append(obj)
#         if sComma: self.lKind.append(sComma)
#     # --------------------------------------------------------------------------
#     # The tuple t is either (keyword,'=',exp) or a single exp obj. This will
#     # return a tuple where the keyword is handled by the stylesheet
#     def HandleKeywords(self, t, stylesheet, l):
#         if type(t)==TupleType:
#             l.append(stylesheet.sKeyword(t[0]))
#             l.append(t[1])
#             stylesheet.ToList(t[2], l)
#         else:
#             stylesheet.ToList(t, l)
#     # --------------------------------------------------------------------------
#     # Convert a basic type into a list.
#     def ToList(self, stylesheet, l):
#         l.append(stylesheet.sKeyword(self.sType))
#         if self.sType2:
#             l.append(stylesheet.sKeyword(self.sType2))
#         if self.sStar:
#             l.append(self.sStar)
# 
#         if not self.lKind:
#             return
#         # E.g. integer *8
#         if len(self.lKind)==1:
#             stylesheet.ToList(self.lKind[0], l)
#         # E.g. (4)  or (KIND=4), since ('KIND','=',4) is a single tuple.
#         elif len(self.lKind)==3:
#             l.append(self.lKind[0])                             # (
#             self.HandleKeywords(self.lKind[1], stylesheet, l)   # 3
#             l.append(self.lKind[2])                             # )
#         # E.g. (3, len=5)
#         else:
#             l.append(self.lKind[0])                             # (
#             self.HandleKeywords(self.lKind[1],stylesheet, l)    # 4
#             l.append(self.lKind[2])                             # ,
#             self.HandleKeywords(self.lKind[3], stylesheet, l)   # 5 
#             l.append(self.lKind[4], nIndentNext=1)              # )


# Path: AOR/Variables.py
import string
from   Variable        import Variable, VariableData
from   AOR.Declaration import Type
    from AOR.Test.VariablesTest import RunTest

    def SetImplicit(self, type, sFrom, sTo=None):
        if not sTo: sTo=sFrom
        # If this is the first implicit statement, a dictionary for the type
        # mapping is created:
        if not self.dImplicit:
            self.dImplit={}
            for i in 'ABCDEFGHOPQRSTUVWXYZ':
                self.dImplicit[i] = Type('REAL')
            for i in 'IJKLMN':
                self.dImplicit[i] = Type('INTEGER')
        # Now add the 
        sFrom = string.upper(sFrom[0])
        sTo   = string.upper(sTo[0]  )
        for i in range(ord(sFrom), ord(sTo)+1):
            self.dImplicit[chr(i)] = type
        # We now have to check if any variables have a wrong implicit
        # type set (e.g. arguments of a subroutine will have the default
        # implicit type set, since when the subroutine statement is parsed
        # no implicit statement is valid).
        for k,v in self.dVarsData.items():
            if v['undefined']:
                v['type']=self.GetImplicitType(`v`)
    # --------------------------------------------------------------------------
    def GetImplicitType(self, s):
        c = string.upper(s[0])
        if self.dImplicit:
            t = self.dImplicit.get(c, None)
            return t
        
        if c>="I" and c <="N":

            return Type('INTEGER')