本文整理汇总了C#中Boo.Lang.Compiler.Ast.ClassDefinition类的典型用法代码示例。如果您正苦于以下问题:C# ClassDefinition类的具体用法?C# ClassDefinition怎么用?C# ClassDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassDefinition类属于Boo.Lang.Compiler.Ast命名空间,在下文中一共展示了ClassDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckBaseTypes
void CheckBaseTypes(ClassDefinition node)
{
IType baseClass = null;
foreach (TypeReference baseTypeRef in node.BaseTypes)
{
IType baseType = GetType(baseTypeRef);
if (baseType.IsInterface)
continue;
if (null != baseClass)
{
Error(
CompilerErrorFactory.ClassAlreadyHasBaseType(baseTypeRef,
node.Name,
baseClass.FullName)
);
continue;
}
baseClass = baseType;
if (baseClass.IsFinal && !TypeSystemServices.IsError(baseClass))
{
Error(
CompilerErrorFactory.CannotExtendFinalType(
baseTypeRef,
baseClass.FullName));
}
}
if (null == baseClass)
node.BaseTypes.Insert(0, CodeBuilder.CreateTypeReference(TypeSystemServices.ObjectType) );
}
示例2: LeaveClassDefinition
public override void LeaveClassDefinition(ClassDefinition node)
{
MarkVisited(node);
if(!_classDefinitionList.Contains(node.Name))
{
_classDefinitionList.Add(node.Name, node);
}
foreach (TypeReference baseTypeRef in node.BaseTypes)
{
IType baseType = GetType(baseTypeRef);
EnsureRelatedNodeWasVisited(node, baseType);
if (baseType.IsInterface)
{
ResolveInterfaceMembers(node, baseTypeRef, baseType);
}
else
{
if (IsAbstract(baseType))
{
ResolveAbstractMembers(node, baseTypeRef, baseType);
}
}
}
}
示例3: Run
/// <summary>
/// Run this compiler step
/// </summary>
public override void Run()
{
if (Context.References.Contains(baseClass.Assembly) == false)
Context.Parameters.References.Add(baseClass.Assembly);
foreach (Module module in CompileUnit.Modules)
{
foreach (string ns in namespaces)
{
module.Imports.Add(new Import(module.LexicalInfo, ns));
}
ClassDefinition definition = new ClassDefinition();
definition.Name = module.FullName;
definition.BaseTypes.Add(new SimpleTypeReference(baseClass.FullName));
GenerateConstructors(definition);
// This is called before the module.Globals is set to a new block so that derived classes may retrieve the
// block from the module.
ExtendBaseClass(module, definition);
module.Globals = new Block();
module.Members.Add(definition);
}
}
示例4: OnStructDefinition
override public void OnStructDefinition(StructDefinition node)
{
ClassDefinition cd = new ClassDefinition(node.LexicalInfo);
cd.Name = node.Name;
cd.Attributes = node.Attributes;
cd.Modifiers = node.Modifiers;
cd.Members = node.Members;
cd.GenericParameters = node.GenericParameters;
cd.BaseTypes = node.BaseTypes;
cd.BaseTypes.Insert(0, CodeBuilder.CreateTypeReference(TypeSystemServices.ValueTypeType));
foreach (TypeMember member in cd.Members)
{
if (member.IsVisibilitySet)
continue;
switch (member.NodeType)
{
case NodeType.Field:
member.Visibility = Context.Parameters.DefaultFieldVisibility;
break;
case NodeType.Property:
member.Visibility = Context.Parameters.DefaultPropertyVisibility;
break;
case NodeType.Method:
member.Visibility = Context.Parameters.DefaultMethodVisibility;
break;
}
if (member.IsProtected)
member.Visibility = TypeMemberModifiers.Public;
}
OnClassDefinition(cd);
ReplaceCurrentNode(cd);
}
示例5: Run
public override void Run()
{
foreach(var module in CompileUnit.Modules)
{
foreach(string name in options.NamespacesToImport)
{
module.Imports.Add(new Import(module.LexicalInfo, name));
}
var macro = new ClassDefinition {Name = GetViewTypeName(module.FullName)};
macro.BaseTypes.Add(new SimpleTypeReference(options.BaseType));
AddConstructor(macro);
ScriptDirectoryProperty(macro, module);
AddRunMethod(macro, module);
foreach(var member in module.Members)
{
macro.Members.Add(member);
}
module.Members.Clear();
module.Members.Add(macro);
}
}
示例6: AddConstructor
// create a constructor that delegate to the base class
private void AddConstructor(ClassDefinition macro)
{
var ctor = new Constructor(macro.LexicalInfo);
ctor.Parameters.Add(
new ParameterDeclaration("viewEngine",
new SimpleTypeReference("MvcContrib.BrailViewEngine.BooViewEngine"))); // TODO: Update Reference
// ctor.Parameters.Add(
// new ParameterDeclaration("output",
// new SimpleTypeReference("System.IO.TextWriter")));
// ctor.Parameters.Add(
// new ParameterDeclaration("context",
// new SimpleTypeReference("Castle.MonoRail.Framework.IEngineContext")));
//
// ctor.Parameters.Add(
// new ParameterDeclaration("__controller",
// new SimpleTypeReference("Castle.MonoRail.Framework.IController")));
//
// ctor.Parameters.Add(
// new ParameterDeclaration("__controllerContext",
// new SimpleTypeReference("Castle.MonoRail.Framework.IControllerContext")));
var mie = new MethodInvocationExpression(new SuperLiteralExpression());
mie.Arguments.Add(AstUtil.CreateReferenceExpression("viewEngine"));
// mie.Arguments.Add(AstUtil.CreateReferenceExpression("output"));
// mie.Arguments.Add(AstUtil.CreateReferenceExpression("context"));
// mie.Arguments.Add(AstUtil.CreateReferenceExpression("__controller"));
// mie.Arguments.Add(AstUtil.CreateReferenceExpression("__controllerContext"));
ctor.Body.Add(mie);
macro.Members.Add(ctor);
}
示例7: Run
public override void Run()
{
foreach(Module module in CompileUnit.Modules)
{
module.Imports.Add(new Import(module.LexicalInfo, "Castle.MonoRail.Views.Brail"));
module.Imports.Add(new Import(module.LexicalInfo, "Castle.MonoRail.Framework"));
foreach(string name in options.NamespacesToImport)
{
module.Imports.Add(new Import(module.LexicalInfo, name));
}
ClassDefinition macro = new ClassDefinition();
macro.Name = GetViewTypeName(module.FullName);
macro.BaseTypes.Add(new SimpleTypeReference("Castle.MonoRail.Views.Brail.BrailBase"));
AddConstructor(macro);
ScriptDirectoryProperty(macro, module);
ViewFileNameProperty(macro, module);
AddRunMethod(macro, module);
foreach(TypeMember member in module.Members)
{
macro.Members.Add(member);
}
module.Members.Clear();
module.Members.Add(macro);
}
}
示例8: OnClassDefinition
public override void OnClassDefinition(ClassDefinition node)
{
IAccessibilityChecker saved = _checker;
_checker = new AccessibilityChecker(node);
base.OnClassDefinition(node);
_checker = saved;
}
示例9: CheckPrivateMembersNeverUsed
protected void CheckPrivateMembersNeverUsed(ClassDefinition node)
{
foreach (TypeMember member in node.Members)
{
WarnIfPrivateMemberNeverUsed(member);
}
}
示例10: Run
public override void Run()
{
var klass = new ClassDefinition { Name = "Foo" };
var baseType = new SimpleTypeReference("object");
klass.BaseTypes.Add(baseType);
var method = new Method { Name = "Bar" };
method.Body.Add(
new ReturnStatement(
new IntegerLiteralExpression(42)));
klass.Members.Add(method);
var module = CompileUnit.Modules[0];
Assert.AreEqual(0, module.Members.Count);
My<CodeReifier>.Instance.ReifyInto(module, klass);
Assert.AreEqual(1, module.Members.Count);
Assert.AreSame(klass, module.Members[0]);
var klassEntity = (IType) klass.Entity;
Assert.IsTrue(klassEntity.IsClass);
Assert.AreSame(TypeSystemServices.ObjectType, klassEntity.BaseType);
var methodEntity = (IMethod)method.Entity;
Assert.AreEqual(method.Name, methodEntity.Name);
Assert.AreSame(TypeSystemServices.IntType, methodEntity.ReturnType);
}
示例11: EnterClassDefinition
public override bool EnterClassDefinition(ClassDefinition node)
{
if (WasVisited(node))
return false;
_visited.Add(node);
return true;
}
示例12: CheckMembers
protected void CheckMembers(ClassDefinition node)
{
foreach (TypeMember member in node.Members)
{
WarnIfPrivateMemberNeverUsed(member);
WarnIfProtectedMemberInSealedClass(member);
}
}
示例13: OnClassDefinition
public override void OnClassDefinition(ClassDefinition node)
{
if (null == node.Entity)
{
node.Entity = new InternalClass(TypeSystemServices, node);
}
Visit(node.Members);
}
示例14: LeaveClassDefinition
public override void LeaveClassDefinition(ClassDefinition node)
{
CheckModifierCombination(node);
CantBeMarkedPartialIfNested(node);
if (node.IsStatic)
node.Modifiers |= TypeMemberModifiers.Abstract | TypeMemberModifiers.Final;
}
示例15: Merge
public void Merge(ClassDefinition node)
{
if (null == node) throw new ArgumentNullException("node");
if (ReferenceEquals(this, node)) return;
this.Attributes.Extend(node.Attributes);
this.BaseTypes.Extend(node.BaseTypes);
this.Members.Extend(node.Members);
}