diff dmd/Module.d @ 174:af724d3510d7

lot os toCBuffer methods implemented moved shared Type.* stuff into Global
author korDen
date Sun, 10 Oct 2010 03:47:23 +0400
parents 96c0fff6897d
children fa9a71a9f5a8
line wrap: on
line diff
--- a/dmd/Module.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Module.d	Sun Oct 10 03:47:23 2010 +0400
@@ -103,7 +103,7 @@
 	UNKNOWN	= -1,	/* unknown segment		*/
 }
 
-struct seg_data 
+struct seg_data
 {
     int              SDseg;		// omf file segment index
     targ_size_t		 SDoffset;	// starting offset for data
@@ -146,7 +146,7 @@
 	CFpsw	       = 0x40,	// we need the flags result after this instruction
 	CFopsize       = 0x80,	// prefix with operand size
 	CFaddrsize    = 0x100, 	// prefix with address size
-	CFds	      = 0x200,	// need DS override (not with es, ss, or cs )	
+	CFds	      = 0x200,	// need DS override (not with es, ss, or cs )
 	CFcs	      = 0x400,	// need CS override
 	CFfs	      = 0x800,	// need FS override
 	CFgs	= (CFcs | CFfs),	// need GS override
@@ -222,10 +222,10 @@
 	{
 		super(ident);
 		FileName objfilename;
-		
+
 		aimports = new Array();
 
-	    //writef("Module.Module(filename = '%s', ident = '%s')\n", filename, ident.toChars());
+	    //writefln("Module.Module(filename = '%s', ident = '%s')", filename, ident.toChars());
 		this.arg = filename;
 
 		FileName srcfilename = FileName.defaultExt(filename, global.mars_ext);
@@ -267,6 +267,7 @@
 
 		FileName symfilename = FileName.forceExt(filename, global.sym_ext);
 
+		//writeln(srcfilename.toChars());
 		srcfile = new File(srcfilename);
 
 		if (doDocComment) {
@@ -296,10 +297,9 @@
 		if (packages && packages.dim)
 		{
 			scope OutBuffer buf = new OutBuffer();
-			int i;
 
 			foreach (pid; packages)
-			{   
+			{
 				buf.writestring(pid.toChars());
 version (Windows)
 {
@@ -324,7 +324,7 @@
 		FileName fd  = FileName.forceExt(filename, global.mars_ext);
 		string sdi = fdi.toChars();
 		string sd  = fd.toChars();
-		
+
 		if (FileName.exists(sdi)) {
 			result = sdi;
 		} else if (FileName.exists(sd)) {
@@ -353,8 +353,10 @@
 			}
 		}
 
-		if (result)
+		if (result) {
+			writeln("loading ", result);
 			m.srcfile = new File(result);
+		}
 
 		if (global.params.verbose)
 		{
@@ -362,7 +364,7 @@
 			if (packages)
 			{
 				foreach (pid; packages)
-				{   
+				{
 					writef("%s.", pid.toChars());
 				}
 			}
@@ -383,7 +385,7 @@
 	{
 		assert(false);
 	}
-    
+
     override void toJsonBuffer(OutBuffer buf)
     {
 		buf.writestring("{\n");
@@ -417,27 +419,27 @@
 
 		buf.writestring("}\n");
 	}
-	
+
     override string kind()
 	{
 		return "module";
 	}
-	
+
     void setDocfile()	// set docfile member
 	{
 		assert(false);
 	}
-	
+
     void read(Loc loc)	// read file
 	{
-		//writef("Module.read('%s') file '%s'\n", toChars(), srcfile.toChars());
+		//writefln("Module.read('%s') file '%s'", toChars(), srcfile.toChars());
 		if (srcfile.read())
 		{
 			error(loc, "cannot read file '%s'", srcfile.toChars());
 			fatal();
 		}
 	}
-	
+
 version (IN_GCC) {
     void parse(bool dump_source = false)	// syntactic parse
 	{
@@ -487,7 +489,7 @@
 
 			dbuf.reserve(buflen / 4);
 			for (pu += bom; pu < pumax; pu++)
-			{  
+			{
 				uint u = le ? readlongLE(pu) : readlongBE(pu);
 				if (u & ~0x7F)
 				{
@@ -505,7 +507,7 @@
 			buf = cast(ubyte*) dbuf.extractData();
 			}
 			else
-			{   
+			{
 				// UTF-16LE (X86)
 				// Convert it to UTF-8
 				le = 1;
@@ -620,7 +622,7 @@
 		}
 
 version (IN_GCC) {
-		// dump utf-8 encoded source 
+		// dump utf-8 encoded source
 		if (dump_source)
 		{	// %% srcname could contain a path ...
 			d_gcc_dump_source(srcname, "utf-8", buf, buflen);
@@ -678,7 +680,7 @@
 			if (!Lexer.isValidIdentifier(this.ident.toChars()))
 				error("has non-identifier characters in filename, use module declaration instead");
 			}
-			
+
 			// Update global list of modules
 			if (!dst.insert(this))
 			{
@@ -697,7 +699,7 @@
 	override void importAll(Scope prevsc)
 	{
 		//writef("+Module.importAll(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
-	
+
 		if (scope_ !is null)
 			return;			// already done
 
@@ -707,7 +709,7 @@
 		 * Ignore prevsc.
 		 */
 		Scope sc = Scope.createGlobal(this);	// create root scope
-	
+
 		// Add import of "object" if this module isn't "object"
 		if (ident != Id.object)
 		{
@@ -726,7 +728,7 @@
 				s.addMember(null, sc.scopesym, 1);
 		}
 		// anything else should be run after addMember, so version/debug symbols are defined
-	
+
 		/* Set scope for the symbols so that if we forward reference
 		 * a symbol, it can possibly be resolved on the spot.
 		 * If this works out well, it can be extended to all modules
@@ -735,10 +737,10 @@
 		setScope(sc);		// remember module scope for semantic
 		foreach (Dsymbol s; members)
 			s.setScope(sc);
-	
+
 		foreach (Dsymbol s; members)
 			s.importAll(sc);
-	
+
 		sc = sc.pop();
 		sc.pop();		// 2 pops because Scope::createGlobal() created 2
 	}
@@ -775,7 +777,7 @@
 		// Add all symbols into module's symbol table
 		symtab = new DsymbolTable();
 		foreach(s; members)
-		{	
+		{
 			s.addMember(null, sc.scopesym, true);
 		}
 
@@ -790,7 +792,7 @@
 
 		// Pass 1 semantic routines: do public side of the definition
 		foreach (Dsymbol s; members)
-		{	
+		{
 			//writef("\tModule('%s'): '%s'.semantic()\n", toChars(), s.toChars());
 			s.semantic(sc);
 			runDeferredSemantic();
@@ -804,7 +806,7 @@
 		semanticRun = semanticstarted;
 		//printf("-Module.semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
 	}
-	
+
     void semantic2()	// pass 2 semantic analysis
 	{
 		auto deferred = global.deferred;
@@ -839,7 +841,7 @@
 		semanticRun = semanticstarted;
 		//printf("-Module.semantic2('%s'): parent = %p\n", toChars(), parent);
 	}
-	
+
     void semantic3()	// pass 3 semantic analysis
 	{
 		//printf("Module.semantic3('%s'): parent = %p\n", toChars(), parent);
@@ -856,7 +858,7 @@
 
 		// Pass 3 semantic routines: do initializers and function bodies
 		foreach(Dsymbol s; members)
-		{	
+		{
 			//printf("Module %s: %s.semantic3()\n", toChars(), s.toChars());
 			s.semantic3(sc);
 		}
@@ -865,7 +867,7 @@
 		sc.pop();
 		semanticRun = semanticstarted;
 	}
-	
+
     override void inlineScan()	// scan for functions to inline
 	{
 		if (semanticstarted >= 4)
@@ -880,7 +882,7 @@
 		//printf("Module = %p\n", sc.scopesym);
 
 		foreach(Dsymbol s; members)
-		{	
+		{
 			//if (global.params.verbose)
 				//printf("inline scan symbol %s\n", s.toChars());
 			s.inlineScan();
@@ -888,7 +890,7 @@
 
 		semanticRun = semanticstarted;
 	}
-	
+
     void setHdrfile()	// set hdrfile member
 	{
 		FileName hdrfilename;
@@ -901,7 +903,7 @@
 		else
 			arghdr = FileName.name(arg);
 		if (!FileName.absolute(arghdr))
-		{	
+		{
 			//FileName.ensurePathExists(global.params.hdrdir);
 			arghdr = FileName.combine(global.params.hdrdir, arghdr);
 		}
@@ -911,21 +913,21 @@
 			hdrfilename = FileName.forceExt(arghdr, global.hdr_ext);
 
 		if (hdrfilename.str == srcfile.name.str)
-		{   
+		{
 			error("Source file and 'header' file have same name '%s'", srcfile.name.str);
 			fatal();
 		}
 
 		hdrfile = new File(hdrfilename);
 	}
-	
+
 version (_DH) {
     void genhdrfile()  // generate D import file
 	{
 		assert(false);
 	}
 }
-	
+
 	/**************************************
 	 * Generate .obj file for Module.
 	 */
@@ -998,10 +1000,10 @@
 
 			covb = cast(uint*)GC.calloc(((numlines + 32) / 32) * (*covb).sizeof);
 		}
-		
+
 		foreach(Dsymbol member; members)
 			member.toObjFile(multiobj);
-		
+
 		if (global.params.cov)
 		{
 			/* Generate
@@ -1081,7 +1083,7 @@
 				cstate.CSpsymtab = &sctor.Sfunc.Flocsym;
 
 				for (int i = 0; i < ectorgates.dim; i++)
-				{	
+				{
 					StaticDtorDeclaration f = cast(StaticDtorDeclaration)ectorgates.data[i];
 
 					Symbol* s = f.vgate.toSymbol();
@@ -1188,27 +1190,27 @@
 				writefunc(ma);
 			}
 		}
-		
+
 
 static if (true) {
 		// Always generate module info, because of templates and -cov
 		if (1 || needModuleInfo())
 			genmoduleinfo();
 }
-		
+
 		obj_termfile();
 	}
-	
+
     void gensymfile()
 	{
 		assert(false);
 	}
-	
+
     void gendocfile()
 	{
 		assert(false);
 	}
-	
+
 	/**********************************
 	 * Determine if we need to generate an instance of ModuleInfo
 	 * for this Module.
@@ -1218,7 +1220,7 @@
     	// writef("needModuleInfo() %s, %d, %d\n", toChars(), needmoduleinfo, global.params.cov);
 		return needmoduleinfo || global.params.cov;
 	}
-	
+
     override Dsymbol search(Loc loc, Identifier ident, int flags)
 	{
 		/* Since modules can be circularly referenced,
@@ -1247,7 +1249,7 @@
 		}
 		return s;
 	}
-	
+
     void deleteObjFile()
 	{
 		if (global.params.obj)
@@ -1280,7 +1282,7 @@
 	    //printf("Module::addDeferredSemantic('%s')\n", s.toChars());
 	    deferred.push(cast(void*)s);
 	}
-	
+
 	/******************************************
 	 * Run semantic() on deferred symbols.
 	 */
@@ -1291,11 +1293,11 @@
 			return;
 		//if (deferred.dim) printf("+Module.runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim);
 		global.nested++;
-		
+
 		size_t len;
 
 		auto deferred = global.deferred;
-		
+
 		do
 		{
 			global.dprogress = 0;
@@ -1424,7 +1426,7 @@
 	{
 		assert(false);
 	}
-	
+
     elem* toEfilename()
 	{
 		elem* efilename;
@@ -1455,7 +1457,7 @@
 		efilename = el_var(sfilename);
 		return efilename;
 	}
-	
+
 	/**************************************
 	 * Generate elem that is a pointer to the module file name.
 	 */
@@ -1465,7 +1467,7 @@
 
 		// Get filename
 		if (needModuleInfo())
-		{   
+		{
 			/* Class ModuleInfo is defined in std.moduleinfo.
 			 * The first member is the name of it, char name[],
 			 * which will be at offset 8.
@@ -1516,7 +1518,7 @@
 		Symbol* msym = toSymbol();
 
 		//dumpSymbol(msym);
-		
+
 		uint offset;
 	version (DMDV2) {
 		uint sizeof_ModuleInfo = 18 * PTRSIZE;
@@ -1551,7 +1553,7 @@
 		if (global.moduleinfo)
 			dtxoff(&dt, global.moduleinfo.toVtblSymbol(), 0, TYM.TYnptr); // vtbl for ModuleInfo
 		else
-		{	
+		{
 			//printf("moduleinfo is null\n");
 			dtdword(&dt, 0);		// BUG: should be an assert()
 		}
@@ -1567,7 +1569,7 @@
 
 		//printf("members.dim = %d\n", members.dim);
 		foreach(Dsymbol member; members)
-		{	
+		{
 			//printf("\tmember '%s'\n", member.toChars());
 			member.addLocalClass(aclasses);
 		}
@@ -1575,7 +1577,7 @@
 		// importedModules[]
 		int aimports_dim = aimports.dim;
 		for (int i = 0; i < aimports.dim; i++)
-		{	
+		{
 			Module m = cast(Module)aimports.data[i];
 			if (!m.needModuleInfo())
 				aimports_dim--;
@@ -1637,11 +1639,11 @@
 		//////////////////////////////////////////////
 
 		for (int i = 0; i < aimports.dim; i++)
-		{	
+		{
 			Module m = cast(Module)aimports.data[i];
 
 			if (m.needModuleInfo())
-			{   
+			{
 				Symbol* s = m.toSymbol();
 
 				/* Weak references don't pull objects in from the library,