Exemplo n.º 1
0
 private void _Pointer(AmyDeclarator declarator)
 {
     CType qualifier = 0;
       bool ok = false;
       while (!ok) {
     Token token = input.ReadToken();
     switch ((TokenType)token.Type) {
       case TokenType.KeywordConst:
     qualifier |= CType.Const;
     break;
       case TokenType.KeywordRestrict:
     qualifier |= CType.Restrict;
     break;
       case TokenType.KeywordVolatile:
     qualifier |= CType.Volatile;
     break;
       //case TokenType.KeywordAtomic:
       //  qualifier |= CType.Atomic;
       //break;
       default:
     input.UnToken(token);
     ok = true;
     break;
     }
       }
       declarator.PushPointer(qualifier);
 }
Exemplo n.º 2
0
        private AmyDeclarator _Declarator(AmyType type)
        {
            AmyDeclarator declarator = new AmyDeclarator(type);
              for (; ; ) {
            Token token = input.ReadToken();
            switch ((TokenType)token.Type) {
              case TokenType.Star:
            _Pointer(declarator);
            break;

              case TokenType.Identifier:
            declarator.Alias = token.Litteral;
            // Console.WriteLine("Declare " + declarator);
            _DeclaratorDeco(declarator);
            return declarator;

              case TokenType.OpenParenthesis:
            // FIXME What if there is no IDENTIFIER !?
            // FIXME avoid recursivity
            AmyDeclarator refer = _Declarator(type);
            token = input.ReadToken();
            if (token.Type != (int)TokenType.CloseParenthesis)
              ErrorReport.Error("Unexpected token");

            _DeclaratorDeco(refer);

            if (false) {
              // If type is unchanged
              // refer.PointerCount == 0 && refer,Paramters == 0
              return refer;
            } else {
              declarator.Alias = refer.Alias;
              refer.Alias = Anonyme();
              // CreateTypeWith refer (FunctionPointer!!)
              declarator.Type = declarator.Type.Refered(refer);
              return declarator;
            }

              case TokenType.OpenBraclet:
            input.UnToken(token);
            _DeclaratorDeco(declarator);
            return declarator;

              default:
            input.UnToken(token);
            return declarator;
            }
              }
        }
Exemplo n.º 3
0
        private void _DeclaratorDeco(AmyDeclarator declarator)
        {
            for (; ; ) {
            Token token = input.ReadToken();
            if (token.Type == (int)TokenType.OpenParenthesis) {
              for (; ; ) {
            // FIXME no storage
            AmyType type = _TypeDeclaration();
            if (type == null) {
              token = input.ReadToken();
              if (token.Type == (int)TokenType.Operator3Dot) {
                Console.WriteLine("Add unbounded param to " + declarator);
                token = input.ReadToken();
                if (token.Type != (int)TokenType.CloseParenthesis)
                  ErrorReport.Error("Unexpected");
                return;
              } else if (token.Type == (int)TokenType.CloseParenthesis)
                return;
              else {
                ErrorReport.Error("Unexpected");
              }
            }
            AmyDeclarator param = _Declarator(type);
            // param.Alias = token.Litteral;
            Console.WriteLine("Add param " + param + " to " + declarator);

            token = input.ReadToken();
            if (token.Type == (int)TokenType.CloseParenthesis)
              return;
            if (token.Type != (int)TokenType.Comma) {
              ErrorReport.Error("Unexpected");
              return;
            }
              }
            } else if (token.Type == (int)TokenType.OpenBraclet) {
              token = input.ReadToken();
              if (token.Type == (int)TokenType.CloseBraclet) {
            declarator.PushPointer(CType.Array);
              } else {
            while (token.Type != (int)TokenType.CloseBraclet)
              token = input.ReadToken();
            declarator.PushPointer(CType.Array);
            // FIXME read Array expression
              }
            } else {
              input.UnToken(token);
              return;
            }
              }
        }
Exemplo n.º 4
0
 public AmyType Refered(AmyDeclarator decl)
 {
     AmyType at = new AmyType(this.Storage, decl.Alias);
       // FIXME
       return at;
 }