anchor.diff:  		asn1ct_gen:get_inner(Def)
   	end,
   
  -    case InnerType of
  -	#'Externaltypereference'{type=T} ->
  -	    emit({nl,"%%  attribute number ",TextPos," with type ",
  -		  T,nl});
  -	IT when is_tuple(IT) ->
  -	    emit({nl,"%%  attribute number ",TextPos," with type ",
  -		  element(2,IT),nl});
  -	_ ->
  -	    emit({nl,"%% attribute number ",TextPos," with type ",
  -		  InnerType,nl})
  -    end,
  -
  -    IsMandatoryAndPredefinedTableC =
  -	fun(noext,mandatory,{"got objfun through args","ObjFun"}) ->
  -		true;
  -	   (_,_,{"got objfun through args","ObjFun"}) ->
  -		false;
  -	   (_,_,_) ->
  -		true
  -	end,
  -    case {InnerType,IsMandatoryAndPredefinedTableC(Ext,Prop,DecInfObj)} of
  -%%	{typefield,_} when Ext == noext, Prop == mandatory ->
  -	{{typefield,_},true}  ->
  -	    %% DecInfObj /= {"got objfun through args","ObjFun"} |
  -	    %% (DecInfObj == {"got objfun through args","ObjFun"} &
  -	    %% Ext == noext & Prop == mandatory)
  -	    asn1ct_name:new(term),
  -	    asn1ct_name:new(tmpterm),
  -	    emit({"{",{curr,tmpterm},", ",{next,bytes},"} = "});
  +    DispType = case InnerType of
  +		   #'Externaltypereference'{type=T} -> T;
  +		   IT when is_tuple(IT) -> element(2,IT);
  +		   _ -> InnerType
  +	       end,
  +    Comment = fun(St) ->
  +		      emit([nl,"%% attribute number ",TextPos,
  +			    " with type ",DispType,nl]),
  +		      St
  +	      end,
  +
  +    Preamble =
  +	case {InnerType,is_mandatory_predef_tab_c(Ext, Prop, DecInfObj)} of
  +	    {{typefield,_},true}  ->
  +		%% DecInfObj /= {"got objfun through args","ObjFun"} |
  +		%% (DecInfObj == {"got objfun through args","ObjFun"} &
  +		%% Ext == noext & Prop == mandatory)
  +		fun(St) ->
  +			asn1ct_name:new(term),
  +			asn1ct_name:new(tmpterm),
  +			emit(["{",{curr,tmpterm},", ",{next,bytes},"} = "]),
  +			St
  +		end;
   	%%{objectfield,_,_} when Ext == noext, Prop == mandatory ->
  -	{{objectfield,_,_},true} ->
  -	    asn1ct_name:new(term),
  -	    asn1ct_name:new(tmpterm),
  -	    emit({"{",{curr,tmpterm},", ",{next,bytes},"} = "});
  +	    {{objectfield,_,_},true} ->
  +		fun(St) ->
  +			asn1ct_name:new(term),
  +			asn1ct_name:new(tmpterm),
  +			emit(["{",{curr,tmpterm},", ",{next,bytes},"} = "]),
  +			St
  +		end;
   	_ ->
   	    case Type of
   		#type{def=#'SEQUENCE'{
   			extaddgroup=Number1,
   			components=ExtGroupCompList1}} when is_integer(Number1)->
  -		    emit({"{{_,"}),
  -		    emit_extaddgroupTerms(term,ExtGroupCompList1),
  -		    emit({"}"});
  +		    fun(St) ->
  +			    emit(["{{_,"]),
  +			    emit_extaddgroupTerms(term,ExtGroupCompList1),
  +			    emit(["}"]),
  +			    emit([",",{next,bytes},"} = "]),
  +			    St
  +		    end;
   		_ ->
  -		    asn1ct_name:new(term),
  -		    emit({"{",{curr,term}})
  -	    end,
  -	    emit({",",{next,bytes},"} = "})
  -    end,
  -
  -    case {Ext,Prop,is_optimized(Erule)} of
  -	{noext,mandatory,_} -> ok; % generate nothing
  -	{noext,_,_} -> %% OPTIONAL or DEFAULT
  -	    OptPos = get_optionality_pos(TextPos,OptTable),
  -	    Element = io_lib:format("Opt band (1 bsl ~w)",[NumberOfOptionals - OptPos]),
  -	    emit(["case ",Element," of",nl]),
  -	    emit(["  _Opt",TextPos," when _Opt",TextPos," > 0 ->"]);
  +		    fun(St) ->
  +			    asn1ct_name:new(term),
  +			    emit(["{",{curr,term}]),
  +			    emit([",",{next,bytes},"} = "]),
  +			    St
  +		    end
  +	    end
  +	end,
  +
  +    OptOrDef =
  +	case {Ext,Prop,is_optimized(Erule)} of
  +	    {noext,mandatory,_} ->
  +		ignore;
  +	    {noext,_,_} -> %% OPTIONAL or DEFAULT
  +		OptPos = get_optionality_pos(TextPos, OptTable),
  +		Element = io_lib:format("Opt band (1 bsl ~w)",
  +					[NumberOfOptionals - OptPos]),
  +		fun(St) ->
  +			emit(["case ",Element," of",nl]),
  +			emit(["  _Opt",TextPos," when _Opt",TextPos," > 0 ->"]),
  +			St
  +		end;
   	{_,_,false} -> %% extension element, not bitstring
  -	    emit(["case Extensions of",nl]),
  -	    emit(["  _ when size(Extensions) >= ",Pos,",element(",Pos,",Extensions) == 1 ->",nl]);
  -	_ ->
  -	    emit(["case Extensions of",nl]),
  -	    emit(["  <<_:",Pos-1,",1:1,_/bitstring>> when bit_size(Extensions) >= ",Pos," ->",nl])
  -    end,
  -    put(component_type,{true,C}),
  -    {TermVar,BytesVar} = gen_dec_line(Erule,TopType,Cname,Type,Tpos,DecInfObj,Ext,Prop),
  -    erase(component_type),
  -    case {Ext,Prop} of
  -	{noext,mandatory} -> true; % generate nothing
  -	{noext,_} ->
  -	    emit([";",nl,"0 ->"]),
  -	    emit(["{"]),
  -	    gen_dec_component_no_val(Ext,Prop),
  -	    emit({",",{curr,bytes},"}",nl}),
  -	    emit([nl,"end"]);
  -	_ ->
  -	    emit([";",nl,"_  ->",nl]),
  -	    emit(["{"]),
  -	    case Type of
  -		#type{def=#'SEQUENCE'{
  -			extaddgroup=Number2,
  -			components=ExtGroupCompList2}} when is_integer(Number2)->
  -		    emit({"{extAddGroup,"}),
  -		    gen_dec_extaddGroup_no_val(Ext,ExtGroupCompList2),
  -		    emit({"}"});
  -		_ ->
  -		    gen_dec_component_no_val(Ext,Prop)
  -	    end,
  -	    emit({",",{curr,bytes},"}",nl}),
  -	    emit([nl,"end"])
  -    end,    
  -    asn1ct_name:new(bytes),
  -    case Rest of
  -	[] ->
  -	    {Tpos+1,AccTerm++TermVar,AccBytes++BytesVar};
  -	_ ->
  -	    emit({com,nl}),
  -	    gen_dec_components_call1(Erule,TopType,Rest,Tpos+1,OptTable,
  -				     "",DecInfObj,Ext, AccTerm++TermVar,
  -				     AccBytes++BytesVar,NumberOfOptionals)
  -    end;
  -
  -gen_dec_components_call1(_,_TopType,[],Pos,_OptTable,_,_,_,AccTerm,AccBytes,_NumberOfOptionals) ->
  -    {Pos,AccTerm,AccBytes}.
  +		fun(St) ->
  +			emit(["case Extensions of",nl]),
  +			emit(["  _ when size(Extensions) >= ",Pos,
  +			      ",element(",Pos,",Extensions) == 1 ->",nl]),
  +			St
  +		end;
  +	    _ ->
  +		fun(St) ->
  +			emit(["case Extensions of",nl]),
  +			emit(["  <<_:",Pos-1,",1:1,_/bitstring>> "
  +			      "when bit_size(Extensions) >= ",Pos," ->",nl]),
  +			St
  +		end
  +	end,
  +    Lines = gen_dec_line_imm(Erule, TopType, Comp, Tpos, DecInfObj, Ext),
  +    Postamble =
  +	case {Ext,Prop} of
  +	    {noext,mandatory} ->
  +		ignore;
  +	    {noext,_} ->
  +		fun(St) ->
  +			emit([";",nl,"0 ->"]),
  +			emit(["{"]),
  +			gen_dec_component_no_val(Ext,Prop),
  +			emit({",",{curr,bytes},"}",nl}),
  +			emit([nl,"end"]),
  +			St
  +		end;
  +	    _ ->
  +		fun(St) ->
  +			emit([";",nl,"_  ->",nl]),
  +			emit(["{"]),
  +			case Type of
  +			    #type{def=#'SEQUENCE'{
  +					 extaddgroup=Number2,
  +					 components=ExtGroupCompList2}}
  +			      when is_integer(Number2)->
  +				emit({"{extAddGroup,"}),
  +				gen_dec_extaddGroup_no_val(Ext,ExtGroupCompList2),
  +				emit({"}"});
  +			    _ ->
  +				gen_dec_component_no_val(Ext, Prop)
  +			end,
  +			emit({",",{curr,bytes},"}",nl}),
  +			emit([nl,"end"]),
  +			St
  +		end
  +	end,
  +    AdvBuffer = {ignore,fun(St) ->
  +				asn1ct_name:new(bytes),
  +				St
  +			end},
  +    [{group,[Comment,Preamble,OptOrDef|Lines]++[Postamble,AdvBuffer]}].
  +
  +is_mandatory_predef_tab_c(noext, mandatory,
  +			  {"got objfun through args","ObjFun"}) ->
  +    true;
  +is_mandatory_predef_tab_c(_, _, {"got objfun through args","ObjFun"}) ->
  +    false;
  +is_mandatory_predef_tab_c(_,_,_) ->
  +    true.
   
   gen_dec_extaddGroup_no_val(Ext,[#'ComponentType'{prop=Prop}])->
       gen_dec_component_no_val(Ext,Prop),
  
positive.code: 			{false,false,false}
  		end
  	end,
  %%    NewCompList = wrap_compList(CompList),
      {AccTerm,AccBytes} =
  	gen_dec_components_call(Erules,Typename,CompList,MaybeComma2,DecObjInf,Ext,length(Optionals)),
      case asn1ct_name:all(term) of
  	[] -> emit(MaybeComma2); % no components at all
  	_ -> emit({com,nl})
      end,
      case {AccTerm,AccBytes} of
  	{[],[]} ->
  	    ok;
  
negative.code: 	    mkvlist(textual_order(to_encoding_order(CompList),asn1ct_name:all(term))),
  	    emit("},")
      end,
      emit({{curr,bytes},"}"}).
  
  textual_order([#'ComponentType'{textual_order=undefined}|_],TermList) ->
      TermList;
  