Ejemplo n.º 1
0
        public override void SetMemberContainingTypeDeclaration(ITypeDeclarationMember member)
        {
            TypedefDeclaration /*?*/ typedef = member as TypedefDeclaration;

            if (typedef != null)
            {
                typedef.SetContainingTypeDeclaration(this);
                return;
            }
            FunctionDeclaration /*?*/ functionDeclaration = member as FunctionDeclaration;

            if (functionDeclaration != null)
            {
                functionDeclaration.SetContainingTypeDeclaration(this);
                return;
            }
            base.SetMemberContainingTypeDeclaration(member);
        }
Ejemplo n.º 2
0
        void ParseTypeDefinition(List<INamespaceDeclarationMember> members, List<ITypeDeclarationMember> globalMembers, TokenSet followers, bool isRecord)
        {
            var noSpecifiers = new Specifier[0];
              var name = this.ParseNameDeclaration(true);
              var loc = name.SourceLocation;
              var name0 = name.Name.Value;
              var mangledName = new VccNameDeclaration(this.GetNameFor("_vcc_math_type_" + name0), loc);

              var tpMembers = new List<ITypeDeclarationMember>();
              var strct = new VccStructDeclaration(mangledName, tpMembers, noSpecifiers, loc);
              var tp = new VccNamedTypeExpression(new VccSimpleName(mangledName, mangledName.SourceLocation));

              UpdateForwardDeclaration(members, strct);

              if (isRecord) {
            List<FieldDeclaration>/*?*/ savedSpecificationFields = this.currentSpecificationFields;
            List<TypeInvariant>/*?*/ savedTypeInvariants = this.currentTypeInvariants;
            this.currentSpecificationFields = null;
            this.currentTypeInvariants = null;
            SourceLocationBuilder sctx = this.GetSourceLocationBuilderForLastScannedToken();

            this.ParseRestOfTypeDeclaration(sctx, members, tp.Expression, tpMembers, followers);
            if (this.currentToken == Token.EndOfFile) {
              ISourceLocation errorLocation = this.scanner.SourceLocationOfLastScannedToken;
              this.HandleError(errorLocation, Error.MissingSemicolonAfterStruct, "end-of-file");
            }
            this.SkipTo(followers);
            this.AssociateTypeWithTypeContract(strct, this.currentSpecificationFields, this.currentTypeInvariants, this.InSpecCode);

            this.currentSpecificationFields = savedSpecificationFields;
            this.currentTypeInvariants = savedTypeInvariants;
              } else {
            strct.IsAbstractType = true;
            /*
            var fld = new FieldDefinition(new List<Specifier>(), 0, VccCompilationHelper.GetBigIntType(nameTable),
                                      new VccNameDeclaration(this.GetNameFor("_vcc_dummy"), loc), null, true, loc);
            tpMembers.Add(fld);
            */
              }

              var typedefDecl = new TypedefDeclaration(tp, name, loc);
              this.RegisterTypedef(name.Value, typedefDecl);
              globalMembers.Add(typedefDecl);
        }
Ejemplo n.º 3
0
        void ParseDataTypeDefinition(List<INamespaceDeclarationMember> members, List<ITypeDeclarationMember> globalMembers, TokenSet followers)
        {
            var noSpecifiers = new Specifier[0];
              var name = this.ParseNameDeclaration(true);
              var loc = name.SourceLocation;
              var mangledName = new VccNameDeclaration(this.GetNameFor("_vcc_math_type_" + name.Name.Value), loc);
              var ctornames = new List<FunctionDeclaration>();
              var strct = new VccDatatypeDeclaration(mangledName, new List<ITypeDeclarationMember>(), noSpecifiers, ctornames, loc);
              UpdateForwardDeclaration(members, strct);

              var tp = new VccNamedTypeExpression(new VccSimpleName(mangledName, mangledName.SourceLocation));

              var typedefDecl = new TypedefDeclaration(tp, name, loc);
              this.RegisterTypedef(name.Value, typedefDecl);
              globalMembers.Add(typedefDecl);

              this.Skip(Token.LeftBrace);

              for (; ; ) {
            SourceLocationBuilder scCtx = this.GetSourceLocationBuilderForLastScannedToken();
            if (this.currentToken != Token.Case)
            {
              this.Skip(this.currentToken == Token.RightBrace ? Token.RightBrace : Token.Case);
              break;
            }
            this.Skip(Token.Case);
            var fname = this.ParseNameDeclaration(true);
            var parmFollowers = followers | Token.RightBrace | Token.Case | Token.Semicolon;
            var parms0 = this.ParseParameterList(parmFollowers);
            this.Skip(Token.RightParenthesis);
            if (this.currentToken == Token.Semicolon)
              this.Skip(Token.Semicolon);
            bool acceptsExtraArguments;
            var parms1 = this.ConvertToParameterDeclarations(parms0, out acceptsExtraArguments);
            var specifiers = new[] { this.CreateAttribute("_vcc_internal__is_datatype_option", "", scCtx) };
            var fdecl = new FunctionDeclaration(acceptsExtraArguments,
                        specifiers, false, CallingConvention.C, TypeMemberVisibility.Public,
                        tp, fname, null, parms1, true, null, scCtx
                    );
            globalMembers.Add(fdecl);
            ctornames.Add(fdecl);
              }

              if (ctornames.Count == 0)
            this.HandleError(Error.EmptySwitch); //TODO use proper error
        }