Enum analysis works
This commit is contained in:
		
							parent
							
								
									a1faf68cce
								
							
						
					
					
						commit
						12755d3f85
					
				| @ -264,6 +264,10 @@ func (analyzer *analysisOperation) inCurrentModule ( | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| // TODO: make a method of analyzer that, given a name, searches through all | ||||
| // accessible scopes and returns the thing the name references. when analyzing | ||||
| // a function, the analyzer should remember a trail of scopes. | ||||
| 
 | ||||
| // doIndent perfroms a fmt.Sprint operation on input, indenting the string. This | ||||
| // does not add a trailing newline. | ||||
| func doIndent (indent int, input ...any) (output string) { | ||||
|  | ||||
| @ -74,7 +74,7 @@ func (analyzer analysisOperation) analyzeEnumSection () ( | ||||
| 	if !inheritsFromTypeSection { | ||||
| 		err = inputSection.Type().NewError ( | ||||
| 			"enum sections can only inherit from other type " + | ||||
| 			"sections.", | ||||
| 			"sections", | ||||
| 			infoerr.ErrorKindError) | ||||
| 		return | ||||
| 	} | ||||
| @ -97,8 +97,15 @@ func (analyzer analysisOperation) analyzeEnumSection () ( | ||||
| 				outputSection.what) | ||||
| 			if err != nil { return } | ||||
| 		} | ||||
| 
 | ||||
| 		outputSection.members = append ( | ||||
| 			outputSection.members, | ||||
| 			outputMember) | ||||
| 	} | ||||
| 
 | ||||
| 	// TODO: fill in members that do not have values with incrementing | ||||
| 	// values. take care to not duplicate them. | ||||
| 
 | ||||
| 	outputSection.complete = true | ||||
| 	return | ||||
| } | ||||
|  | ||||
| @ -130,7 +130,7 @@ func (analyzer analysisOperation) analyzeTypeSection () ( | ||||
| 	if !inheritsFromTypeSection { | ||||
| 		err = inputSection.Type().NewError ( | ||||
| 			"type sections can only inherit from other type " + | ||||
| 			"sections.", | ||||
| 			"sections", | ||||
| 			infoerr.ErrorKindError) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| @ -119,16 +119,15 @@ func (what Type) underlyingPrimitive () (underlying *TypeSection) { | ||||
| 			underlying = | ||||
| 				actual.(*TypeSection). | ||||
| 				what.underlyingPrimitive() | ||||
| 		// TODO | ||||
| 		// case *FaceSection: | ||||
| 			// TODO: depending on if this is an object interface or | ||||
| 			// a function interface, return either Face or Func. | ||||
| 			// we can assume this because of inheritence rules. | ||||
| 			 | ||||
| 		// // case *EnumSection: | ||||
| 			// underlying = | ||||
| 				// actual.(*EnumSection). | ||||
| 				// what.underlyingPrimitive() | ||||
| 		case *EnumSection: | ||||
| 			underlying = | ||||
| 				actual.(*EnumSection). | ||||
| 				what.underlyingPrimitive() | ||||
| 		 | ||||
| 		default: | ||||
| 			panic ( | ||||
| @ -164,13 +163,12 @@ func (what Type) isSingular () (singular bool) { | ||||
| 		switch actual.(type) { | ||||
| 		case *TypeSection: | ||||
| 			singular = actual.(*TypeSection).what.isSingular() | ||||
| 		// TODO: uncomment this when these sections have been | ||||
| 		// implemented | ||||
| 		// TODO: uncomment this when this section has been implemented | ||||
| 		// case *FaceSection: | ||||
| 			// singular = true | ||||
| 			 | ||||
| 		// case *EnumSection: | ||||
| 			// singular = actual.(*EnumSection).what.isSingular() | ||||
| 		case *EnumSection: | ||||
| 			singular = actual.(*EnumSection).what.isSingular() | ||||
| 		 | ||||
| 		default: | ||||
| 			panic ( | ||||
| @ -207,13 +205,12 @@ func (what Type) reduce () (reduced Type, reducible bool) { | ||||
| 	case *TypeSection: | ||||
| 		reduced, reducible = what.actual.(*TypeSection).what.reduce() | ||||
| 		 | ||||
| 	// TODO: uncomment this when these sections have been | ||||
| 	// implemented | ||||
| 	// TODO: uncomment this when his section has been implemented | ||||
| 	// case *FaceSection: | ||||
| 		// singular = true | ||||
| 		 | ||||
| 	// case *EnumSection: | ||||
| 		// reduced, reducible = what.actual.(*EnumSection).what.reduce() | ||||
| 	case *EnumSection: | ||||
| 		reduced, reducible = what.actual.(*EnumSection).what.reduce() | ||||
| 	 | ||||
| 	default: | ||||
| 		panic ( | ||||
| @ -268,7 +265,7 @@ func (analyzer analysisOperation) analyzeType ( | ||||
| 
 | ||||
| 		switch actual.(type) { | ||||
| 		// TODO: uncomment once these sections are implemented | ||||
| 		case *TypeSection /* , *EnumSection, *FaceSection */: | ||||
| 		case *TypeSection, *EnumSection /* , *FaceSection */: | ||||
| 			outputType.actual = actual | ||||
| 		default: | ||||
| 			err = inputType.NewError ( | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| :arf | ||||
| --- | ||||
| 
 | ||||
| enum ro Weekday:Int | ||||
| enum ro aWeekday:Int | ||||
| 	- sunday | ||||
| 	- monday | ||||
| 	- tuesday | ||||
| @ -9,3 +9,12 @@ enum ro Weekday:Int | ||||
| 	- thursday | ||||
| 	- friday | ||||
| 	- saturday | ||||
| 
 | ||||
| type ro bColor:U32 | ||||
| 
 | ||||
| enum ro cNamedColor:bColor | ||||
| 	- red   0xFF0000 | ||||
| 	- green 0x00FF00 | ||||
| 	- blue  0x0000FF | ||||
| 
 | ||||
| type ro X:cNamedColor | ||||
|  | ||||
		Reference in New Issue
	
	Block a user