/*ident "@(#)cls4:src/template.c 1.30" */
/*******************************************************************************
C++ source for the C++ Language System, Release 3.0. This product
is a new release of the original cfront developed in the computer
science research center of AT&T Bell Laboratories.
Copyright (c) 1991 AT&T and UNIX System Laboratories, Inc.
Copyright (c) 1984, 1989, 1990 AT&T. All Rights Reserved.
THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE of AT&T and UNIX System
Laboratories, Inc. The copyright notice above does not evidence
any actual or intended publication of such source code.
*******************************************************************************/
/******************************************************************************
* Copyright (c) 1989 by Object Design, Inc., Burlington, Mass.
* All rights reserved.
*******************************************************************************/
/*******************************************************************
* template.c
*
* TBD
*
* 1) The template copying process could probably be speeded up
* substantially, by only placing "graph-like" nodes in the hash
* table. The current implementation plays it safe, and places
* all nodes in the hash table.
*
* 2) remove `$' in lex.c
*
* 3) Add something to lalex to handle x<y<int>>. Currently parsed
* as a right shift rather than nested template instance.
*********************************************************************/
#include "tree_copy.h"
#include "cfront.h"
#include <string.h>
#include "template.h"
#include <stdlib.h>
#include <ctype.h>
/*
* in string.h on ansi/plan9
* #include <memory.h>
*/
#include "hash.h"
extern int bound; // is not mentioned in the header file
bit tempdcl;
Ptempl_inst dummyinst=0;
Ptempl_inst curr_inst=0;
Pfunct_inst fdummyinst=0;
Pfunct_inst fcurr_inst=0;
static bit notinstflag=0;
//static bit matchflag=0;
templ_nest check_bound_type = not_set;
Ptable bound_expr_tbl;
const int max_string_size = 1024;
const int default_copy_hash_size = 1000;
const int MAX_INST_DEPTH = 8; // maximum instantiations at one time
// static data member definitions
Pfunt templ_compilation::f_list=0;
Pbase_inst basic_inst::head=0;
Ptempl templ_compilation::list=0;
Pcons templ_compilation::last_cons=0;
Pcons templ_compilation::last_friend_cons=0;
Pcons templ_compilation::templ_refs=0;
Pcons templ_compilation::friend_templ_refs=0;
Ptstate templ_compilation::save_templ=0;
Ptempl_base templ_compilation::parsed_template=0;
Pfunt templ_compilation::f_owner=0;
Ptempl templ_compilation::owner=0;
Plist templ_compilation::param_end=0;
Plist templ_compilation::params=0;
// The canonical template compilation instance.
templ_compilation *templp;
Ptable templ_compilation::templates;
Ptype templ_compilation::any_type = ::any_type;
// Save and restore global state around a template instantiation
void
state::save() {
Cdcl = ::Cdcl;
Cstmt = ::Cstmt;
curloc = ::curloc;
curr_file = ::curr_file;
curr_expr = ::curr_expr;
curr_icall = ::curr_icall;
curr_loop = ::curr_loop;
curr_block = ::curr_block;
curr_switch = ::curr_switch;
bound = ::bound ;
inline_restr = ::inline_restr;
last_line = ::last_line;
no_of_badcall = ::no_of_badcall;
no_of_undcl = ::no_of_undcl;
badcall = ::badcall;
undcl = ::undcl;
}
void
state::restore() {
::Cdcl = Cdcl;
::Cstmt = Cstmt;
::curloc = curloc;
::curr_file = curr_file;
::curr_expr = curr_expr;
::curr_icall = curr_icall;
::curr_loop = curr_loop;
::curr_block = curr_block;
::curr_switch = curr_switch;
::bound = bound;
::inline_restr = inline_restr;
::last_line = last_line;
::no_of_badcall = no_of_badcall;
::no_of_undcl = no_of_undcl;
::badcall = badcall;
::undcl = undcl;
}
void
state::init() {
::bound = 0;
::inline_restr = 0;
::no_of_badcall = ::no_of_undcl = 0;
::undcl = ::badcall = NULL;
// lastline needs to be initialized probaly via a call to putline
}
bit
basetype::parametrized_class() {
return ((base == COBJ) &&
Ptclass(Pbase(this)->b_name->tp)->class_base==UNINSTANTIATED);
}
bit
classdef::parametrized_class() {
return (class_base == UNINSTANTIATED);
}
Templ_type
get_class_base(Pbase b) {
if (b->base != COBJ)
error('i',"::get_class_base: badAT(%k) cobjX",b->base);
return Ptclass(Pbase(b)->b_name->tp)->class_base ;
}
Templ_type
get_templ_base(Pbase b) {
if (b->base != COBJ)
error('i',"::get_templ_base: badAT(%k) cobjX",b->base);
return Pclass(Pbase(b)->b_name->tp)->templ_base;
}
Ptclass
get_template_class(Pbase b) {
Templ_type t = get_class_base(b) ;
if (! ((t==INSTANTIATED) || (t==UNINSTANTIATED)))
error ('i', "C is not aYC");
return Ptclass(Pbase(b)->b_name->tp);
}
Ptempl_inst
get_templ_inst(Pbase b) {
return (get_template_class(b))->inst;
}
static bit
same_class_templ(Pclass c1, Pclass c2)
{
// error('d',"same_class_templ: c1 %s c2 %s c1 %d c2 %d", c1->string, c2->string, c1->class_base, c2->class_base);
if (c1 == c2) return true;
if ((c1->class_base == INSTANTIATED) &&
(c2->class_base == UNINSTANTIATED) &&
(Ptclass(c1)->inst->def== Ptclass(c2)->inst->def))
return true;
if ((c2->class_base == INSTANTIATED) &&
(c1->class_base == UNINSTANTIATED) &&
(Ptclass(c1)->inst->def== Ptclass(c2)->inst->def))
return true;
return false;
}
bit
classdef::same_class(Pclass pc,int access)
/* Predicate to determine whether two classes are indeed the same.
* cfront normally relies on pointer identity, however, this test
* is insufficient when parametrized class instantiationa are involved,
* since there are potentially many instances of a COBJ and CLASS
* for a given instantiation.
*
* it would seem reasonable to always have the occurrence of
* an UNINSTANTIATED and INSTANTIATED instance be checked;
* this occurs, for example, in
* template<class T> class Tag{};
* template<class T> struct Shrub {
* struct Link { Link* next; };
* int advance(Tag<T>&); // UNINSTANTIATED
* };
*
* void f() {
* Shrub<short> s; Tag<short> t;
* s.advance(t); } // INSTANTIATED -- same class!
*
* however, it seems that same_class also determines whether or not
* an instantiation needs to be done??? and so currently making this
* a blanket check causes certain classes under certain conditions
* not to be instantiated -- if this is truly the case, this should
* be broken into two functions
*/
{
// error('d',"%t->same_class(%t, %d)",this,pc,access);
if (this == 0 || pc == 0 ) return false;
if (this == pc) return true;
if (class_base == VANILLA &&
class_base == pc->class_base &&
in_class && pc->in_class )
{
if (in_class == pc->in_class)
return true;
if (nested_sig &&
strcmp(nested_sig,pc->nested_sig)==0)
return true;
return false;
}
Templ_type this_base = this->class_base;
Templ_type pc_base = pc->class_base;
if ((this_base == CL_TEMPLATE) &&
(pc_base == INSTANTIATED) &&
(Ptclass(pc)->inst->def_basetype()->b_name->tp==this))
return true;
// The inverse symmetric test
if ((pc_base == CL_TEMPLATE) &&
(this_base == INSTANTIATED) &&
(Ptclass(this)->inst->def_basetype()->b_name->tp==pc))
return true;
// Check whether the templates were determined to be
// identical after instantiation.
if ((pc_base == INSTANTIATED) &&
(this_base == INSTANTIATED) &&
(strcmp(pc->string,string)==0 ||
(Ptclass(this)->inst->same(Ptclass(pc)->inst))))
return true;
if (access == 0) return false;
// change to treatment of friend instantiation
// now makes this a possibility
if (this_base == INSTANTIATED &&
pc_base == UNINSTANTIATED) {
char *str = Ptclass(this)->inst->def->namep->string;
// error('d',"same_class: this: %
没有合适的资源?快使用搜索试试~ 我知道了~
一个c++转c的工具(cfront源码)
5星 · 超过95%的资源 需积分: 50 374 下载量 146 浏览量
2011-12-29
14:50:24
上传
评论 8
收藏 1.73MB TGZ 举报
温馨提示
共582个文件
h:254个
c:216个
3:23个
一个c++转c的工具(cfront源码),满足那些源码饿鬼好奇心
资源详情
资源评论
资源推荐
收起资源包目录
一个c++转c的工具(cfront源码) (582个子文件)
c++filt.1 1KB
16 0B
24 0B
task.3 31KB
ios.3 20KB
queue.3 15KB
sbuf.prot.3 15KB
istream.3 13KB
ostream.3 10KB
sbuf.pub.3 9KB
IOS.INTRO.3 8KB
filebuf.3 7KB
fstream.3 7KB
manip.3 5KB
ssbuf.3 5KB
tasksim.3 5KB
strstream.3 5KB
interrupt.3 4KB
cplxerr.3 3KB
TASK.INTRO.3 3KB
cplxops.3 3KB
CPLX.INTRO.3 2KB
cplxexp.3 2KB
cartpol.3 2KB
cplxtrig.3 2KB
stdiobuf.3 1KB
fudge.c.386 8KB
swap.s.386 7KB
fudge.c.3b 13KB
swap.s.3b 5KB
fudge.c.68k 7KB
swap.s.68k 7KB
8 0B
Bits.bobf 28KB
build 7KB
template.c 123KB
template.c 123KB
dcl3.c 66KB
dcl3.c 66KB
ptlink.c 63KB
simpl2.c 62KB
simpl2.c 62KB
dcl4.c 59KB
dcl4.c 59KB
expr3.c 58KB
expr3.c 58KB
yacc.c 55KB
yacc.c 55KB
expr2.c 54KB
expr2.c 54KB
expr.c 53KB
expr.c 53KB
norm.c 52KB
norm.c 52KB
print2.c 48KB
print2.c 48KB
dcl.c 47KB
dcl.c 47KB
find.c 45KB
find.c 45KB
lalex.c 45KB
lalex.c 45KB
dcl2.c 31KB
dcl2.c 31KB
simpl.c 30KB
simpl.c 30KB
tree_walk.c 30KB
tree_walk.c 30KB
lex.c 28KB
lex.c 28KB
dem.c 25KB
expand.c 24KB
expand.c 24KB
print.c 23KB
print.c 23KB
typ.c 21KB
typ.c 21KB
main.c 21KB
main.c 21KB
hw_stack.c 18KB
error.c 16KB
error.c 16KB
ptutil.c 14KB
ptcomp.c 13KB
filebuf.c 13KB
filebuf.c 13KB
task.c 13KB
typ2.c 11KB
typ2.c 11KB
task.c 11KB
table.c 10KB
table.c 10KB
_arr_map.c 9KB
_arr_map.c 9KB
out.c 9KB
out.c 9KB
doprint.c 8KB
demangle.c 8KB
args.c 8KB
alloc.c 8KB
共 582 条
- 1
- 2
- 3
- 4
- 5
- 6
yj_hnm
- 粉丝: 1
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论7