diff dmd/StorageClassDeclaration.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children b7d29f613539
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/StorageClassDeclaration.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,124 @@
+module dmd.StorageClassDeclaration;
+
+import dmd.AttribDeclaration;
+import dmd.Array;
+import dmd.TOK;
+import dmd.Token;
+import dmd.Scope;
+import dmd.Dsymbol;
+import dmd.OutBuffer;
+import dmd.HdrGenState;
+import dmd.STC;
+
+class StorageClassDeclaration: AttribDeclaration
+{
+    STC stc;
+
+    this(STC stc, Array decl)
+	{
+		super(decl);
+		
+		this.stc = stc;
+	}
+	
+    Dsymbol syntaxCopy(Dsymbol s)
+	{
+		assert(false);
+	}
+	
+    void setScope(Scope sc)
+	{
+		if (decl)
+		{
+			STC scstc = sc.stc;
+
+			/* These sets of storage classes are mutually exclusive,
+			 * so choose the innermost or most recent one.
+			 */
+			if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest))
+				scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest);
+			if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared))
+				scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared);
+			if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest))
+				scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest);
+			if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls))
+				scstc &= ~(STC.STCgshared | STC.STCshared | STC.STCtls);
+			scstc |= stc;
+
+			setScopeNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign);
+		}
+	}
+	
+    void semantic(Scope sc)
+	{
+		if (decl)
+		{
+			STC scstc = sc.stc;
+
+			/* These sets of storage classes are mutually exclusive,
+			 * so choose the innermost or most recent one.
+			 */
+			if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest))
+				scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest);
+			if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared))
+				scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared);
+			if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest))
+				scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest);
+			if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls))
+				scstc &= ~(STC.STCgshared | STC.STCshared | STC.STCtls);
+			scstc |= stc;
+
+			semanticNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign);
+		}
+	}
+	
+    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		assert(false);
+	}
+
+    static void stcToCBuffer(OutBuffer buf, int stc)
+	{
+		struct SCstring
+		{
+			int stc;
+			TOK tok;
+		};
+
+		static SCstring[] table =
+		[
+			{ STCauto,         TOKauto },
+			{ STCscope,        TOKscope },
+			{ STCstatic,       TOKstatic },
+			{ STCextern,       TOKextern },
+			{ STCconst,        TOKconst },
+			{ STCfinal,        TOKfinal },
+			{ STCabstract,     TOKabstract },
+			{ STCsynchronized, TOKsynchronized },
+			{ STCdeprecated,   TOKdeprecated },
+			{ STCoverride,     TOKoverride },
+			{ STClazy,         TOKlazy },
+			{ STCalias,        TOKalias },
+			{ STCout,          TOKout },
+			{ STCin,           TOKin },
+///		version (DMDV2) {
+///			{ STCimmutable,    TOKimmutable },
+///			{ STCshared,       TOKshared },
+///			{ STCnothrow,      TOKnothrow },
+///			{ STCpure,         TOKpure },
+///			{ STCref,          TOKref },
+///			{ STCtls,          TOKtls },
+///			{ STCgshared,      TOKgshared },
+///		}
+		];
+
+		for (int i = 0; i < table.length; i++)
+		{
+			if (stc & table[i].stc)
+			{
+				buf.writestring(Token.toChars(table[i].tok));
+				buf.writeByte(' ');
+			}
+		}
+	}
+}
\ No newline at end of file